Removed AxisAlignedBox (Replaced by BoundingBox)

Former-commit-id: 931dd6710caf49aeaede51efe209d714f080c44b
This commit is contained in:
Lynix
2013-02-21 18:28:32 +01:00
parent 2e6b864cad
commit 1b5215d4c2
22 changed files with 561 additions and 768 deletions

View File

@@ -1,87 +0,0 @@
// 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
#ifndef NAZARA_AXISALIGNEDBOX_HPP
#define NAZARA_AXISALIGNEDBOX_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzAxisAlignedBox
{
public:
NzAxisAlignedBox();
NzAxisAlignedBox(nzExtend Extend);
NzAxisAlignedBox(T X, T Y, T Z, T Width, T Height, T Depth);
NzAxisAlignedBox(const NzCube<T>& Cube);
NzAxisAlignedBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzAxisAlignedBox(const NzAxisAlignedBox<U>& box);
NzAxisAlignedBox(const NzAxisAlignedBox& box) = default;
~NzAxisAlignedBox() = default;
bool Contains(T X, T Y, T Z) const;
bool Contains(const NzAxisAlignedBox& box) const;
bool Contains(const NzVector3<T>& vector) const;
NzAxisAlignedBox& ExtendTo(T X, T Y, T Z);
NzAxisAlignedBox& ExtendTo(const NzAxisAlignedBox& box);
NzAxisAlignedBox& ExtendTo(const NzVector3<T>& vector);
NzVector3<T> GetCorner(nzCorner corner) const;
NzVector3<T> GetCenter() const;
NzCube<T> GetCube() const;
nzExtend GetExtend() const;
NzVector3<T> GetNegativeVertex(const NzVector3<T>& normal) const;
NzVector3<T> GetPosition() const;
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
NzVector3<T> GetSize() const;
bool Intersect(const NzAxisAlignedBox& box, NzAxisAlignedBox* intersection = nullptr) const;
bool IsFinite() const;
bool IsInfinite() const;
bool IsNull() const;
NzAxisAlignedBox& MakeInfinite();
NzAxisAlignedBox& MakeNull();
NzAxisAlignedBox& Set(nzExtend Extend);
NzAxisAlignedBox& Set(T X, T Y, T Z, T Width, T Height, T Depth);
NzAxisAlignedBox& Set(const NzAxisAlignedBox<T>& box);
NzAxisAlignedBox& Set(const NzCube<T>& Cube);
NzAxisAlignedBox& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzAxisAlignedBox& Set(const NzAxisAlignedBox<U>& box);
NzString ToString() const;
NzAxisAlignedBox& Transform(const NzMatrix4<T>& matrix, bool applyTranslation = true);
NzAxisAlignedBox operator*(T scalar) const;
NzAxisAlignedBox& operator*=(T scalar);
bool operator==(const NzAxisAlignedBox& box) const;
bool operator!=(const NzAxisAlignedBox& box) const;
static NzAxisAlignedBox Infinite();
static NzAxisAlignedBox Lerp(const NzAxisAlignedBox& from, const NzAxisAlignedBox& to, T interpolation);
static NzAxisAlignedBox Null();
nzExtend extend;
NzCube<T> cube;
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox<T>& box);
typedef NzAxisAlignedBox<double> NzAxisAlignedBoxd;
typedef NzAxisAlignedBox<float> NzAxisAlignedBoxf;
#include <Nazara/Math/AxisAlignedBox.inl>
#endif // NAZARA_AXISALIGNEDBOX_HPP

View File

