Moved AxisAlignedBox to mathematic module
Former-commit-id: 2cb5b151941a431b5c12457f0decf7b39195052d
This commit is contained in:
parent
d56900fe01
commit
add363a290
|
|
@ -0,0 +1,87 @@
|
|||
// 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
|
||||
|
|
@ -0,0 +1,610 @@
|
|||
// 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_Infinite;
|
||||
|
||||
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; //
|
||||
|
||||
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>
|
||||
|
|
@ -21,6 +21,15 @@ enum nzCorner
|
|||
nzCorner_Max = nzCorner_NearRightTop
|
||||
};
|
||||
|
||||
enum nzExtend
|
||||
{
|
||||
nzExtend_Finite,
|
||||
nzExtend_Infinite,
|
||||
nzExtend_Null,
|
||||
|
||||
nzExtend_Max = nzExtend_Null
|
||||
};
|
||||
|
||||
enum nzFrustumPlane
|
||||
{
|
||||
nzFrustumPlane_Bottom,
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Utility/SubMesh.hpp>
|
||||
|
||||
class NzAxisAlignedBox;
|
||||
class NzSkeleton;
|
||||
|
||||
class NAZARA_API NzDebugDrawer
|
||||
{
|
||||
public:
|
||||
static void Draw(const NzAxisAlignedBox& aabb);
|
||||
static void Draw(const NzAxisAlignedBoxf& aabb);
|
||||
static void Draw(const NzCubef& cube);
|
||||
static void Draw(const NzCubei& cube);
|
||||
static void Draw(const NzCubeui& cube);
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#ifndef NAZARA_AXISALIGNEDBOX_HPP
|
||||
#define NAZARA_AXISALIGNEDBOX_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
class NAZARA_API NzAxisAlignedBox
|
||||
{
|
||||
public:
|
||||
NzAxisAlignedBox();
|
||||
NzAxisAlignedBox(const NzCubef& cube);
|
||||
NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2);
|
||||
NzAxisAlignedBox(nzExtend extend);
|
||||
|
||||
bool Contains(const NzAxisAlignedBox& box);
|
||||
bool Contains(const NzVector3f& vector);
|
||||
|
||||
void ExtendTo(const NzAxisAlignedBox& box);
|
||||
void ExtendTo(const NzVector3f& vector);
|
||||
|
||||
NzVector3f GetCorner(nzCorner corner) const;
|
||||
NzCubef GetCube() const;
|
||||
nzExtend GetExtend() const;
|
||||
NzVector3f GetMaximum() const;
|
||||
NzVector3f GetMinimum() const;
|
||||
|
||||
bool IsFinite() const;
|
||||
bool IsInfinite() const;
|
||||
bool IsNull() const;
|
||||
|
||||
void SetInfinite();
|
||||
void SetExtends(const NzVector3f& vec1, const NzVector3f& vec2);
|
||||
void SetNull();
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
void Transform(const NzMatrix4f& matrix, bool applyTranslation = true);
|
||||
|
||||
operator NzString() const;
|
||||
|
||||
static NzAxisAlignedBox Lerp(const NzAxisAlignedBox& from, const NzAxisAlignedBox& to, float interpolation);
|
||||
|
||||
static const NzAxisAlignedBox Infinite;
|
||||
static const NzAxisAlignedBox Null;
|
||||
|
||||
private:
|
||||
nzExtend m_extend;
|
||||
NzCubef m_cube;
|
||||
};
|
||||
|
||||
NAZARA_API std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb);
|
||||
|
||||
#endif // NAZARA_AXISALIGNEDBOX_HPP
|
||||
|
|
@ -128,15 +128,6 @@ enum nzEventType
|
|||
nzEventType_Max = nzEventType_TextEntered
|
||||
};
|
||||
|
||||
enum nzExtend
|
||||
{
|
||||
nzExtend_Finite,
|
||||
nzExtend_Infinite,
|
||||
nzExtend_Null,
|
||||
|
||||
nzExtend_Max = nzExtend_Null
|
||||
};
|
||||
|
||||
enum nzImageType
|
||||
{
|
||||
nzImageType_1D,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
|
|||
|
||||
void GenerateAABBs();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const override;
|
||||
const NzAxisAlignedBoxf& GetAABB() const override;
|
||||
nzAnimationType GetAnimationType() const override;
|
||||
unsigned int GetFrameCount() const;
|
||||
const NzIndexBuffer* GetIndexBuffer() const override;
|
||||
|
|
@ -46,7 +46,7 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
|
|||
bool IsAnimated() const override;
|
||||
bool IsValid();
|
||||
|
||||
void SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb);
|
||||
void SetAABB(unsigned int frameIndex, const NzAxisAlignedBoxf& aabb);
|
||||
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
||||
void SetNormal(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& normal);
|
||||
void SetPosition(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& position);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <Nazara/Core/ResourceListener.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Math/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/SubMesh.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
|
|
@ -59,7 +59,7 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
|||
void GenerateNormalsAndTangents();
|
||||
void GenerateTangents();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const;
|
||||
const NzAxisAlignedBoxf& GetAABB() const;
|
||||
NzString GetAnimation() const;
|
||||
nzAnimationType GetAnimationType() const;
|
||||
unsigned int GetJointCount() const;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class NAZARA_API NzSkeletalMesh final : public NzSubMesh
|
|||
|
||||
void Finish();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const;
|
||||
const NzAxisAlignedBoxf& GetAABB() const;
|
||||
nzAnimationType GetAnimationType() const final;
|
||||
void* GetBindPoseBuffer();
|
||||
const void* GetBindPoseBuffer() const;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#define NAZARA_SKELETON_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Math/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Utility/Joint.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ class NAZARA_API NzSkeleton
|
|||
bool Create(unsigned int jointCount);
|
||||
void Destroy();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const;
|
||||
const NzAxisAlignedBoxf& GetAABB() const;
|
||||
NzJoint* GetJoint(const NzString& jointName);
|
||||
NzJoint* GetJoint(unsigned int index);
|
||||
const NzJoint* GetJoint(const NzString& jointName) const;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener
|
|||
|
||||
bool GenerateAABB();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const override;
|
||||
const NzAxisAlignedBoxf& GetAABB() const override;
|
||||
nzAnimationType GetAnimationType() const final;
|
||||
const NzIndexBuffer* GetIndexBuffer() const override;
|
||||
NzVertexBuffer* GetVertexBuffer() override;
|
||||
|
|
@ -33,13 +33,13 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener
|
|||
bool IsAnimated() const final;
|
||||
bool IsValid() const;
|
||||
|
||||
void SetAABB(const NzAxisAlignedBox& aabb);
|
||||
void SetAABB(const NzAxisAlignedBoxf& aabb);
|
||||
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
||||
|
||||
private:
|
||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||
|
||||
NzAxisAlignedBox m_aabb;
|
||||
NzAxisAlignedBoxf m_aabb;
|
||||
const NzIndexBuffer* m_indexBuffer = nullptr;
|
||||
NzVertexBuffer* m_vertexBuffer = nullptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Math/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
|
|
@ -27,7 +27,7 @@ class NAZARA_API NzSubMesh : public NzResource
|
|||
|
||||
virtual void Finish() = 0; ///DOC: Mets le mesh dans sa position d'origine et calcule son AABB
|
||||
|
||||
virtual const NzAxisAlignedBox& GetAABB() const = 0;
|
||||
virtual const NzAxisAlignedBoxf& GetAABB() const = 0;
|
||||
virtual nzAnimationType GetAnimationType() const = 0;
|
||||
virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
|
||||
unsigned int GetMaterialIndex() const;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
|
|
@ -32,7 +31,7 @@ namespace
|
|||
static int colorLocation = -1;
|
||||
}
|
||||
|
||||
void NzDebugDrawer::Draw(const NzAxisAlignedBox& aabb)
|
||||
void NzDebugDrawer::Draw(const NzAxisAlignedBoxf& aabb)
|
||||
{
|
||||
if (!aabb.IsFinite())
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,279 +0,0 @@
|
|||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox() :
|
||||
m_extend(nzExtend_Null)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(const NzCubef& cube) :
|
||||
m_extend(nzExtend_Finite),
|
||||
m_cube(cube)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2) :
|
||||
m_extend(nzExtend_Finite),
|
||||
m_cube(vec1, vec2)
|
||||
{
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::NzAxisAlignedBox(nzExtend extend) :
|
||||
m_extend(extend)
|
||||
{
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::Contains(const NzAxisAlignedBox& box)
|
||||
{
|
||||
if (m_extend == nzExtend_Null || box.m_extend == nzExtend_Null)
|
||||
return false;
|
||||
else if (m_extend == nzExtend_Infinite || box.m_extend == nzExtend_Infinite)
|
||||
return true;
|
||||
|
||||
return m_cube.Contains(box.m_cube);
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::Contains(const NzVector3f& vector)
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return m_cube.Contains(vector);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return true;
|
||||
|
||||
case nzExtend_Null:
|
||||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Extend type not handled (0x" + NzString::Number(m_extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box)
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
switch (box.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
m_cube.ExtendTo(box.m_cube);
|
||||
break;
|
||||
|
||||
case nzExtend_Infinite:
|
||||
SetInfinite();
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzExtend_Infinite:
|
||||
// Rien à faire
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
operator=(box);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::ExtendTo(const NzVector3f& vector)
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
m_cube.ExtendTo(vector);
|
||||
break;
|
||||
|
||||
case nzExtend_Infinite:
|
||||
// Rien à faire
|
||||
break;
|
||||
|
||||
case nzExtend_Null:
|
||||
m_extend = nzExtend_Finite;
|
||||
m_cube.Set(vector, vector);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NzVector3f NzAxisAlignedBox::GetCorner(nzCorner corner) const
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return m_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 NzVector3f();
|
||||
|
||||
case nzExtend_Null:
|
||||
return NzVector3f::Zero();
|
||||
}
|
||||
|
||||
NazaraError("Extend type not handled (0x" + NzString::Number(m_extend, 16) + ')');
|
||||
return NzVector3f();
|
||||
}
|
||||
|
||||
NzCubef NzAxisAlignedBox::GetCube() const
|
||||
{
|
||||
return m_cube;
|
||||
}
|
||||
|
||||
nzExtend NzAxisAlignedBox::GetExtend() const
|
||||
{
|
||||
return m_extend;
|
||||
}
|
||||
|
||||
NzVector3f NzAxisAlignedBox::GetMaximum() const
|
||||
{
|
||||
return m_cube.GetPosition() + m_cube.GetSize();
|
||||
}
|
||||
|
||||
NzVector3f NzAxisAlignedBox::GetMinimum() const
|
||||
{
|
||||
return m_cube.GetPosition();
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::IsFinite() const
|
||||
{
|
||||
return m_extend == nzExtend_Finite;
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::IsInfinite() const
|
||||
{
|
||||
return m_extend == nzExtend_Infinite;
|
||||
}
|
||||
|
||||
bool NzAxisAlignedBox::IsNull() const
|
||||
{
|
||||
return m_extend == nzExtend_Null;
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::SetInfinite()
|
||||
{
|
||||
m_extend = nzExtend_Infinite;
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::SetExtends(const NzVector3f& vec1, const NzVector3f& vec2)
|
||||
{
|
||||
m_extend = nzExtend_Finite;
|
||||
m_cube.Set(vec1, vec2);
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::SetNull()
|
||||
{
|
||||
m_extend = nzExtend_Null;
|
||||
}
|
||||
|
||||
NzString NzAxisAlignedBox::ToString() const
|
||||
{
|
||||
switch (m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return "NzAxisAlignedBox(min=" + GetMinimum().ToString() + ", max=" + GetMaximum().ToString() + ')';
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return "NzAxisAlignedBox(Infinite)";
|
||||
|
||||
case nzExtend_Null:
|
||||
return "NzAxisAlignedBox(Null)";
|
||||
}
|
||||
|
||||
return "NzAxisAlignedBox(ERROR)";
|
||||
}
|
||||
|
||||
void NzAxisAlignedBox::Transform(const NzMatrix4f& matrix, bool applyTranslation)
|
||||
{
|
||||
if (m_extend != nzExtend_Finite)
|
||||
return;
|
||||
|
||||
NzVector3f center = matrix.Transform(m_cube.GetCenter(), (applyTranslation) ? 1.f : 0.f); // Valeur multipliant la translation
|
||||
NzVector3f halfSize = m_cube.GetSize() * 0.5f;
|
||||
|
||||
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);
|
||||
|
||||
m_cube.Set(center - halfSize, center + halfSize);
|
||||
}
|
||||
|
||||
NzAxisAlignedBox::operator NzString() const
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
NzAxisAlignedBox NzAxisAlignedBox::Lerp(const NzAxisAlignedBox& from, const NzAxisAlignedBox& to, float 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.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
{
|
||||
switch (from.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return NzCubef::Lerp(from.m_cube, to.m_cube, interpolation);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return Infinite;
|
||||
|
||||
case nzExtend_Null:
|
||||
return from.m_cube * interpolation;
|
||||
}
|
||||
}
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return Infinite; // Un petit peu d'infini est infini quand même ;)
|
||||
|
||||
case nzExtend_Null:
|
||||
{
|
||||
switch (from.m_extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return from.m_cube * (1.f - interpolation);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return Infinite;
|
||||
|
||||
case nzExtend_Null:
|
||||
return Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Null;
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox NzAxisAlignedBox::Infinite(nzExtend_Infinite);
|
||||
const NzAxisAlignedBox NzAxisAlignedBox::Null(nzExtend_Null);
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb)
|
||||
{
|
||||
out << aabb.ToString();
|
||||
return out;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
struct NzKeyframeMeshImpl
|
||||
{
|
||||
NzAxisAlignedBox* aabb;
|
||||
NzAxisAlignedBoxf* aabb;
|
||||
NzVector2f* uv;
|
||||
NzVector3f* normals;
|
||||
NzVector3f* positions;
|
||||
|
|
@ -59,7 +59,7 @@ bool NzKeyframeMesh::Create(NzVertexBuffer* vertexBuffer, unsigned int frameCoun
|
|||
vertexBuffer->AddResourceReference();
|
||||
|
||||
m_impl = new NzKeyframeMeshImpl;
|
||||
m_impl->aabb = new NzAxisAlignedBox[frameCount+1]; // La première case représente l'AABB interpolée
|
||||
m_impl->aabb = new NzAxisAlignedBoxf[frameCount+1]; // La première case représente l'AABB interpolée
|
||||
m_impl->frameCount = frameCount;
|
||||
m_impl->vertexBuffer = vertexBuffer;
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ void NzKeyframeMesh::GenerateAABBs()
|
|||
unsigned int vertexCount = m_impl->vertexBuffer->GetVertexCount();
|
||||
for (unsigned int i = 0; i < m_impl->frameCount; ++i)
|
||||
{
|
||||
NzAxisAlignedBox& aabb = m_impl->aabb[i+1]; // l'AABB 0 est celle qui est interpolée
|
||||
NzAxisAlignedBoxf& aabb = m_impl->aabb[i+1]; // l'AABB 0 est celle qui est interpolée
|
||||
if (aabb.IsNull())
|
||||
{
|
||||
// Génération de l'AABB selon la position
|
||||
|
|
@ -134,13 +134,15 @@ void NzKeyframeMesh::GenerateAABBs()
|
|||
}
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzKeyframeMesh::GetAABB() const
|
||||
const NzAxisAlignedBoxf& NzKeyframeMesh::GetAABB() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Keyframe mesh not created");
|
||||
return NzAxisAlignedBox::Null;
|
||||
|
||||
static NzAxisAlignedBoxf dummy(nzExtend_Null);
|
||||
return dummy;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -402,7 +404,7 @@ bool NzKeyframeMesh::IsValid()
|
|||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
void NzKeyframeMesh::SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb)
|
||||
void NzKeyframeMesh::SetAABB(unsigned int frameIndex, const NzAxisAlignedBoxf& aabb)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
|
|
@ -500,7 +502,7 @@ void NzKeyframeMesh::SetPosition(unsigned int frameIndex, unsigned int vertexInd
|
|||
unsigned int index = frameIndex*vertexCount + vertexIndex;
|
||||
|
||||
m_impl->positions[index] = position;
|
||||
m_impl->aabb[frameIndex+1].SetNull(); // Invalidation de l'AABB
|
||||
m_impl->aabb[frameIndex+1].MakeNull(); // Invalidation de l'AABB
|
||||
}
|
||||
|
||||
void NzKeyframeMesh::SetTangent(unsigned int frameIndex, unsigned int vertexIndex, const NzVector3f& tangent)
|
||||
|
|
@ -564,7 +566,7 @@ void NzKeyframeMesh::InterpolateImpl(unsigned int frameA, unsigned int frameB, f
|
|||
#endif
|
||||
|
||||
// Interpolation de l'AABB
|
||||
m_impl->aabb[0] = NzAxisAlignedBox::Lerp(m_impl->aabb[frameA+1], m_impl->aabb[frameB+1], interpolation);
|
||||
m_impl->aabb[0] = NzAxisAlignedBoxf::Lerp(m_impl->aabb[frameA+1], m_impl->aabb[frameB+1], interpolation);
|
||||
|
||||
NzMeshVertex* vertex = reinterpret_cast<NzMeshVertex*>(m_impl->vertexBuffer->Map(nzBufferAccess_DiscardAndWrite));
|
||||
if (!vertex)
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ bool NzMD5AnimParser::ParseBounds()
|
|||
return false;
|
||||
}
|
||||
|
||||
m_frames[i].aabb.SetExtends(min, max);
|
||||
m_frames[i].aabb.Set(min, max);
|
||||
}
|
||||
|
||||
if (!Advance())
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Math/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <vector>
|
||||
|
||||
class NzMD5AnimParser
|
||||
|
|
@ -34,7 +34,7 @@ class NzMD5AnimParser
|
|||
};
|
||||
|
||||
std::vector<Joint> joints;
|
||||
NzAxisAlignedBox aabb;
|
||||
NzAxisAlignedBoxf aabb;
|
||||
};
|
||||
|
||||
struct Joint
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ struct NzMeshImpl
|
|||
std::vector<NzString> materials;
|
||||
std::vector<NzSubMesh*> subMeshes;
|
||||
nzAnimationType animationType;
|
||||
NzAxisAlignedBox aabb;
|
||||
NzAxisAlignedBoxf aabb;
|
||||
NzSkeleton skeleton; // Uniquement pour les meshs squelettiques
|
||||
NzString animationPath;
|
||||
unsigned int jointCount; // Uniquement pour les meshs squelettiques
|
||||
|
|
@ -77,7 +77,7 @@ bool NzMesh::AddSubMesh(NzSubMesh* subMesh)
|
|||
subMesh->AddResourceListener(this, m_impl->subMeshes.size());
|
||||
subMesh->Finish();
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->aabb.MakeNull(); // On invalide l'AABB
|
||||
m_impl->subMeshes.push_back(subMesh);
|
||||
|
||||
return true;
|
||||
|
|
@ -123,7 +123,7 @@ bool NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh)
|
|||
subMesh->AddResourceListener(this, index);
|
||||
subMesh->Finish();
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->aabb.MakeNull(); // On invalide l'AABB
|
||||
m_impl->subMeshes.push_back(subMesh);
|
||||
m_impl->subMeshMap[identifier] = index;
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ void NzMesh::Animate(const NzAnimation* animation, unsigned int frameA, unsigned
|
|||
break;
|
||||
}
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->aabb.MakeNull(); // On invalide l'AABB
|
||||
}
|
||||
|
||||
bool NzMesh::CreateKeyframe()
|
||||
|
|
@ -417,13 +417,15 @@ void NzMesh::GenerateTangents()
|
|||
}
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzMesh::GetAABB() const
|
||||
const NzAxisAlignedBoxf& NzMesh::GetAABB() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Mesh not created");
|
||||
return NzAxisAlignedBox::Null;
|
||||
|
||||
static NzAxisAlignedBoxf dummy(nzExtend_Null);
|
||||
return dummy;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -698,7 +700,7 @@ void NzMesh::InvalidateAABB() const
|
|||
}
|
||||
#endif
|
||||
|
||||
m_impl->aabb.SetNull();
|
||||
m_impl->aabb.MakeNull();
|
||||
}
|
||||
|
||||
bool NzMesh::HasSubMesh(const NzString& identifier) const
|
||||
|
|
@ -789,7 +791,7 @@ void NzMesh::RemoveSubMesh(const NzString& identifier)
|
|||
(*it2)->RemoveResourceListener(this);
|
||||
m_impl->subMeshes.erase(it2);
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->aabb.MakeNull(); // On invalide l'AABB
|
||||
}
|
||||
|
||||
void NzMesh::RemoveSubMesh(unsigned int index)
|
||||
|
|
@ -816,7 +818,7 @@ void NzMesh::RemoveSubMesh(unsigned int index)
|
|||
(*it)->RemoveResourceListener(this);
|
||||
m_impl->subMeshes.erase(it);
|
||||
|
||||
m_impl->aabb.SetNull(); // On invalide l'AABB
|
||||
m_impl->aabb.MakeNull(); // On invalide l'AABB
|
||||
}
|
||||
|
||||
void NzMesh::SetAnimation(const NzString& animationPath)
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ struct NzSkeletalMeshImpl
|
|||
{
|
||||
std::vector<NzVertexWeight> vertexWeights;
|
||||
std::vector<NzWeight> weights;
|
||||
NzAxisAlignedBox aabb;
|
||||
NzAxisAlignedBoxf aabb;
|
||||
nzUInt8* bindPoseBuffer;
|
||||
const NzIndexBuffer* indexBuffer = nullptr;
|
||||
NzVertexBuffer* vertexBuffer;
|
||||
|
|
@ -208,13 +208,15 @@ void NzSkeletalMesh::Finish()
|
|||
Skin();
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzSkeletalMesh::GetAABB() const
|
||||
const NzAxisAlignedBoxf& NzSkeletalMesh::GetAABB() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Skeletal mesh not created");
|
||||
return NzAxisAlignedBox::Null;
|
||||
|
||||
static NzAxisAlignedBoxf dummy(nzExtend_Null);
|
||||
return dummy;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||
#include <map>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
|
|
@ -11,7 +10,7 @@ struct NzSkeletonImpl
|
|||
{
|
||||
std::map<NzString, unsigned int> jointMap; ///FIXME: unordered_map
|
||||
std::vector<NzJoint> joints;
|
||||
NzAxisAlignedBox aabb;
|
||||
NzAxisAlignedBoxf aabb;
|
||||
bool jointMapUpdated = false;
|
||||
};
|
||||
|
||||
|
|
@ -51,13 +50,15 @@ void NzSkeleton::Destroy()
|
|||
}
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzSkeleton::GetAABB() const
|
||||
const NzAxisAlignedBoxf& NzSkeleton::GetAABB() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Skeleton not created");
|
||||
return NzAxisAlignedBox::Null;
|
||||
|
||||
static NzAxisAlignedBoxf dummy(nzExtend_Null);
|
||||
return dummy;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -94,7 +95,7 @@ NzJoint* NzSkeleton::GetJoint(const NzString& jointName)
|
|||
#endif
|
||||
|
||||
// Invalidation de l'AABB
|
||||
m_impl->aabb.SetNull();
|
||||
m_impl->aabb.MakeNull();
|
||||
|
||||
return &m_impl->joints[it->second];
|
||||
}
|
||||
|
|
@ -116,7 +117,7 @@ NzJoint* NzSkeleton::GetJoint(unsigned int index)
|
|||
#endif
|
||||
|
||||
// Invalidation de l'AABB
|
||||
m_impl->aabb.SetNull();
|
||||
m_impl->aabb.MakeNull();
|
||||
|
||||
return &m_impl->joints[index];
|
||||
}
|
||||
|
|
@ -264,7 +265,7 @@ void NzSkeleton::Interpolate(const NzSkeleton& skeletonA, const NzSkeleton& skel
|
|||
for (unsigned int i = 0; i < m_impl->joints.size(); ++i)
|
||||
m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation);
|
||||
|
||||
m_impl->aabb.SetNull();
|
||||
m_impl->aabb.MakeNull();
|
||||
}
|
||||
|
||||
void NzSkeleton::Interpolate(const NzSkeleton& skeletonA, const NzSkeleton& skeletonB, float interpolation, unsigned int* indices, unsigned int indiceCount)
|
||||
|
|
@ -312,7 +313,7 @@ void NzSkeleton::Interpolate(const NzSkeleton& skeletonA, const NzSkeleton& skel
|
|||
m_impl->joints[index].Interpolate(jointsA[index], jointsB[index], interpolation);
|
||||
}
|
||||
|
||||
m_impl->aabb.SetNull();
|
||||
m_impl->aabb.MakeNull();
|
||||
}
|
||||
|
||||
bool NzSkeleton::IsValid() const
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ bool NzStaticMesh::Create(NzVertexBuffer* vertexBuffer)
|
|||
|
||||
void NzStaticMesh::Destroy()
|
||||
{
|
||||
m_aabb.SetNull();
|
||||
m_aabb.MakeNull();
|
||||
|
||||
if (m_indexBuffer)
|
||||
{
|
||||
|
|
@ -79,7 +79,7 @@ bool NzStaticMesh::GenerateAABB()
|
|||
return true;
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzStaticMesh::GetAABB() const
|
||||
const NzAxisAlignedBoxf& NzStaticMesh::GetAABB() const
|
||||
{
|
||||
return m_aabb;
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ bool NzStaticMesh::IsValid() const
|
|||
return m_vertexBuffer != nullptr;
|
||||
}
|
||||
|
||||
void NzStaticMesh::SetAABB(const NzAxisAlignedBox& aabb)
|
||||
void NzStaticMesh::SetAABB(const NzAxisAlignedBoxf& aabb)
|
||||
{
|
||||
m_aabb = aabb;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue