// 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 #include #include #define F(a) static_cast(a) template NzBoundingVolume::NzBoundingVolume() : extend(nzExtend_Null) { } template NzBoundingVolume::NzBoundingVolume(nzExtend Extend) { Set(Extend); } template NzBoundingVolume::NzBoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template NzBoundingVolume::NzBoundingVolume(const NzBox& box) { Set(box); } template NzBoundingVolume::NzBoundingVolume(const NzVector3& vec1, const NzVector3& vec2) { Set(vec1, vec2); } template template NzBoundingVolume::NzBoundingVolume(const NzBoundingVolume& volume) { Set(volume); } template bool NzBoundingVolume::IsFinite() const { return extend == nzExtend_Finite; } template bool NzBoundingVolume::IsInfinite() const { return extend == nzExtend_Infinite; } template bool NzBoundingVolume::IsNull() const { return extend == nzExtend_Null; } template NzBoundingVolume& NzBoundingVolume::MakeInfinite() { extend = nzExtend_Infinite; return *this; } template NzBoundingVolume& NzBoundingVolume::MakeNull() { extend = nzExtend_Null; return *this; } template NzBoundingVolume& NzBoundingVolume::Set(nzExtend Extend) { extend = Extend; return *this; } template NzBoundingVolume& NzBoundingVolume::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 NzBoundingVolume& NzBoundingVolume::Set(const NzBoundingVolume& volume) { obb.Set(volume.obb); // Seul l'OBB est importante pour la suite return *this; } template NzBoundingVolume& NzBoundingVolume::Set(const NzBox& box) { obb.Set(box); extend = nzExtend_Finite; return *this; } template NzBoundingVolume& NzBoundingVolume::Set(const NzVector3& vec1, const NzVector3& vec2) { obb.Set(vec1, vec2); extend = nzExtend_Finite; return *this; } template template NzBoundingVolume& NzBoundingVolume::Set(const NzBoundingVolume& volume) { obb.Set(volume.obb); extend = volume.extend; return *this; } template NzString NzBoundingVolume::ToString() const { switch (extend) { case nzExtend_Finite: return "BoundingVolume(localBox=" + obb.localBox.ToString() + ')'; case nzExtend_Infinite: return "BoundingVolume(Infinite)"; case nzExtend_Null: return "BoundingVolume(Null)"; } // Si nous arrivons ici c'est que l'extend est invalide NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')'); return "BoundingVolume(ERROR)"; } template void NzBoundingVolume::Update(const NzMatrix4& transformMatrix) { aabb.Set(obb.localBox); aabb.Transform(transformMatrix); obb.Update(transformMatrix); } template NzBoundingVolume NzBoundingVolume::operator*(T scalar) const { NzBoundingVolume volume(*this); volume *= scalar; return volume; } template NzBoundingVolume& NzBoundingVolume::operator*=(T scalar) { obb *= scalar; return *this; } template bool NzBoundingVolume::operator==(const NzBoundingVolume& volume) const { if (extend == volume.extend) return obb == volume.obb; else return false; } template bool NzBoundingVolume::operator!=(const NzBoundingVolume& volume) const { return !operator==(volume); } template NzBoundingVolume NzBoundingVolume::Infinite() { NzBoundingVolume volume; volume.MakeInfinite(); return volume; } template NzBoundingVolume NzBoundingVolume::Lerp(const NzBoundingVolume& from, const NzBoundingVolume& 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: { NzBoundingVolume volume; volume.Set(NzOrientedBox::Lerp(from.obb, to.obb, interpolation)); return volume; } 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(to.extend, 16) + ')'); return Null(); } template NzBoundingVolume NzBoundingVolume::Null() { NzBoundingVolume volume; volume.MakeNull(); return volume; } template std::ostream& operator<<(std::ostream& out, const NzBoundingVolume& volume) { out << volume.ToString(); return out; } #undef F #include