Adding some methods to Cube class
Former-commit-id: b8a72658aa97841156910e8ec1120d109069fce1
This commit is contained in:
parent
a9b538de20
commit
283b551d56
|
|
@ -9,7 +9,9 @@
|
||||||
|
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Math/Enums.hpp>
|
#include <Nazara/Math/Enums.hpp>
|
||||||
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
#include <Nazara/Math/Rect.hpp>
|
#include <Nazara/Math/Rect.hpp>
|
||||||
|
#include <Nazara/Math/Sphere.hpp>
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -33,12 +35,15 @@ class NzCube
|
||||||
NzCube& ExtendTo(const NzVector3<T>& point);
|
NzCube& ExtendTo(const NzVector3<T>& point);
|
||||||
NzCube& ExtendTo(const NzCube& cube);
|
NzCube& ExtendTo(const NzCube& cube);
|
||||||
|
|
||||||
|
NzSphere<T> GetBoundingSphere() const;
|
||||||
NzVector3<T> GetCorner(nzCorner corner) const;
|
NzVector3<T> GetCorner(nzCorner corner) const;
|
||||||
NzVector3<T> GetCenter() const;
|
NzVector3<T> GetCenter() const;
|
||||||
NzVector3<T> GetNegativeVertex(const NzVector3<T>& normal) const;
|
NzVector3<T> GetNegativeVertex(const NzVector3<T>& normal) const;
|
||||||
NzVector3<T> GetPosition() const;
|
NzVector3<T> GetPosition() const;
|
||||||
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
|
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
|
||||||
|
T GetRadius() const;
|
||||||
NzVector3<T> GetSize() const;
|
NzVector3<T> GetSize() const;
|
||||||
|
T GetSquaredRadius() const;
|
||||||
|
|
||||||
bool Intersect(const NzCube& cube, NzCube* intersection = nullptr) const;
|
bool Intersect(const NzCube& cube, NzCube* intersection = nullptr) const;
|
||||||
|
|
||||||
|
|
@ -55,6 +60,8 @@ class NzCube
|
||||||
|
|
||||||
NzString ToString() const;
|
NzString ToString() const;
|
||||||
|
|
||||||
|
NzCube& Transform(const NzMatrix4<T>& matrix, bool applyTranslation = true);
|
||||||
|
|
||||||
T& operator[](unsigned int i);
|
T& operator[](unsigned int i);
|
||||||
T operator[](unsigned int i) const;
|
T operator[](unsigned int i) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,10 +138,16 @@ NzVector3<T> NzCube<T>::GetCorner(nzCorner corner) const
|
||||||
return NzVector3f();
|
return NzVector3f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzSphere<T> NzCube<T>::GetBoundingSphere() const
|
||||||
|
{
|
||||||
|
return NzSphere<T>(GetCenter(), GetRadius());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzVector3<T> NzCube<T>::GetCenter() const
|
NzVector3<T> NzCube<T>::GetCenter() const
|
||||||
{
|
{
|
||||||
return NzVector3<T>(x + width/F(2.0), y + height/F(2.0), z + depth/F(2.0));
|
return NzVector3<T>(x + width*F(0.5), y + height*F(0.5), z + depth*F(0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -184,12 +190,27 @@ NzVector3<T> NzCube<T>::GetPositiveVertex(const NzVector3<T>& normal) const
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T NzCube<T>::GetRadius() const
|
||||||
|
{
|
||||||
|
return std::sqrt(GetSquaredRadius());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzVector3<T> NzCube<T>::GetSize() const
|
NzVector3<T> NzCube<T>::GetSize() const
|
||||||
{
|
{
|
||||||
return NzVector3<T>(width, height, depth);
|
return NzVector3<T>(width, height, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T NzCube<T>::GetSquaredRadius() const
|
||||||
|
{
|
||||||
|
NzVector3<T> size(GetSize());
|
||||||
|
size *= F(0.5); // La taille étant relative à la position (minimum) du cube et non pas à son centre
|
||||||
|
|
||||||
|
return size.GetSquaredLength();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool NzCube<T>::Intersect(const NzCube& cube, NzCube* intersection) const
|
bool NzCube<T>::Intersect(const NzCube& cube, NzCube* intersection) const
|
||||||
{
|
{
|
||||||
|
|
@ -319,6 +340,19 @@ NzString NzCube<T>::ToString() const
|
||||||
return ss << "Cube(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
|
return ss << "Cube(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzCube<T>& NzCube<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation)
|
||||||
|
{
|
||||||
|
NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
|
||||||
|
NzVector3<T> halfSize = 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);
|
||||||
|
|
||||||
|
return Set(center - halfSize, center + halfSize);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& NzCube<T>::operator[](unsigned int i)
|
T& NzCube<T>::operator[](unsigned int i)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue