More Math cleanup

This commit is contained in:
SirLynix 2022-12-18 16:33:05 +01:00
parent a1e62adb71
commit 5ca7b398c2
15 changed files with 104 additions and 454 deletions

View File

@ -24,10 +24,8 @@ namespace Nz
public:
BoundingVolume();
BoundingVolume(Extend Extend);
BoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth);
BoundingVolume(const Box<T>& box);
BoundingVolume(const OrientedBox<T>& orientedBox);
BoundingVolume(const Vector3<T>& vec1, const Vector3<T>& vec2);
template<typename U> explicit BoundingVolume(const BoundingVolume<U>& volume);
BoundingVolume(const BoundingVolume& volume) = default;
~BoundingVolume() = default;
@ -40,17 +38,6 @@ namespace Nz
bool IsInfinite() const;
bool IsNull() const;
BoundingVolume& MakeInfinite();
BoundingVolume& MakeNull();
BoundingVolume& Set(Extend Extend);
BoundingVolume& Set(T X, T Y, T Z, T Width, T Height, T Depth);
BoundingVolume& Set(const BoundingVolume<T>& volume);
BoundingVolume& Set(const Box<T>& box);
BoundingVolume& Set(const OrientedBox<T>& orientedBox);
BoundingVolume& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
template<typename U> BoundingVolume& Set(const BoundingVolume<U>& volume);
std::string ToString() const;
void Update(const Matrix4<T>& transformMatrix);

View File