@@ -1,610 +0,0 @@
// 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 <Nazara/Core/StringStream.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Basic.hpp>
#include <algorithm>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzAxisAlignedBox<T>::NzAxisAlignedBox() :
extend(nzExtend_Null)
{
}
template<typename T>
NzAxisAlignedBox<T>::NzAxisAlignedBox(nzExtend Extend)
{
Set(Extend);
}
template<typename T>
NzAxisAlignedBox<T>::NzAxisAlignedBox(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
template<typename T>
NzAxisAlignedBox<T>::NzAxisAlignedBox(const NzCube<T>& Cube)
{
Set(Cube);
}
template<typename T>
NzAxisAlignedBox<T>::NzAxisAlignedBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzAxisAlignedBox<T>::NzAxisAlignedBox(const NzAxisAlignedBox<U>& box)
{
Set(box);
}
template<typename T>
bool NzAxisAlignedBox<T>::Contains(T x, T y, T z) const
{
switch (extend)
{
case nzExtend_Finite:
return cube.Contains(x, y, z);
case nzExtend_Infinite:
return true;
case nzExtend_Null:
return false;
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return false;
}
template<typename T>
bool NzAxisAlignedBox<T>::Contains(const NzAxisAlignedBox& box) const
{
if (extend == nzExtend_Null || box.extend == nzExtend_Null)
return false;
else if (extend == nzExtend_Infinite || box.extend == nzExtend_Infinite)
return true;
return cube.Contains(box.cube);
}
template<typename T>
bool NzAxisAlignedBox<T>::Contains(const NzVector3<T>& vector) const
{
switch (extend)
{
case nzExtend_Finite:
return cube.Contains(vector);
case nzExtend_Infinite:
return true;
case nzExtend_Null:
return false;
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return false;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::ExtendTo(T X, T Y, T Z)
{
switch (extend)
{
case nzExtend_Finite:
cube.ExtendTo(X, Y, Z);
return *this;
case nzExtend_Infinite:
return *this; // Rien à faire
case nzExtend_Null:
return Set(cube.Set(X, Y, Z, F(0.0), F(0.0), F(0.0)));;
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::ExtendTo(const NzAxisAlignedBox& box)
{
switch (extend)
{
case nzExtend_Finite:
switch (box.extend)
{
case nzExtend_Finite:
cube.ExtendTo(box.cube);
return *this;
case nzExtend_Infinite:
return MakeInfinite();
case nzExtend_Null:
return *this;
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')');
return *this;
case nzExtend_Infinite:
return *this; // Rien à faire
case nzExtend_Null:
return Set(box);
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::ExtendTo(const NzVector3<T>& vector)
{
return ExtendTo(vector.x, vector.y, vector.z);
}
template<typename T>
NzVector3<T> NzAxisAlignedBox<T>::GetCorner(nzCorner corner) const
{
switch (extend)
{
case nzExtend_Finite:
return cube.GetCorner(corner);
case nzExtend_Infinite:
// Il est possible de renvoyer un vecteur avec des flottants infinis dont le signe dépend du coin
// Bien que ça soit plus juste mathématiquement, je ne vois pas l'intérêt...
NazaraError("Infinite AABB has no corner");
return NzVector3<T>();
case nzExtend_Null:
return NzVector3<T>::Zero();
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return NzVector3<T>();
}
template<typename T>
NzCube<T> NzAxisAlignedBox<T>::GetCube() const
{
return cube;
}
template<typename T>
nzExtend NzAxisAlignedBox<T>::GetExtend() const
{
return extend;
}
template<typename T>
NzVector3<T> NzAxisAlignedBox<T>::GetNegativeVertex(const NzVector3<T>& normal) const
{
switch (extend)
{
case nzExtend_Finite:
return cube.GetNegativeVertex(normal);
case nzExtend_Infinite:
// Il est possible de renvoyer un vecteur avec des flottants infinis dont le signe dépend de la normale
// Bien que ça soit plus juste mathématiquement, je ne vois pas l'intérêt...
NazaraError("Infinite AABB has no negative vertex");
return NzVector3<T>();
case nzExtend_Null:
return NzVector3<T>::Zero();
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return NzVector3<T>();
}
template<typename T>
NzVector3<T> NzAxisAlignedBox<T>::GetPosition() const
{
switch (extend)
{
case nzExtend_Finite:
return cube.GetPosition();
case nzExtend_Infinite:
// Il est possible de renvoyer un vecteur avec des flottants infinis
// Bien que ça soit plus juste mathématiquement, je ne vois pas l'intérêt...
NazaraError("Infinite AABB has no position");
return NzVector3<T>();
case nzExtend_Null:
return NzVector3<T>::Zero();
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return NzVector3<T>();
}
template<typename T>
NzVector3<T> NzAxisAlignedBox<T>::GetPositiveVertex(const NzVector3<T>& normal) const
{
switch (extend)
{
case nzExtend_Finite:
return cube.GetPositiveVertex(normal);
case nzExtend_Infinite:
// Il est possible de renvoyer un vecteur avec des flottants infinis dont le signe dépend de la normale
// Bien que ça soit plus juste mathématiquement, je ne vois pas l'intérêt...
NazaraError("Infinite AABB has no corner");
return NzVector3<T>();
case nzExtend_Null:
return NzVector3<T>::Zero();
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return NzVector3<T>();
}
template<typename T>
NzVector3<T> NzAxisAlignedBox<T>::GetSize() const
{
switch (extend)
{
case nzExtend_Finite:
return cube.GetSize();
case nzExtend_Infinite:
// Il est possible de renvoyer un vecteur avec des flottants infinis
// Bien que ça soit plus juste mathématiquement, je ne vois pas l'intérêt...
NazaraError("Infinite AABB has no size");
return NzVector3<T>();
case nzExtend_Null:
return NzVector3<T>::Zero();
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return NzVector3<T>();
}
template<typename T>
bool NzAxisAlignedBox<T>::Intersect(const NzAxisAlignedBox& box, NzAxisAlignedBox* intersection) const
{
switch (extend)
{
case nzExtend_Finite:
{
switch (box.extend)
{
case nzExtend_Finite:
{
if (cube.Intersect(box.cube, &intersection->cube))
{
intersection->extend = nzExtend_Finite;
return true;
}
else
return false;
}
case nzExtend_Infinite:
intersection->Set(*this);
return true;
case nzExtend_Null:
return false;
}
NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')');
return false;
}
case nzExtend_Infinite:
if (!box.IsNull()) // Si l'AABB n'est pas nulle, c'est qu'elle est finie ou infinie
{
// Et dans ce cas, il y a toujous intersection équivalente à la seconde AABB
intersection->Set(box);
return true;
}
else
return false;
case nzExtend_Null:
return false; // N'a jamais de collision avec quoi que ce soit
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return false;
}
template<typename T>
bool NzAxisAlignedBox<T>::IsFinite() const
{
return extend == nzExtend_Finite;
}
template<typename T>
bool NzAxisAlignedBox<T>::IsInfinite() const
{
return extend == nzExtend_Infinite;
}
template<typename T>
bool NzAxisAlignedBox<T>::IsNull() const
{
return extend == nzExtend_Null;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::MakeInfinite()
{
extend = nzExtend_Infinite;
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::MakeNull()
{
extend = nzExtend_Null;
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Set(nzExtend Extend)
{
extend = Extend;
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
cube.Set(X, Y, Z, Width, Height, Depth);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Set(const NzAxisAlignedBox<T>& box)
{
std::memcpy(this, &box, sizeof(NzAxisAlignedBox));
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Set(const NzCube<T>& Cube)
{
cube.Set(Cube);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
cube.Set(vec1, vec2);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
template<typename U>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Set(const NzAxisAlignedBox<U>& box)
{
cube.Set(box);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
NzString NzAxisAlignedBox<T>::ToString() const
{
switch (extend)
{
case nzExtend_Finite:
return "NzAxisAlignedBox(min=" + cube.GetPosition().ToString() + ", max=" + (cube.GetPosition()+cube.GetSize()).ToString() + ')';
case nzExtend_Infinite:
return "NzAxisAlignedBox(Infinite)";
case nzExtend_Null:
return "NzAxisAlignedBox(Null)";
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return "NzAxisAlignedBox(ERROR)";
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation)
{
if (extend != nzExtend_Finite)
return *this; // Toute transformation d'une AABox autre que finie résultera en la même AABox
NzVector3<T> center = matrix.Transform(cube.GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
NzVector3<T> halfSize = cube.GetSize() * F(0.5);
halfSize.Set(std::fabs(matrix(0,0))*halfSize.x + std::fabs(matrix(1,0))*halfSize.y + std::fabs(matrix(2,0))*halfSize.z,
std::fabs(matrix(0,1))*halfSize.x + std::fabs(matrix(1,1))*halfSize.y + std::fabs(matrix(2,1))*halfSize.z,
std::fabs(matrix(0,2))*halfSize.x + std::fabs(matrix(1,2))*halfSize.y + std::fabs(matrix(2,2))*halfSize.z);
cube.Set(center - halfSize, center + halfSize);
return *this;
}
template<typename T>
NzAxisAlignedBox<T> NzAxisAlignedBox<T>::operator*(T scalar) const
{
NzAxisAlignedBox box(*this);
box *= scalar;
return box;
}
template<typename T>
NzAxisAlignedBox<T>& NzAxisAlignedBox<T>::operator*=(T scalar)
{
switch (extend)
{
case nzExtend_Finite:
cube *= scalar;
return *this;
case nzExtend_Infinite:
// L'infini multiplié par quoi que ce soit d'autre que zéro reste l'infini
// (On ne se préoccupe pas de l'infini de signe négatif, car ça finirait par être équivalent)
if (NzNumberEquals(scalar, F(0.0)))
MakeNull();
return *this;
case nzExtend_Null:
return *this; //
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return NzVector3<T>();
}
template<typename T>
bool NzAxisAlignedBox<T>::operator==(const NzAxisAlignedBox& box) const
{
if (extend == box.extend)
return cube == box.cube;
else
return false;
}
template<typename T>
bool NzAxisAlignedBox<T>::operator!=(const NzAxisAlignedBox& box) const
{
return !operator==(box);
}
template<typename T>
NzAxisAlignedBox<T> NzAxisAlignedBox<T>::Infinite()
{
NzAxisAlignedBox box;
box.MakeInfinite();
return box;
}
template<typename T>
NzAxisAlignedBox<T> NzAxisAlignedBox<T>::Lerp(const NzAxisAlignedBox& from, const NzAxisAlignedBox& 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:
return NzCube<T>::Lerp(from.cube, to.cube, interpolation);
case nzExtend_Infinite:
return Infinite();
case nzExtend_Null:
return from.cube * interpolation;
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (From AABB) (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.cube * (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 AABB) (0x" + NzString::Number(from.extend, 16) + ')');
return Null();
}
}
// Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (To AABB) (0x" + NzString::Number(from.extend, 16) + ')');
return Null();
}
template<typename T>
NzAxisAlignedBox<T> NzAxisAlignedBox<T>::Null()
{
NzAxisAlignedBox box;
box.MakeNull();
return box;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox<T>& box)
{
out << box.ToString();
return out;
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,70 @@
// 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
#ifndef NAZARA_BOUNDINGBOX_HPP
#define NAZARA_BOUNDINGBOX_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/OrientedCube.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzBoundingBox
{
public:
NzBoundingBox();
NzBoundingBox(nzExtend Extend);
NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth);
NzBoundingBox(const NzCube<T>& Cube);
NzBoundingBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzBoundingBox(const NzBoundingBox<U>& box);
NzBoundingBox(const NzBoundingBox& box) = default;
~NzBoundingBox() = default;
bool IsFinite() const;
bool IsInfinite() const;
bool IsNull() const;
NzBoundingBox& MakeInfinite();
NzBoundingBox& MakeNull();
NzBoundingBox& Set(nzExtend Extend);
NzBoundingBox& Set(T X, T Y, T Z, T Width, T Height, T Depth);
NzBoundingBox& Set(const NzBoundingBox<T>& box);
NzBoundingBox& Set(const NzCube<T>& Cube);
NzBoundingBox& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzBoundingBox& Set(const NzBoundingBox<U>& box);
NzString ToString() const;
void Update(const NzMatrix4<T>& transformMatrix);
NzBoundingBox operator*(T scalar) const;
NzBoundingBox& operator*=(T scalar);
bool operator==(const NzBoundingBox& box) const;
bool operator!=(const NzBoundingBox& box) const;
static NzBoundingBox Infinite();
static NzBoundingBox Lerp(const NzBoundingBox& from, const NzBoundingBox& to, T interpolation);
static NzBoundingBox Null();
nzExtend extend;
NzCube<T> aabb;
NzOrientedCube<T> obb;
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzBoundingBox<T>& box);
typedef NzBoundingBox<double> NzBoundingBoxd;
typedef NzBoundingBox<float> NzBoundingBoxf;
#include <Nazara/Math/BoundingBox.inl>
#endif // NAZARA_BOUNDINGBOX_HPP

View File

@@ -0,0 +1,295 @@
// 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 <Nazara/Core/StringStream.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Basic.hpp>
#include <algorithm>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzBoundingBox<T>::NzBoundingBox() :
extend(nzExtend_Null)
{
}
template<typename T>
NzBoundingBox<T>::NzBoundingBox(nzExtend Extend)
{
Set(Extend);
}
template<typename T>
NzBoundingBox<T>::NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
template<typename T>
NzBoundingBox<T>::NzBoundingBox(const NzCube<T>& Cube)
{
Set(Cube);
}
template<typename T>
NzBoundingBox<T>::NzBoundingBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzBoundingBox<T>::NzBoundingBox(const NzBoundingBox<U>& box)
{
Set(box);
}
template<typename T>
bool NzBoundingBox<T>::IsFinite() const
{
return extend == nzExtend_Finite;
}
template<typename T>
bool NzBoundingBox<T>::IsInfinite() const
{
return extend == nzExtend_Infinite;
}
template<typename T>
bool NzBoundingBox<T>::IsNull() const
{
return extend == nzExtend_Null;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::MakeInfinite()
{
extend = nzExtend_Infinite;
return *this;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::MakeNull()
{
extend = nzExtend_Null;
return *this;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(nzExtend Extend)
{
extend = Extend;
return *this;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::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<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzBoundingBox<T>& box)
{
obb.Set(box.obb); // Seul l'OBB est importante pour la suite
return *this;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzCube<T>& Cube)
{
obb.Set(Cube);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
obb.Set(vec1, vec2);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
template<typename U>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzBoundingBox<U>& box)
{
obb.Set(box.obb);
extend = box.extend;
return *this;
}
template<typename T>
NzString NzBoundingBox<T>::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<typename T>
void NzBoundingBox<T>::Update(const NzMatrix4<T>& transformMatrix)
{
aabb.Set(obb.localCube);
aabb.Transform(transformMatrix);
obb.Update(transformMatrix);
}
template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::operator*(T scalar) const
{
NzBoundingBox box(*this);
box *= scalar;
return box;
}
template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::operator*=(T scalar)
{
aabb *= scalar;
obb *= scalar;
}
template<typename T>
bool NzBoundingBox<T>::operator==(const NzBoundingBox& box) const
{
if (extend == box.extend)
return obb == box.obb;
else
return false;
}
template<typename T>
bool NzBoundingBox<T>::operator!=(const NzBoundingBox& box) const
{
return !operator==(box);
}
template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::Infinite()
{
NzBoundingBox box;
box.MakeInfinite();
return box;
}
template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::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<T>::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<typename T>
NzBoundingBox<T> NzBoundingBox<T>::Null()
{
NzBoundingBox box;
box.MakeNull();
return box;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzBoundingBox<T>& box)
{
out << box.ToString();
return out;
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -8,9 +8,10 @@
#define NAZARA_FRUSTUM_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/AxisAlignedBox.hpp>
#include <Nazara/Math/BoundingBox.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/OrientedCube.hpp>
#include <Nazara/Math/Plane.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp>
@@ -26,8 +27,9 @@ class NzFrustum
NzFrustum& Build(T angle, T ratio, T zNear, T zFar, const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up = NzVector3<T>::Up());
bool Contains(const NzAxisAlignedBox<T>& box) const;
bool Contains(const NzBoundingBox<T>& box) const;
bool Contains(const NzCube<T>& cube) const;
bool Contains(const NzOrientedCube<T>& orientedCube) const;
bool Contains(const NzSphere<T>& sphere) const;
bool Contains(const NzVector3<T>& point) const;
bool Contains(const NzVector3<T>* points, unsigned int pointCount) const;
@@ -38,8 +40,9 @@ class NzFrustum
const NzVector3<T>& GetCorner(nzCorner corner) const;
const NzPlane<T>& GetPlane(nzFrustumPlane plane) const;
nzIntersectionSide Intersect(const NzAxisAlignedBox<T>& box) const;
nzIntersectionSide Intersect(const NzBoundingBox<T>& box) const;
nzIntersectionSide Intersect(const NzCube<T>& cube) const;
nzIntersectionSide Intersect(const NzOrientedCube<T>& orientedCube) const;
nzIntersectionSide Intersect(const NzSphere<T>& sphere) const;
nzIntersectionSide Intersect(const NzVector3<T>* points, unsigned int pointCount) const;

View File

@@ -66,12 +66,12 @@ NzFrustum<T>& NzFrustum<T>::Build(T angle, T ratio, T zNear, T zFar, const NzVec
}
template<typename T>
bool NzFrustum<T>::Contains(const NzAxisAlignedBox<T>& box) const
bool NzFrustum<T>::Contains(const NzBoundingBox<T>& box) const
{
switch (box.extend)
{
case nzExtend_Finite:
return Contains(box.cube);
return Contains(box.aabb) && Contains(box.obb);
case nzExtend_Infinite:
return true;
@@ -97,6 +97,12 @@ bool NzFrustum<T>::Contains(const NzCube<T>& cube) const
return true;
}
template<typename T>
bool NzFrustum<T>::Contains(const NzOrientedCube<T>& orientedCube) const
{
return Contains(&orientedCube[0], 8);
}
template<typename T>
bool NzFrustum<T>::Contains(const NzSphere<T>& sphere) const
{
@@ -347,12 +353,12 @@ const NzPlane<T>& NzFrustum<T>::GetPlane(nzFrustumPlane plane) const
}
template<typename T>
nzIntersectionSide NzFrustum<T>::Intersect(const NzAxisAlignedBox<T>& box) const
nzIntersectionSide NzFrustum<T>::Intersect(const NzBoundingBox<T>& box) const
{
switch (box.extend)
{
case nzExtend_Finite:
return Intersect(box.cube);
return Intersect(box.aabb) && Intersect(box.obb); // Test de l'AABB et puis de l'OBB
case nzExtend_Infinite:
return nzIntersectionSide_Intersecting;
@@ -382,6 +388,12 @@ nzIntersectionSide NzFrustum<T>::Intersect(const NzCube<T>& cube) const
return side;
}
template<typename T>
nzIntersectionSide NzFrustum<T>::Intersect(const NzOrientedCube<T>& orientedCube) const
{
return Intersect(&orientedCube[0], 8);
}
template<typename T>
nzIntersectionSide NzFrustum<T>::Intersect(const NzSphere<T>& sphere) const
{

View File

@@ -88,7 +88,7 @@ class NzMatrix4
operator const T*() const;
T& operator()(unsigned int x, unsigned int y);
const T& operator()(unsigned int x, unsigned int y) const;
T operator()(unsigned int x, unsigned int y) const;
NzMatrix4& operator=(const NzMatrix4& matrix) = default;

View File

@@ -769,7 +769,7 @@ T& NzMatrix4<T>::operator()(unsigned int x, unsigned int y)
}
template<typename T>
const T& NzMatrix4<T>::operator()(unsigned int x, unsigned int y) const
T NzMatrix4<T>::operator()(unsigned int x, unsigned int y) const
{
#if NAZARA_MATH_SAFE
if (x > 3 || y > 3)