// 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 NzOrientedCube::NzOrientedCube(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template NzOrientedCube::NzOrientedCube(const NzCube& cube) { Set(cube); } template NzOrientedCube::NzOrientedCube(const NzVector3& vec1, const NzVector3& vec2) { Set(vec1, vec2); } template template NzOrientedCube::NzOrientedCube(const NzOrientedCube& orientedCube) { Set(orientedCube); } template const NzVector3& NzOrientedCube::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 NzOrientedCube::IsValid() const { return localCube.IsValid(); } template NzOrientedCube& NzOrientedCube::MakeZero() { localCube.MakeZero(); return *this; } template NzOrientedCube& NzOrientedCube::Set(T X, T Y, T Z, T Width, T Height, T Depth) { localCube.Set(X, Y, Z, Width, Height, Depth); return *this; } template NzOrientedCube& NzOrientedCube::Set(const NzCube& cube) { localCube.Set(cube); return *this; } template NzOrientedCube& NzOrientedCube::Set(const NzOrientedCube& orientedCube) { std::memcpy(this, &orientedCube, sizeof(NzOrientedCube)); return *this; } template NzOrientedCube& NzOrientedCube::Set(const NzVector3& vec1, const NzVector3& vec2) { localCube.Set(vec1, vec2); return *this; } template template NzOrientedCube& NzOrientedCube::Set(const NzOrientedCube& orientedCube) { for (unsigned int i = 0; i <= nzCorner_Max; ++i) m_corners[i].Set(orientedCube.m_corners[i]); localCube = orientedCube.localCube; return *this; } template NzString NzOrientedCube::ToString() const { NzStringStream ss; return ss << "OrientedCube(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 NzOrientedCube::Update(const NzMatrix4& transformMatrix) { for (unsigned int i = 0; i <= nzCorner_Max; ++i) m_corners[i] = transformMatrix.Transform(localCube.GetCorner(static_cast(i))); } template NzOrientedCube::operator NzVector3*() { return &m_corners[0]; } template NzOrientedCube::operator const NzVector3*() const { return &m_corners[0]; } template NzVector3& NzOrientedCube::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 NzOrientedCube::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 NzOrientedCube NzOrientedCube::operator*(T scalar) const { NzOrientedCube box(*this); box *= scalar; return box; } template NzOrientedCube& NzOrientedCube::operator*=(T scalar) { localCube *= scalar; return *this; } template bool NzOrientedCube::operator==(const NzOrientedCube& box) const { return localCube == box.localCube; } template bool NzOrientedCube::operator!=(const NzOrientedCube& box) const { return !operator==(box); } template NzOrientedCube NzOrientedCube::Lerp(const NzOrientedCube& from, const NzOrientedCube& to, T interpolation) { NzOrientedCube orientedCube; orientedCube.Set(NzCube::Lerp(from.localCube, to.localCube, interpolation)); return orientedCube; } template NzOrientedCube NzOrientedCube::Zero() { NzOrientedCube orientedCube; orientedCube.MakeZero(); return orientedCube; } template std::ostream& operator<<(std::ostream& out, const NzOrientedCube& orientedCube) { return out << orientedCube.ToString(); } #undef F #include