// Copyright (C) 2013 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 #define F(a) static_cast(a) template NzOrientedBox::NzOrientedBox(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template NzOrientedBox::NzOrientedBox(const NzBox& box) { Set(box); } template NzOrientedBox::NzOrientedBox(const NzVector3& vec1, const NzVector3& vec2) { Set(vec1, vec2); } template template NzOrientedBox::NzOrientedBox(const NzOrientedBox& orientedBox) { Set(orientedBox); } template const NzVector3& NzOrientedBox::GetCorner(nzCorner corner) const { #ifdef NAZARA_DEBUG if (corner > nzCorner_Max) { NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')'); static NzVector3 dummy; return dummy; } #endif return m_corners[corner]; } template bool NzOrientedBox::IsValid() const { return localBox.IsValid(); } template NzOrientedBox& NzOrientedBox::MakeZero() { localBox.MakeZero(); return *this; } template NzOrientedBox& NzOrientedBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) { localBox.Set(X, Y, Z, Width, Height, Depth); return *this; } template NzOrientedBox& NzOrientedBox::Set(const NzBox& box) { localBox.Set(box); return *this; } template NzOrientedBox& NzOrientedBox::Set(const NzOrientedBox& orientedBox) { std::memcpy(this, &orientedBox, sizeof(NzOrientedBox)); return *this; } template NzOrientedBox& NzOrientedBox::Set(const NzVector3& vec1, const NzVector3& vec2) { localBox.Set(vec1, vec2); return *this; } template template NzOrientedBox& NzOrientedBox::Set(const NzOrientedBox& orientedBox) { for (unsigned int i = 0; i <= nzCorner_Max; ++i) m_corners[i].Set(orientedBox.m_corners[i]); localBox = orientedBox.localBox; return *this; } template NzString NzOrientedBox::ToString() const { NzStringStream ss; return ss << "OrientedBox(FLB: " << m_corners[nzCorner_FarLeftBottom].ToString() << "\n" << " FLT: " << m_corners[nzCorner_FarLeftTop].ToString() << "\n" << " FRB: " << m_corners[nzCorner_FarRightBottom].ToString() << "\n" << " FRT: " << m_corners[nzCorner_FarRightTop].ToString() << "\n" << " NLB: " << m_corners[nzCorner_NearLeftBottom].ToString() << "\n" << " NLT: " << m_corners[nzCorner_NearLeftTop].ToString() << "\n" << " NRB: " << m_corners[nzCorner_NearRightBottom].ToString() << "\n" << " NRT: " << m_corners[nzCorner_NearRightTop].ToString() << ")\n"; } template void NzOrientedBox::Update(const NzMatrix4& transformMatrix) { for (unsigned int i = 0; i <= nzCorner_Max; ++i) m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast(i))); } template NzOrientedBox::operator NzVector3*() { return &m_corners[0]; } template NzOrientedBox::operator const NzVector3*() const { return &m_corners[0]; } template NzVector3& NzOrientedBox::operator()(unsigned int i) { #if NAZARA_MATH_SAFE if (i > nzCorner_Max) { NzStringStream ss; ss << "Index out of range: (" << i << " >= 3)"; NazaraError(ss); throw std::out_of_range(ss.ToString()); } #endif return &m_corners[i]; } template NzVector3 NzOrientedBox::operator()(unsigned int i) const { #if NAZARA_MATH_SAFE if (i > nzCorner_Max) { NzStringStream ss; ss << "Index out of range: (" << i << " >= 3)"; NazaraError(ss); throw std::out_of_range(ss.ToString()); } #endif return &m_corners[i]; } template NzOrientedBox NzOrientedBox::operator*(T scalar) const { NzOrientedBox box(*this); box *= scalar; return box; } template NzOrientedBox& NzOrientedBox::operator*=(T scalar) { localBox *= scalar; return *this; } template bool NzOrientedBox::operator==(const NzOrientedBox& box) const { return localBox == box.localBox; } template bool NzOrientedBox::operator!=(const NzOrientedBox& box) const { return !operator==(box); } template NzOrientedBox NzOrientedBox::Lerp(const NzOrientedBox& from, const NzOrientedBox& to, T interpolation) { NzOrientedBox orientedBox; orientedBox.Set(NzBox::Lerp(from.localBox, to.localBox, interpolation)); return orientedBox; } template NzOrientedBox NzOrientedBox::Zero() { NzOrientedBox orientedBox; orientedBox.MakeZero(); return orientedBox; } template std::ostream& operator<<(std::ostream& out, const NzOrientedBox& orientedBox) { return out << orientedBox.ToString(); } #undef F #include