Fixes unit tests

This commit is contained in:
SirLynix 2022-12-18 17:08:03 +01:00
parent 5ca7b398c2
commit 46fe1c550c
8 changed files with 15 additions and 69 deletions

View File

@ -41,7 +41,6 @@ namespace Nz
bool Intersect(const BoundingVolume<T>& volume, T* closestHit = nullptr, T* furthestHit = nullptr) const;
bool Intersect(const Box<T>& box, T* closestHit = nullptr, T* furthestHit = nullptr) const;
bool Intersect(const Box<T>& box, const Matrix4<T>& transform, T* closestHit = nullptr, T* furthestHit = nullptr) const;
bool Intersect(const OrientedBox<T>& orientedBox, T* closestHit = nullptr, T* furthestHit = nullptr) const;
bool Intersect(const Plane<T>& plane, T* hit = nullptr) const;
bool Intersect(const Sphere<T>& sphere, T* closestHit = nullptr, T* furthestHit = nullptr) const;
bool Intersect(const Vector3<T>& firstPoint, const Vector3<T>& secondPoint, const Vector3<T>& thirdPoint, T* hit = nullptr) const;

View File

@ -308,44 +308,6 @@ namespace Nz
return true;
}
/*!
* \brief Checks whether or not this ray intersects with the OrientedBox
* \return true if it intersects
*
* \param orientedBox OrientedBox to check
* \param closestHit Optional argument to get the closest parameter where the intersection is only if it happened
* \param furthestHit Optional argument to get the furthest parameter where the intersection is only if it happened
*
* \see Intersect
*/
template<typename T>
bool Ray<T>::Intersect(const OrientedBox<T>& orientedBox, T* closestHit, T* furthestHit) const
{
Vector3<T> corner = orientedBox.GetCorner(BoxCorner::FarLeftBottom);
Vector3<T> oppositeCorner = orientedBox.GetCorner(BoxCorner::NearRightTop);
Vector3<T> width = (orientedBox.GetCorner(BoxCorner::NearLeftBottom) - corner);
Vector3<T> height = (orientedBox.GetCorner(BoxCorner::FarLeftTop) - corner);
Vector3<T> depth = (orientedBox.GetCorner(BoxCorner::FarRightBottom) - corner);
// Construction de la matrice de transformation de l'OBB
Matrix4<T> matrix(width.x, height.x, depth.x, corner.x,
width.y, height.y, depth.y, corner.y,
width.z, height.z, depth.z, corner.z,
T(0.0), T(0.0), T(0.0), T(1.0));
matrix.InverseTransform();
corner = matrix.Transform(corner);
oppositeCorner = matrix.Transform(oppositeCorner);
Box<T> tmpBox(corner, oppositeCorner);
Ray<T> tmpRay(matrix.Transform(origin), matrix.Transform(direction));
return tmpRay.Intersect(tmpBox, closestHit, furthestHit);
}
/*!
* \brief Checks whether or not this ray intersects with the plane
* \return true if it intersects

View File

@ -175,7 +175,7 @@ namespace Nz
{
std::shared_ptr<Image> newImage = std::make_shared<Image>(ImageType::E2D, PixelFormat::A8, size.x, size.y);
if (oldImage)
newImage->Copy(static_cast<Image&>(*oldImage), Rectui(Vector2ui::Zero(), Vector2ui(oldImage->GetSize())), Vector2ui(0, 0)); // Copie des anciennes données
newImage->Copy(static_cast<Image&>(*oldImage), Boxui(Vector3ui::Zero(), oldImage->GetSize()), Vector2ui(0, 0)); // Copie des anciennes données
return newImage;
}

View File

@ -17,15 +17,17 @@ SCENARIO("Box", "[MATH][BOX]")
THEN("They should stay the same")
{
REQUIRE(firstZero == secondZero);
CHECK(!firstZero.IsValid());
CHECK(!secondZero.IsValid());
CHECK(firstZero.IsValid());
CHECK(firstZero.IsNull());
CHECK(secondZero.IsValid());
CHECK(secondZero.IsNull());
}
}
}
GIVEN("Two unit and center boxes")
{
Nz::Boxf firstCenterAndUnit(Nz::Rectf(Nz::Vector2f::Zero(), Nz::Vector2f::Unit()));
Nz::Boxf firstCenterAndUnit(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
Nz::Boxf secondCenterAndUnit(1.f, 1.f, 1.f);
WHEN("We ask for some informations")
@ -91,8 +93,8 @@ SCENARIO("Box", "[MATH][BOX]")
GIVEN("Two wrong box (negative width, height and depth")
{
Nz::Boxf firstWrongBox = Nz::Boxf::Invalid();
Nz::Boxf secondWrongBox = Nz::Boxf::Invalid();
Nz::Boxf firstWrongBox(-Nz::Vector3f::Unit());
Nz::Boxf secondWrongBox(-Nz::Vector3f::Unit());
WHEN("We check if valid")
{
@ -121,8 +123,8 @@ SCENARIO("Box", "[MATH][BOX]")
CHECK(firstWrongBox.Contains(0.f, 0.f, 0.f));
CHECK(secondWrongBox.Contains(0.f, 0.f, 0.f));
secondWrongBox = secondWrongBox.Lerp(Nz::Boxf::Zero(), secondWrongBox, 0.f); // Zeroed
secondWrongBox.ExtendTo(Nz::Boxf(Nz::Vector3f(0.1f, 0.1f, 0.1f), Nz::Vector3f(0.9f, 0.9f, 0.9f)));
secondWrongBox = Nz::Boxf::Lerp(Nz::Boxf::Zero(), secondWrongBox, 0.f); // Zeroed
secondWrongBox.ExtendTo(Nz::Boxf::FromExtends(Nz::Vector3f(0.1f, 0.1f, 0.1f), Nz::Vector3f(0.9f, 0.9f, 0.9f)));
secondWrongBox.Translate(Nz::Vector3f(0.05f, 0.05f, 0.05f)); // Box 0.15 to 0.95
CHECK(firstWrongBox.Contains(secondWrongBox));

View File

@ -65,23 +65,6 @@ SCENARIO("Ray", "[MATH][RAY]")
CHECK(!ray.Intersect(Nz::Spheref(Nz::Vector3f::UnitX(), 0.9f)));
}
THEN("For the OBB collision's")
{
float tmpClosest;
float tmpFurthest;
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(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));
}
THEN("For the bounding volume collision's")
{
Nz::BoundingVolumef nullVolume(Nz::Extend::Null);

View File

@ -7,7 +7,7 @@ SCENARIO("Rect", "[MATH][RECT]")
GIVEN("Two same Nz::Rectangles center and unit lengths")
{
Nz::Rectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f);
Nz::Rectf secondCenterAndUnit(Nz::Recti(Nz::Vector2i::Unit(), Nz::Vector2i::Zero()));
Nz::Rectf secondCenterAndUnit(Nz::Recti::FromExtends(Nz::Vector2i::Unit(), Nz::Vector2i::Zero()));
WHEN("We ask if they are the same")
{
@ -32,11 +32,11 @@ SCENARIO("Rect", "[MATH][RECT]")
}
}
WHEN("We make an empty")
WHEN("We make it empty")
{
THEN("It's not valid")
{
CHECK(!(firstCenterAndUnit.Scale(0.f)).IsValid());
CHECK(firstCenterAndUnit.Scale(0.f).IsNull());
}
}

View File

@ -51,7 +51,7 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
WHEN("We get sphere from box unit and center")
{
Nz::Boxf centerUnitBox(Nz::Vector3f::Unit() * -0.5f, Nz::Vector3f::Unit() * 0.5f);
Nz::Boxf centerUnitBox = Nz::Boxf::FromExtends(Nz::Vector3f::Unit() * -0.5f, Nz::Vector3f::Unit() * 0.5f);
THEN("This is equal to sphere center and radius 0.75")
{

View File

@ -310,7 +310,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
{
THEN("We expect this to be true")
{
Nz::Rectf segmentAABB(positionA, positionB);
Nz::Rectf segmentAABB = Nz::Rectf::FromExtends(positionA, positionB);
REQUIRE(body.GetAABB() == segmentAABB);
}
}