// Copyright (C) 2012 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 #include #include #define F(a) static_cast(a) template NzBoundingBox::NzBoundingBox() : extend(nzExtend_Null) { } template NzBoundingBox::NzBoundingBox(nzExtend Extend) { Set(Extend); } template NzBoundingBox::NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template NzBoundingBox::NzBoundingBox(const NzCube& Cube) { Set(Cube); } template NzBoundingBox::NzBoundingBox(const NzVector3& vec1, const NzVector3& vec2) { Set(vec1, vec2); } template template NzBoundingBox::NzBoundingBox(const NzBoundingBox& box) { Set(box); } template bool NzBoundingBox::IsFinite() const { return extend == nzExtend_Finite; } template bool NzBoundingBox::IsInfinite() const { return extend == nzExtend_Infinite; } template bool NzBoundingBox::IsNull() const { return extend == nzExtend_Null; } template NzBoundingBox& NzBoundingBox::MakeInfinite() { extend = nzExtend_Infinite; return *this; } template NzBoundingBox& NzBoundingBox::MakeNull() { extend = nzExtend_Null; return *this; } template NzBoundingBox& NzBoundingBox::Set(nzExtend Extend) { extend = Extend; return *this; } template NzBoundingBox& NzBoundingBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) { obb.Set(X, Y, Z, Width, Height, Depth); extend = nzExtend_Finite; return *this; } template NzBoundingBox& NzBoundingBox::Set(const NzBoundingBox& box) { obb.Set(box.obb); // Seul l'OBB est importante pour la suite return *this; } template NzBoundingBox& NzBoundingBox::Set(const NzCube& Cube) { obb.Set(Cube); extend = nzExtend_Finite; return *this; } template NzBoundingBox& NzBoundingBox::Set(const NzVector3& vec1, const NzVector3& vec2) { obb.Set(vec1, vec2); extend = nzExtend_Finite; return *this; } template template NzBoundingBox& NzBoundingBox::Set(const NzBoundingBox& box) { obb.Set(box.obb); extend = box.extend; return *this; } template NzString NzBoundingBox::ToString() const { switch (extend) { case nzExtend_Finite: return "BoundingBox(localCube=" + obb.localCube.ToString() + ')'; case nzExtend_Infinite: return "BoundingBox(Infinite)"; case nzExtend_Null: return "BoundingBox(Null)"; } // Si nous arrivons ici c'est que l'extend est invalide NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')'); return "BoundingBox(ERROR)"; } template void NzBoundingBox::Update(const NzMatrix4& transformMatrix) { aabb.Set(obb.localCube); aabb.Transform(transformMatrix); obb.Update(transformMatrix); } template NzBoundingBox NzBoundingBox::operator*(T scalar) const { NzBoundingBox box(*this); box *= scalar; return box; } template NzBoundingBox& NzBoundingBox::operator*=(T scalar) { obb *= scalar; return *this; } template bool NzBoundingBox::operator==(const NzBoundingBox& box) const { if (extend == box.extend) return obb == box.obb; else return false; } template bool NzBoundingBox::operator!=(const NzBoundingBox& box) const { return !operator==(box); } template NzBoundingBox NzBoundingBox::Infinite() { NzBoundingBox box; box.MakeInfinite(); return box; } template NzBoundingBox NzBoundingBox::Lerp(const NzBoundingBox& from, const NzBoundingBox& to, T interpolation) { #ifdef NAZARA_DEBUG if (interpolation < 0.f || interpolation > 1.f) { NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); return Null(); } #endif if (NzNumberEquals(interpolation, 0.f)) return from; if (NzNumberEquals(interpolation, 1.f)) return to; switch (to.extend) { case nzExtend_Finite: { switch (from.extend) { case nzExtend_Finite: { NzBoundingBox box; box.Set(NzOrientedCube::Lerp(from.obb, to.obb, interpolation)); return box; } case nzExtend_Infinite: return Infinite(); case nzExtend_Null: return from.obb * interpolation; } // Si nous arrivons ici c'est que l'extend est invalide NazaraError("Invalid extend type (From) (0x" + NzString::Number(from.extend, 16) + ')'); return Null(); } case nzExtend_Infinite: return Infinite(); // Un petit peu d'infini est infini quand même ;) case nzExtend_Null: { switch (from.extend) { case nzExtend_Finite: return from.obb * (F(1.0) - interpolation); case nzExtend_Infinite: return Infinite(); case nzExtend_Null: return Null(); } // Si nous arrivons ici c'est que l'extend est invalide NazaraError("Invalid extend type (From) (0x" + NzString::Number(from.extend, 16) + ')'); return Null(); } } // Si nous arrivons ici c'est que l'extend est invalide NazaraError("Invalid extend type (To) (0x" + NzString::Number(from.extend, 16) + ')'); return Null(); } template NzBoundingBox NzBoundingBox::Null() { NzBoundingBox box; box.MakeNull(); return box; } template std::ostream& operator<<(std::ostream& out, const NzBoundingBox& box) { out << box.ToString(); return out; } #undef F #include