@ -42,28 +42,9 @@ namespace Nz
*/
template<typename T>
BoundingVolume<T>::BoundingVolume(Extend Extend)
BoundingVolume<T>::BoundingVolume(Extend Extend) :
extend(Extend)
{
Set(Extend);
}
/*!
* \brief Constructs a BoundingVolume object from its position and sizes
*
* \param X X component of position
* \param Y Y component of position
* \param Z Z component of position
* \param Width Width of the box (following X)
* \param Height Height of the box (following Y)
* \param Depth Depth of the box (following Z)
*
* \remark Aabb is uninitialized
*/
template<typename T>
BoundingVolume<T>::BoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
/*!
@ -75,9 +56,10 @@ namespace Nz
*/
template<typename T>
BoundingVolume<T>::BoundingVolume(const Box<T>& box)
BoundingVolume<T>::BoundingVolume(const Box<T>& box) :
extend(Extend::Finite),
obb(box)
{
Set(box);
}
/*!
@ -89,25 +71,10 @@ namespace Nz
*/
template<typename T>
BoundingVolume<T>::BoundingVolume(const OrientedBox<T>& orientedBox)
BoundingVolume<T>::BoundingVolume(const OrientedBox<T>& orientedBox) :
extend(Extend::Finite),
obb(orientedBox)
{
Set(orientedBox);
}
/*!
* \brief Constructs a BoundingVolume object from two vectors representing point of the space
* (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum
*
* \param vec1 First point
* \param vec2 Second point
*
* \remark Aabb is uninitialized
*/
template<typename T>
BoundingVolume<T>::BoundingVolume(const Vector3<T>& vec1, const Vector3<T>& vec2)
{
Set(vec1, vec2);
}
/*!
@ -118,12 +85,13 @@ namespace Nz
template<typename T>
template<typename U>
BoundingVolume<T>::BoundingVolume(const BoundingVolume<U>& volume)
BoundingVolume<T>::BoundingVolume(const BoundingVolume<U>& volume) :
extend(volume.extend),
aabb(volume.aabb),
obb(volume.obb)
{
Set(volume);
}
/*!
* \brief Extends the bounding volume to contain another bounding volume
* \return A reference to the the bounding volume
@ -149,7 +117,7 @@ namespace Nz
}
case Extend::Infinite:
MakeInfinite();
extend = Extend::Infinite;
break;
case Extend::Null:
@ -219,156 +187,6 @@ namespace Nz
return extend == Extend::Null;
}
/*!
* \brief Makes the bounding volume infinite
* \return A reference to this bounding volume with Extend::Infinite for extend
*
* \see Infinite
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::MakeInfinite()
{
extend = Extend::Infinite;
return *this;
}
/*!
* \brief Makes the bounding volume null
* \return A reference to this bounding volume with Extend::Null for extend
*
* \see Null
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::MakeNull()
{
extend = Extend::Null;
return *this;
}
/*!
* \brief Sets the extend of the bounding volume from Extend
* \return A reference to this bounding volume
*
* \param Extend New extend
*
* \remark This method is meant to be called with Extend::Infinite or Extend::Null
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::Set(Extend Extend)
{
extend = Extend;
return *this;
}
/*!
* \brief Sets the components of the bounding volume
* \return A reference to this bounding volume
*
* \param X X position
* \param Y Y position
* \param Z Z position
* \param Width Width of the oriented box (following X)
* \param Height Height of the oriented box (following Y)
* \param Depth Depth of the oriented box (following Z)
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
obb.Set(X, Y, Z, Width, Height, Depth);
extend = Extend::Finite;
return *this;
}
/*!
* \brief Sets the components of the bounding volume from another bounding volume
* \return A reference to this bounding volume
*
* \param volume The other bounding volume
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::Set(const BoundingVolume<T>& volume)
{
obb.Set(volume.obb); // Only OBB is important for the moment
extend = volume.extend;
return *this;
}
/*!
* \brief Sets the components of the bounding volume from a box
* \return A reference to this bounding volume
*
* \param box Box<T> object
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::Set(const Box<T>& box)
{
obb.Set(box);
extend = Extend::Finite;
return *this;
}
/*!
* \brief Sets the components of the bounding volume from an oriented box
* \return A reference to this bounding volume
*
* \param orientedBox OrientedBox<T> object
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::Set(const OrientedBox<T>& orientedBox)
{
obb.Set(orientedBox);
extend = Extend::Finite;
return *this;
}
/*!
* \brief Sets a BoundingVolume object from two vectors representing point of the space
* (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum
*
* \param vec1 First point
* \param vec2 Second point
*/
template<typename T>
BoundingVolume<T>& BoundingVolume<T>::Set(const Vector3<T>& vec1, const Vector3<T>& vec2)
{
obb.Set(vec1, vec2);
extend = Extend::Finite;
return *this;
}
/*!
* \brief Sets the components of the bounding volume from another type of BoundingVolume
* \return A reference to this bounding volume
*
* \param volume BoundingVolume of type U to convert its components
*/
template<typename T>
template<typename U>
BoundingVolume<T>& BoundingVolume<T>::Set(const BoundingVolume<U>& volume)
{
obb.Set(volume.obb);
extend = volume.extend;
return *this;
}
/*!
* \brief Gives a string representation
* \return A string representation of the object: "BoundingVolume(localBox="")" if finite, or "BoundingVolume(Infinite)" or "BoundingVolume(Null)"
@ -491,7 +309,7 @@ namespace Nz
BoundingVolume<T> BoundingVolume<T>::Infinite()
{
BoundingVolume volume;
volume.MakeInfinite();
volume.extend = Extend::Infinite;
return volume;
}
@ -514,14 +332,6 @@ namespace Nz
template<typename T>
BoundingVolume<T> BoundingVolume<T>::Lerp(const BoundingVolume& from, const BoundingVolume& to, T interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < T(0.0) || interpolation > T(1.0))
{
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
return Null();
}
#endif
if (NumberEquals(interpolation, T(0.0)))
return from;
@ -535,18 +345,18 @@ namespace Nz
switch (from.extend)
{
case Extend::Finite:
{
BoundingVolume volume;
volume.Set(OrientedBox<T>::Lerp(from.obb, to.obb, interpolation));
return volume;
}
return BoundingVolume{ OrientedBox<T>::Lerp(from.obb, to.obb, interpolation) };
case Extend::Infinite:
return Infinite();
case Extend::Null:
return to.obb * interpolation;
{
Box<T> destBox = to.obb.localBox;
destBox.Scale(interpolation);
return { destBox };
}
}
// If we arrive here, the extend is invalid
@ -562,7 +372,12 @@ namespace Nz
switch (from.extend)
{
case Extend::Finite:
return from.obb * (T(1.0) - interpolation);
{
Box<T> fromBox = from.obb.localBox;
fromBox.Scale(T(1.0) - interpolation);
return { fromBox };
}
case Extend::Infinite:
return Infinite();
@ -593,7 +408,7 @@ namespace Nz
BoundingVolume<T> BoundingVolume<T>::Null()
{
BoundingVolume volume;
volume.MakeNull();
volume.extend = Extend::Null;
return volume;
}

View File

@ -26,9 +26,11 @@ namespace Nz
Box(T Width, T Height, T Depth);
Box(T X, T Y, T Z, T Width, T Height, T Depth);
Box(const Rect<T>& rect);
explicit Box(const Vector3<T>& lengths);
explicit Box(const Vector3<T>& pos, const Vector3<T>& lengths);
template<typename U> explicit Box(const Box<U>& box);
Box(const Box& box) = default;
Box(const Box&) = default;
Box(Box&&) noexcept = default;
~Box() = default;
bool Contains(T X, T Y, T Z) const;
@ -69,7 +71,7 @@ namespace Nz
const T& operator[](std::size_t i) const;
Box& operator=(const Box&) = default;
Box& operator=(Box&&) = default;
Box& operator=(Box&&) noexcept = default;
bool operator==(const Box& box) const;
bool operator!=(const Box& box) const;

View File

@ -78,6 +78,19 @@ namespace Nz
{
}
/*!
* \brief Constructs a Rect object from a vector representing its length
* The position will be set to zero
*
* \param pos (X, Y, Z) of the box
* \param lengths (Width, Height, Depth) of the box
*/
template<typename T>
Box<T>::Box(const Vector3<T>& lengths) :
Box(Vector3<T>::Zero(), lengths)
{
}
/*!
* \brief Constructs a Box object from two vector representing position and lengths
*

View File

@ -22,11 +22,10 @@ namespace Nz
{
public:
OrientedBox() = default;
OrientedBox(T X, T Y, T Z, T Width, T Height, T Depth);
OrientedBox(const Box<T>& box);
OrientedBox(const Vector3<T>& vec1, const Vector3<T>& vec2);
template<typename U> explicit OrientedBox(const OrientedBox<U>& orientedBox);
OrientedBox(const OrientedBox& orientedBox) = default;
OrientedBox(const OrientedBox&) = default;
OrientedBox(OrientedBox&&) noexcept = default;
~OrientedBox() = default;
const Vector3<T>& GetCorner(BoxCorner corner) const;
@ -34,25 +33,16 @@ namespace Nz
bool IsValid() const;
OrientedBox& MakeZero();
OrientedBox& Set(T X, T Y, T Z, T Width, T Height, T Depth);
OrientedBox& Set(const Box<T>& box);
OrientedBox& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
template<typename U> OrientedBox& Set(const OrientedBox<U>& orientedBox);
std::string ToString() const;
void Update(const Matrix4<T>& transformMatrix);
void Update(const Vector3<T>& transformMatrix);
Vector3<T>& operator()(unsigned int i);
Vector3<T> operator()(unsigned int i) const;
const Vector3<T>& operator()(unsigned int i) const;
OrientedBox operator*(T scalar) const;
OrientedBox& operator=(const OrientedBox& other) = default;
OrientedBox& operator*=(T scalar);
OrientedBox& operator=(const OrientedBox&) = default;
OrientedBox& operator=(OrientedBox&&) noexcept = default;
bool operator==(const OrientedBox& box) const;
bool operator!=(const OrientedBox& box) const;

View File

@ -21,23 +21,6 @@ namespace Nz
* \remark You need to call Update not to have undefined behaviour
*/
/*!
* \brief Constructs a OrientedBox object from its position and sizes
*
* \param X X component of position
* \param Y Y component of position
* \param Z Z component of position
* \param Width Width of the box (following X)
* \param Height Height of the box (following Y)
* \param Depth Depth of the box (following Z)
*/
template<typename T>
OrientedBox<T>::OrientedBox(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
/*!
* \brief Constructs a OrientedBox object from a box
*
@ -45,23 +28,9 @@ namespace Nz
*/
template<typename T>
OrientedBox<T>::OrientedBox(const Box<T>& box)
OrientedBox<T>::OrientedBox(const Box<T>& box) :
localBox(box)
{
Set(box);
}
/*!
* \brief Constructs a OrientedBox object from two vectors representing point of the space
* (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum
*
* \param vec1 First point
* \param vec2 Second point
*/
template<typename T>
OrientedBox<T>::OrientedBox(const Vector3<T>& vec1, const Vector3<T>& vec2)
{
Set(vec1, vec2);
}
/*!
@ -72,9 +41,11 @@ namespace Nz
template<typename T>
template<typename U>
OrientedBox<T>::OrientedBox(const OrientedBox<U>& orientedBox)
OrientedBox<T>::OrientedBox(const OrientedBox<U>& orientedBox) :
localBox(orientedBox.localBox)
{
Set(orientedBox);
for (unsigned int i = 0; i < BoxCornerCount; ++i)
m_corners[i] = Vector3<T>(orientedBox(i));
}
/*!
@ -119,91 +90,6 @@ namespace Nz
return localBox.IsValid();
}
/*!
* \brief Makes the oriented box position (0, 0, 0) and lengths (0, 0, 0)
* \return A reference to this oriented box with position (0, 0, 0) and lengths (0, 0, 0)
*
* \see Zero
*/
template<typename T>
OrientedBox<T>& OrientedBox<T>::MakeZero()
{
localBox.MakeZero();
return *this;
}
/*!
* \brief Sets the components of the oriented box
* \return A reference to this oriented box
*
* \param X X position
* \param Y Y position
* \param Z Z position
* \param Width Width of the oriented box (following X)
* \param Height Height of the oriented box (following Y)
* \param Depth Depth of the oriented box (following Z)
*/
template<typename T>
OrientedBox<T>& OrientedBox<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
localBox.Set(X, Y, Z, Width, Height, Depth);
return *this;
}
/*!
* \brief Sets the components of the oriented box from a box
* \return A reference to this oriented box
*
* \param box Box<T> object
*/
template<typename T>
OrientedBox<T>& OrientedBox<T>::Set(const Box<T>& box)
{
localBox = box;
return *this;
}
/*!
* \brief Sets a OrientedBox object from two vectors representing point of the space
* (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum
*
* \param vec1 First point
* \param vec2 Second point
*/
template<typename T>
OrientedBox<T>& OrientedBox<T>::Set(const Vector3<T>& vec1, const Vector3<T>& vec2)
{
localBox.Set(vec1, vec2);
return *this;
}
/*!
* \brief Sets the components of the orientedBox from another type of OrientedBox
* \return A reference to this orientedBox
*
* \param orientedBox OrientedBox of type U to convert its components
*/
template<typename T>
template<typename U>
OrientedBox<T>& OrientedBox<T>::Set(const OrientedBox<U>& orientedBox)
{
for (unsigned int i = 0; i < BoxCornerCount; ++i)
m_corners[i].Set(orientedBox(i));
localBox.Set(orientedBox.localBox);
return *this;
}
/*!
* \brief Gives a string representation
* \return A string representation of the object: "OrientedBox(...)"
@ -278,7 +164,7 @@ namespace Nz
*/
template<typename T>
Vector3<T> OrientedBox<T>::operator()(unsigned int i) const
const Vector3<T>& OrientedBox<T>::operator()(unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= BoxCornerCount)
@ -294,37 +180,6 @@ namespace Nz
return m_corners[i];
}
/*!
* \brief Multiplies the lengths with the scalar
* \return A OrientedBox where the position is the same and width, height and depth are the product of the old width, height and depth and the scalar
*
* \param scalar The scalar to multiply width, height and depth with
*/
template<typename T>
OrientedBox<T> OrientedBox<T>::operator*(T scalar) const
{
OrientedBox box(*this);
box *= scalar;
return box;
}
/*!
* \brief Multiplies the lengths of this oriented box with the scalar
* \return A reference to this oriented box where lengths are the product of these lengths and the scalar
*
* \param scalar The scalar to multiply width, height and depth with
*/
template<typename T>
OrientedBox<T>& OrientedBox<T>::operator*=(T scalar)
{
localBox *= scalar;
return *this;
}
/*!
* \brief Compares the oriented box to other one
* \return true if the two oriented boxes are the same
@ -368,10 +223,7 @@ namespace Nz
template<typename T>
OrientedBox<T> OrientedBox<T>::Lerp(const OrientedBox& from, const OrientedBox& to, T interpolation)
{
OrientedBox orientedBox;
orientedBox.Set(Box<T>::Lerp(from.localBox, to.localBox, interpolation));
return orientedBox;
return OrientedBox{ Box<T>::Lerp(from.localBox, to.localBox, interpolation) };
}
/*!
@ -384,10 +236,7 @@ namespace Nz
template<typename T>
OrientedBox<T> OrientedBox<T>::Zero()
{
OrientedBox orientedBox;
orientedBox.MakeZero();
return orientedBox;
return OrientedBox{ Box<T>::Zero() };
}
/*!

View File

@ -22,9 +22,11 @@ namespace Nz
Rect() = default;
Rect(T Width, T Height);
Rect(T X, T Y, T Width, T Height);
explicit Rect(const Vector2<T>& vec1, const Vector2<T>& vec2);
explicit Rect(const Vector2<T>& lengths);
explicit Rect(const Vector2<T>& pos, const Vector2<T>& lengths);
template<typename U> explicit Rect(const Rect<U>& rect);
Rect(const Rect& rect) = default;
Rect(const Rect&) = default;
Rect(Rect&&) noexcept = default;
~Rect() = default;
bool Contains(T X, T Y) const;
@ -62,7 +64,7 @@ namespace Nz
const T& operator[](std::size_t i) const;
Rect& operator=(const Rect&) = default;
Rect& operator=(Rect&&) = default;
Rect& operator=(Rect&&) noexcept = default;
bool operator==(const Rect& rect) const;
bool operator!=(const Rect& rect) const;

View File

@ -55,6 +55,18 @@ namespace Nz
{
}
/*!
* \brief Constructs a Rect object from a vector representing its length
* The position will be set to zero
*
* \param lengths (Width, Height) of the rect
*/
template<typename T>
Rect<T>::Rect(const Vector2<T>& lengths) :
Rect(Vector2<T>::Zero(), lengths)
{
}
/*!
* \brief Constructs a Rect object from two vector representing position and lengths
*

View File

@ -119,7 +119,7 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
Nz::OrientedBoxf zeroOBB = Nz::OrientedBoxf::Zero();
Nz::OrientedBoxf copy(zeroOBB);
REQUIRE(Serialize(context, zeroOBB));
zeroOBB = Nz::OrientedBoxf(1, 1, 1, 1, 1, 1); // Random values
zeroOBB = Nz::OrientedBoxf(Nz::Boxf(1, 1, 1, 1, 1, 1)); // Random values
REQUIRE(zeroOBB != copy);
context.stream->SetCursorPos(0);
REQUIRE(Unserialize(context, &zeroOBB));

View File

@ -26,26 +26,6 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
}
}
WHEN("If we multiply them")
{
THEN("They should still be different")
{
nullVolume *= 5.f;
infiniteVolume = infiniteVolume * 0.5f;
REQUIRE(nullVolume != infiniteVolume);
AND_WHEN("We ask for the characteristic (infinite and null)")
{
THEN("They should still be respectively null and infinite")
{
CHECK(nullVolume.IsNull());
CHECK(infiniteVolume.IsInfinite());
}
}
}
}
WHEN("We compare two null or two infinite")
{
THEN("Everything should be ok")
@ -58,8 +38,8 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
GIVEN("Two same bounding volume with different constructor")
{
Nz::BoundingVolumef firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef secondCenterAndUnit(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
Nz::BoundingVolumef firstCenterAndUnit(Nz::Boxf(0.f, 0.f, 0.f, 1.f, 1.f, 1.f));
Nz::BoundingVolumef secondCenterAndUnit{ Nz::Boxf(Nz::Vector3f::Unit()) };
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
@ -105,11 +85,11 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
{
THEN("Compilation should be fine")
{
Nz::BoundingVolumef nullBoundingVolume = Nz::BoundingVolumef(Nz::Vector3f::Zero(), Nz::Vector3f::Zero());
Nz::BoundingVolumef nullBoundingVolume = Nz::BoundingVolumef(Nz::Boxf::Zero());
Nz::BoundingVolumef centerAndUnit = firstCenterAndUnit;
nullBoundingVolume.Update(Nz::Matrix4f::Identity());
centerAndUnit.Update(Nz::Matrix4f::Identity());
Nz::BoundingVolumef result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::BoundingVolumef result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::BoundingVolumef::Lerp(nullBoundingVolume, centerAndUnit, 0.5f) == result);
@ -118,7 +98,7 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
WHEN("We lerp with special cases")
{
Nz::OrientedBoxf centerAndUnitOBB(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf centerAndUnitOBB(Nz::Boxf(0.f, 0.f, 0.f, 1.f, 1.f, 1.f));
centerAndUnitOBB.Update(Nz::Matrix4f::Identity());
Nz::BoundingVolumef centerAndUnit(centerAndUnitOBB);
@ -128,7 +108,7 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
THEN("Normal to null should give a smaller volume")
{
Nz::BoundingVolumef result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::BoundingVolumef result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::BoundingVolumef::Lerp(centerAndUnit, nullBoundingVolume, 0.5f) == result);
@ -141,7 +121,7 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
THEN("Null to normal should give a small volume")
{
Nz::BoundingVolumef result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::BoundingVolumef result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::BoundingVolumef::Lerp(nullBoundingVolume, centerAndUnit, 0.5f) == result);

View File

@ -9,10 +9,10 @@ SCENARIO("Box", "[MATH][BOX]")
Nz::Boxf firstZero(Nz::Boxf::Zero());
Nz::Boxf secondZero(Nz::Vector3f::Zero(), Nz::Vector3f::Zero());
WHEN("We multiply them")
WHEN("We scale them")
{
firstZero = firstZero * 1.f;
secondZero = secondZero * Nz::Vector3f::Unit() * 3.f;
firstZero.Scale(1.f);
secondZero.Scale(Nz::Vector3f::Unit() * 3.f);
THEN("They should stay the same")
{
@ -91,8 +91,8 @@ SCENARIO("Box", "[MATH][BOX]")
GIVEN("Two wrong box (negative width, height and depth")
{
Nz::Boxf firstWrongBox(-Nz::Vector3f::Unit());
Nz::Boxf secondWrongBox(-Nz::Vector3f::Unit());
Nz::Boxf firstWrongBox = Nz::Boxf::Invalid();
Nz::Boxf secondWrongBox = Nz::Boxf::Invalid();
WHEN("We check if valid")
{

View File

@ -12,11 +12,11 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
Nz::BoundingVolumef bv(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit()));
bv.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(bv));
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f)));
Nz::OrientedBoxf obb(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f);
Nz::OrientedBoxf obb(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f));
obb.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(obb));
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
@ -31,12 +31,12 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef bv(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f));
bv.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(bv));
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(Nz::Boxf(Nz::Vector3f::UnitX() * 500.f, Nz::Vector3f::Unit())));
Nz::OrientedBoxf obb(Nz::Vector3f::UnitX() * 100.f, Nz::Vector3f::Unit());
Nz::OrientedBoxf obb(Nz::Boxf(Nz::Vector3f::UnitX() * 100.f, Nz::Vector3f::Unit()));
obb.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(obb));
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(Nz::Spheref(Nz::Vector3f::UnitX() * 100.f, 0.5f)));
@ -49,11 +49,11 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
Nz::BoundingVolumef bv(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f));
bv.Update(Nz::Matrix4f::Identity());
CHECK(!frustum.Contains(bv));
CHECK(!frustum.Contains(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f)));
Nz::OrientedBoxf obb(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
Nz::OrientedBoxf obb(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f));
obb.Update(Nz::Matrix4f::Identity());
CHECK(!frustum.Contains(obb));
CHECK(!frustum.Contains(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
@ -66,11 +66,11 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef bv(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f));
bv.Update(Nz::Matrix4f::Identity());
CHECK(frustum.Contains(bv));
CHECK(frustum.Contains(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
Nz::OrientedBoxf obb(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf obb(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f));
obb.Update(Nz::Matrix4f::Identity());
CHECK(frustum.Contains(obb));
CHECK(frustum.Contains(Nz::Spheref(Nz::Vector3f::UnitX() * 500.f, 1.f)));

View File

@ -6,8 +6,8 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
{
GIVEN("Two center and unit oriented boxes")
{
Nz::OrientedBoxf firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf secondCenterAndUnit(Nz::OrientedBox<int>(Nz::Vector3i::Zero(), Nz::Vector3i::Unit()));
Nz::OrientedBoxf firstCenterAndUnit(Nz::Boxf(0.f, 0.f, 0.f, 1.f, 1.f, 1.f));
Nz::OrientedBoxf secondCenterAndUnit(Nz::OrientedBox<int>(Nz::Boxi(Nz::Vector3i::Zero(), Nz::Vector3i::Unit())));
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
@ -33,7 +33,7 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
{
THEN("Results are different between operator * and update(ScaleMatrix) but corners are the same")
{
firstCenterAndUnit *= 2.f;
firstCenterAndUnit.localBox.Scale(2.f);
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Scale(Nz::Vector3f::Unit() * 2.f));
@ -53,7 +53,7 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
Nz::OrientedBoxf centerAndUnit = firstCenterAndUnit;
nullOrientedBox.Update(Nz::Matrix4f::Identity());
centerAndUnit.Update(Nz::Matrix4f::Identity());
Nz::OrientedBoxf result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::OrientedBoxf result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::OrientedBoxf::Lerp(nullOrientedBox, centerAndUnit, 0.5f) == result);

View File

@ -70,14 +70,14 @@ SCENARIO("Ray", "[MATH][RAY]")
float tmpClosest;
float tmpFurthest;
Nz::OrientedBoxf obb(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf obb(Nz::Boxf(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f));
obb.Update(Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f).ToQuaternion()));
CHECK(ray.Intersect(obb, &tmpClosest, &tmpFurthest));
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY());
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 2.f));
obb = Nz::OrientedBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f);
obb = Nz::OrientedBoxf(Nz::Boxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f));
obb.Update(Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 0.f, 90.f).ToQuaternion()));
CHECK(!ray.Intersect(obb, &tmpClosest, &tmpFurthest));
}

View File

@ -36,7 +36,7 @@ SCENARIO("Rect", "[MATH][RECT]")
{
THEN("It's not valid")
{
CHECK(!(firstCenterAndUnit * 0.f).IsValid());
CHECK(!(firstCenterAndUnit.Scale(0.f)).IsValid());
}
}