// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include ///DOC: Pour que les coins soient valides, la méthode Update doit être appelée #define F(a) static_cast(a) namespace Nz { template OrientedBox::OrientedBox(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template OrientedBox::OrientedBox(const Box& box) { Set(box); } template OrientedBox::OrientedBox(const Vector3& vec1, const Vector3& vec2) { Set(vec1, vec2); } template template OrientedBox::OrientedBox(const OrientedBox& orientedBox) { Set(orientedBox); } template const Vector3& OrientedBox::GetCorner(BoxCorner corner) const { #ifdef NAZARA_DEBUG if (corner > BoxCorner_Max) { NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')'); static Vector3 dummy; return dummy; } #endif return m_corners[corner]; } template bool OrientedBox::IsValid() const { return localBox.IsValid(); } template OrientedBox& OrientedBox::MakeZero() { localBox.MakeZero(); return *this; } template OrientedBox& OrientedBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) { localBox.Set(X, Y, Z, Width, Height, Depth); return *this; } template OrientedBox& OrientedBox::Set(const Box& box) { localBox.Set(box); return *this; } template OrientedBox& OrientedBox::Set(const OrientedBox& orientedBox) { std::memcpy(this, &orientedBox, sizeof(OrientedBox)); return *this; } template OrientedBox& OrientedBox::Set(const Vector3& vec1, const Vector3& vec2) { localBox.Set(vec1, vec2); return *this; } template template OrientedBox& OrientedBox::Set(const OrientedBox& orientedBox) { for (unsigned int i = 0; i <= BoxCorner_Max; ++i) m_corners[i].Set(orientedBox(i)); localBox.Set(orientedBox.localBox); return *this; } template String OrientedBox::ToString() const { StringStream ss; return ss << "OrientedBox(FLB: " << m_corners[BoxCorner_FarLeftBottom].ToString() << "\n" << " FLT: " << m_corners[BoxCorner_FarLeftTop].ToString() << "\n" << " FRB: " << m_corners[BoxCorner_FarRightBottom].ToString() << "\n" << " FRT: " << m_corners[BoxCorner_FarRightTop].ToString() << "\n" << " NLB: " << m_corners[BoxCorner_NearLeftBottom].ToString() << "\n" << " NLT: " << m_corners[BoxCorner_NearLeftTop].ToString() << "\n" << " NRB: " << m_corners[BoxCorner_NearRightBottom].ToString() << "\n" << " NRT: " << m_corners[BoxCorner_NearRightTop].ToString() << ")\n"; } template void OrientedBox::Update(const Matrix4& transformMatrix) { for (unsigned int i = 0; i <= BoxCorner_Max; ++i) m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast(i))); } template void OrientedBox::Update(const Vector3& translation) { for (unsigned int i = 0; i <= BoxCorner_Max; ++i) m_corners[i] = localBox.GetCorner(static_cast(i)) + translation; } template OrientedBox::operator Vector3*() { return &m_corners[0]; } template OrientedBox::operator const Vector3*() const { return &m_corners[0]; } template Vector3& OrientedBox::operator()(unsigned int i) { #if NAZARA_MATH_SAFE if (i > BoxCorner_Max) { StringStream ss; ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")"; NazaraError(ss); throw std::out_of_range(ss.ToString()); } #endif return m_corners[i]; } template Vector3 OrientedBox::operator()(unsigned int i) const { #if NAZARA_MATH_SAFE if (i > BoxCorner_Max) { StringStream ss; ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")"; NazaraError(ss); throw std::out_of_range(ss.ToString()); } #endif return m_corners[i]; } template OrientedBox OrientedBox::operator*(T scalar) const { OrientedBox box(*this); box *= scalar; return box; } template OrientedBox& OrientedBox::operator*=(T scalar) { localBox *= scalar; return *this; } template bool OrientedBox::operator==(const OrientedBox& box) const { return localBox == box.localBox; } template bool OrientedBox::operator!=(const OrientedBox& box) const { return !operator==(box); } template OrientedBox OrientedBox::Lerp(const OrientedBox& from, const OrientedBox& to, T interpolation) { OrientedBox orientedBox; orientedBox.Set(Box::Lerp(from.localBox, to.localBox, interpolation)); return orientedBox; } template OrientedBox OrientedBox::Zero() { OrientedBox orientedBox; orientedBox.MakeZero(); return orientedBox; } } template std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox) { return out << orientedBox.ToString(); } #undef F #include