Move ComputeTest,GraphicsTest,RenderTest and Std140Debug to the tests folder

Also renamed NazaraUnitTests to UnitTests
This commit is contained in:
SirLynix
2022-12-26 08:44:11 +01:00
parent fe8715f1fb
commit 4b804dc613
71 changed files with 33 additions and 36 deletions

View File

@@ -0,0 +1,134 @@
#include <Nazara/Physics2D/Collider2D.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Collider2D", "[PHYSICS2D][COLLIDER2D]")
{
GIVEN("No particular elements")
{
WHEN("We construct a box with Rect")
{
Nz::Rectf aabb(5.f, 3.f, 10.f, 6.f);
Nz::BoxCollider2D box(aabb);
THEN("We expect those to be true")
{
CHECK(box.GetRect() == aabb);
CHECK(box.GetSize() == aabb.GetLengths());
CHECK(box.GetType() == Nz::ColliderType2D::Box);
}
}
WHEN("We construct a box with Vector2D")
{
Nz::Vector2f vec(5.f, 3.f);
Nz::Rectf aabb(-2.5f, -1.5f, 5.f, 3.f);
Nz::BoxCollider2D box(vec);
THEN("We expect those to be true")
{
CHECK(box.GetRect() == aabb);
CHECK(box.GetSize() == vec);
CHECK(box.GetType() == Nz::ColliderType2D::Box);
}
}
WHEN("We construct a circle")
{
Nz::Vector2f position(5.f, 3.f);
float radius = 7.f;
Nz::CircleCollider2D circle(radius, position);
THEN("We expect those to be true")
{
CHECK(circle.GetRadius() == Catch::Approx(radius));
CHECK(circle.GetType() == Nz::ColliderType2D::Circle);
}
}
WHEN("We construct a compound")
{
Nz::Rectf aabb(0.f, 0.f, 1.f, 1.f);
std::shared_ptr<Nz::BoxCollider2D> box1 = std::make_shared<Nz::BoxCollider2D>(aabb);
aabb.Translate(Nz::Vector2f::Unit());
std::shared_ptr<Nz::BoxCollider2D> box2 = std::make_shared<Nz::BoxCollider2D>(aabb);
std::vector<std::shared_ptr<Nz::Collider2D>> colliders;
colliders.push_back(box1);
colliders.push_back(box2);
Nz::CompoundCollider2D compound(colliders);
THEN("We expect those to be true")
{
CHECK(compound.GetType() == Nz::ColliderType2D::Compound);
}
}
WHEN("We construct a convex")
{
std::vector<Nz::Vector2f> vertices;
vertices.push_back(Nz::Vector2f(0.f, 0.f));
vertices.push_back(Nz::Vector2f(0.f, 1.f));
vertices.push_back(Nz::Vector2f(1.f, 1.f));
vertices.push_back(Nz::Vector2f(1.f, 0.f));
Nz::ConvexCollider2D convex(Nz::SparsePtr<const Nz::Vector2f>(vertices.data()), vertices.size());
THEN("We expect those to be true")
{
CHECK(convex.GetType() == Nz::ColliderType2D::Convex);
}
}
WHEN("We construct a null")
{
Nz::NullCollider2D null;
THEN("We expect those to be true")
{
CHECK(null.GetType() == Nz::ColliderType2D::Null);
}
}
WHEN("We construct a segment")
{
Nz::Vector2f firstPoint(2.f, 1.f);
Nz::Vector2f secondPoint(-4.f, -3.f);
Nz::SegmentCollider2D segment(firstPoint, secondPoint);
THEN("We expect those to be true")
{
CHECK(segment.GetFirstPoint() == firstPoint);
CHECK(segment.GetLength() == Catch::Approx(firstPoint.Distance(secondPoint)));
CHECK(segment.GetSecondPoint() == secondPoint);
CHECK(segment.GetType() == Nz::ColliderType2D::Segment);
}
}
WHEN("We verify general purpose methods")
{
Nz::Rectf aabb(5.f, 3.f, 10.f, 6.f);
Nz::BoxCollider2D box(aabb);
Nz::UInt32 categoryMask = 1;
Nz::UInt32 groupId = 2;
Nz::UInt32 typeId = 3;
Nz::UInt32 mask = 4;
bool trigger = true;
box.SetCategoryMask(categoryMask);
box.SetCollisionGroup(groupId);
box.SetCollisionId(typeId);
box.SetCollisionMask(mask);
box.SetTrigger(trigger);
THEN("We expect those to be true")
{
CHECK(box.GetCategoryMask() == categoryMask);
CHECK(box.GetCollisionGroup() == groupId);
CHECK(box.GetCollisionId() == typeId);
CHECK(box.GetCollisionMask() == mask);
CHECK(box.IsTrigger() == trigger);
}
}
}
}

View File

@@ -0,0 +1,204 @@
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world, const Nz::Vector2f& position, bool isMoving = true, const Nz::Vector2f& lengths = Nz::Vector2f::Unit());
Nz::UInt32 collisionGroup = 1;
Nz::UInt32 categoryMask = 2;
Nz::UInt32 collisionMask = 3;
SCENARIO("PhysWorld2D", "[PHYSICS2D][PHYSWORLD2D]")
{
GIVEN("A physic world and a bunch of entities on a grid")
{
Nz::PhysWorld2D world;
std::vector<Nz::RigidBody2D> bodies;
const int numberOfBodiesPerLign = 3;
for (int i = 0; i != numberOfBodiesPerLign; ++i)
{
for (int j = 0; j != numberOfBodiesPerLign; ++j)
{
bodies.push_back(CreateBody(world, Nz::Vector2f(10.f * i, 10.f * j)));
}
}
world.Step(1.f);
WHEN("We ask for the nearest body")
{
Nz::PhysWorld2D::NearestQueryResult result;
REQUIRE(world.NearestBodyQuery(-Nz::Vector2f::UnitY() * 1.f, 2.f, collisionGroup, categoryMask, collisionMask, &result));
THEN("It should be the one on the origin")
{
CHECK(result.nearestBody == &bodies[0]);
CHECK(result.closestPoint == Nz::Vector2f::Zero());
CHECK(result.fraction == -Nz::Vector2f::UnitY());
CHECK(result.distance == Catch::Approx(1.f));
}
REQUIRE(world.NearestBodyQuery(Nz::Vector2f::UnitY() * 2.f, 2.f, collisionGroup, categoryMask, collisionMask, &result));
THEN("It should be the one on the origin")
{
CHECK(result.nearestBody == &bodies[0]);
CHECK(result.closestPoint == Nz::Vector2f::UnitY());
CHECK(result.fraction == Nz::Vector2f::UnitY());
CHECK(result.distance == Catch::Approx(1.f));
}
}
WHEN("We ask for the first ray collision")
{
Nz::Vector2f origin = -Nz::Vector2f::UnitY() * 2.f;
Nz::Vector2f end = (numberOfBodiesPerLign + 1) * 10.f * Nz::Vector2f::UnitY();
Nz::PhysWorld2D::RaycastHit result;
REQUIRE(world.RaycastQueryFirst(origin, end, 1.f, collisionGroup, categoryMask, collisionMask, &result));
THEN("It should be the one on the origin")
{
CHECK(result.nearestBody == &bodies[0]);
CHECK(result.fraction == Catch::Approx(1.f / 42.f));
CHECK(result.hitPos == Nz::Vector2f::Zero());
CHECK(result.hitNormal == -Nz::Vector2f::UnitY());
}
}
WHEN("We ask for the ray collisions")
{
Nz::Vector2f origin = -Nz::Vector2f::UnitY() * 2.f;
Nz::Vector2f end = (numberOfBodiesPerLign + 1) * 10.f * Nz::Vector2f::UnitY();
std::vector<Nz::PhysWorld2D::RaycastHit> results;
REQUIRE(world.RaycastQuery(origin, end, 1.f, collisionGroup, categoryMask, collisionMask, &results));
THEN("It should be the first lign")
{
REQUIRE(results.size() == numberOfBodiesPerLign);
for (int i = 0; i != numberOfBodiesPerLign; ++i)
{
const Nz::PhysWorld2D::RaycastHit& result = results[i];
CHECK(result.nearestBody == &bodies[i]);
CHECK(result.fraction == Catch::Approx(i / 4.f).margin(0.1f));
CHECK(result.hitPos == Nz::Vector2f(0.f, i * 10.f));
CHECK(result.hitNormal == -Nz::Vector2f::UnitY());
}
}
}
WHEN("We ask for a region")
{
std::vector<Nz::RigidBody2D*> results;
world.RegionQuery(Nz::Rectf(-5.f, -5.f, 5.f, 5.f), collisionGroup, categoryMask, collisionMask, &results);
THEN("It should be the one on the origin")
{
REQUIRE(results.size() == 1);
CHECK(results[0] == &bodies[0]);
}
}
}
GIVEN("Three entities, a character, a wall and a trigger zone")
{
unsigned int CHARACTER_COLLISION_ID = 1;
unsigned int WALL_COLLISION_ID = 2;
unsigned int TRIGGER_COLLISION_ID = 3;
int statusTriggerCollision = 0;
Nz::PhysWorld2D world;
Nz::Rectf characterAABB(0.f, 0.f, 1.f, 1.f);
std::shared_ptr<Nz::Collider2D> characterBox = std::make_shared<Nz::BoxCollider2D>(characterAABB);
characterBox->SetCollisionId(CHARACTER_COLLISION_ID);
Nz::RigidBody2D character(&world, 1.f, characterBox);
character.SetPosition(Nz::Vector2f::Zero());
Nz::Rectf wallAABB(0.f, 0.f, 1.f, 2.f);
std::shared_ptr<Nz::Collider2D> wallBox = std::make_shared<Nz::BoxCollider2D>(wallAABB);
wallBox->SetCollisionId(WALL_COLLISION_ID);
Nz::RigidBody2D wall(&world, 0.f, wallBox);
wall.SetPosition(Nz::Vector2f(5.f, 0.f));
Nz::Rectf triggerAABB(0.f, 0.f, 1.f, 1.f);
std::shared_ptr<Nz::Collider2D> triggerBox = std::make_shared<Nz::BoxCollider2D>(triggerAABB);
triggerBox->SetTrigger(true);
triggerBox->SetCollisionId(TRIGGER_COLLISION_ID);
Nz::RigidBody2D trigger(&world, 0.f, triggerBox);
trigger.SetPosition(Nz::Vector2f(2.f, 0.f));
world.Step(0.f);
Nz::PhysWorld2D::Callback characterTriggerCallback;
characterTriggerCallback.startCallback = [&](Nz::PhysWorld2D&, Nz::Arbiter2D&, Nz::RigidBody2D&, Nz::RigidBody2D&, void*) -> bool {
statusTriggerCollision = statusTriggerCollision | 1 << 0;
return true;
};
characterTriggerCallback.preSolveCallback = [&](Nz::PhysWorld2D&, Nz::Arbiter2D&, Nz::RigidBody2D&, Nz::RigidBody2D&, void*) -> bool {
statusTriggerCollision = statusTriggerCollision | 1 << 1;
return true;
};
characterTriggerCallback.postSolveCallback = [&](Nz::PhysWorld2D&, Nz::Arbiter2D&, Nz::RigidBody2D&, Nz::RigidBody2D&, void*) {
statusTriggerCollision = statusTriggerCollision | 1 << 2;
};
characterTriggerCallback.endCallback = [&](Nz::PhysWorld2D&, Nz::Arbiter2D&, Nz::RigidBody2D&, Nz::RigidBody2D&, void*) {
statusTriggerCollision = statusTriggerCollision | 1 << 3;
};
world.RegisterCallbacks(CHARACTER_COLLISION_ID, TRIGGER_COLLISION_ID, characterTriggerCallback);
int statusWallCollision = 0;
Nz::PhysWorld2D::Callback characterWallCallback;
characterWallCallback.startCallback = [&](Nz::PhysWorld2D&, Nz::Arbiter2D&, Nz::RigidBody2D&, Nz::RigidBody2D&, void*) -> bool {
statusWallCollision = statusWallCollision | 1 << 0;
return true;
};
characterWallCallback.endCallback = [&](Nz::PhysWorld2D&, Nz::Arbiter2D&, Nz::RigidBody2D&, Nz::RigidBody2D&, void*) {
statusWallCollision = statusWallCollision | 1 << 1;
};
world.RegisterCallbacks(CHARACTER_COLLISION_ID, WALL_COLLISION_ID, characterWallCallback);
WHEN("We make our character go towards the wall")
{
character.SetVelocity(Nz::Vector2f(1.f, 0.f));
for (int i = 0; i != 11; ++i)
world.Step(0.1f);
THEN("It should trigger several collisions")
{
CHECK(statusTriggerCollision == 3);
for (int i = 0; i != 20; ++i)
world.Step(0.1f);
CHECK(statusTriggerCollision == 11);
CHECK(character.GetPosition().x == Catch::Approx(3.1f).margin(0.01f));
for (int i = 0; i != 9; ++i)
world.Step(0.1f);
CHECK(character.GetPosition().x == Catch::Approx(4.f).margin(0.01f));
world.Step(0.1f);
CHECK(character.GetPosition().x == Catch::Approx(4.f).margin(0.01f));
CHECK(statusWallCollision == 1); // It should be close to the wall
character.SetVelocity(Nz::Vector2f(-2.f, 0.f));
for (int i = 0; i != 10; ++i)
world.Step(0.1f);
CHECK(statusWallCollision == 3);
}
}
}
}
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world, const Nz::Vector2f& position, bool isMoving, const Nz::Vector2f& lengths)
{
Nz::Rectf aabb(0.f, 0.f, lengths.x, lengths.y);
std::shared_ptr<Nz::Collider2D> box = std::make_shared<Nz::BoxCollider2D>(aabb);
box->SetCategoryMask(categoryMask);
box->SetCollisionMask(collisionMask);
float mass = isMoving ? 1.f : 0.f;
Nz::RigidBody2D rigidBody(&world, mass, box);
rigidBody.SetPosition(position);
return rigidBody;
}

View File

@@ -0,0 +1,353 @@
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include <limits>
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world);
void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right);
void EQUALITY(const Nz::Rectf& left, const Nz::Rectf& right);
SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
{
GIVEN("A physic world and a rigid body")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
Nz::Vector2f positionAABB(3.f, 4.f);
Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f);
std::shared_ptr<Nz::Collider2D> box = std::make_shared<Nz::BoxCollider2D>(aabb);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, box);
float angularVelocity = 0.2f;
body.SetAngularVelocity(angularVelocity);
Nz::Vector2f massCenter(5.f, 7.f);
body.SetMassCenter(massCenter);
Nz::Vector2f position(9.f, 1.f);
body.SetPosition(position);
float rotation = 0.1f;
body.SetRotation(rotation);
Nz::Vector2f velocity(-4.f, -2.f);
body.SetVelocity(velocity);
bool userdata = false;
body.SetUserdata(&userdata);
world.Step(1.f);
WHEN("We copy construct the body")
{
body.AddForce(Nz::Vector2f(3.f, 5.f));
Nz::RigidBody2D copiedBody(body);
EQUALITY(copiedBody, body);
world.Step(1.f);
EQUALITY(copiedBody, body);
}
WHEN("We move construct the body")
{
Nz::RigidBody2D copiedBody(body);
Nz::RigidBody2D movedBody(std::move(body));
EQUALITY(movedBody, copiedBody);
}
WHEN("We copy assign the body")
{
Nz::RigidBody2D copiedBody(&world, 0.f);
copiedBody = body;
EQUALITY(copiedBody, body);
}
WHEN("We move assign the body")
{
Nz::RigidBody2D copiedBody(body);
Nz::RigidBody2D movedBody(&world, 0.f);
movedBody = std::move(body);
EQUALITY(movedBody, copiedBody);
}
WHEN("We set a new geometry")
{
float radius = 5.f;
body.SetGeom(std::make_shared<Nz::CircleCollider2D>(radius));
world.Step(1.f);
THEN("The aabb should be updated")
{
position = body.GetPosition();
Nz::Rectf circleAABB(position.x - radius, position.y - radius, 2.f * radius, 2.f* radius);
EQUALITY(body.GetAABB(), circleAABB);
}
}
}
GIVEN("A physic world")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
Nz::Rectf aabb(3.f, 4.f, 1.f, 2.f);
WHEN("We get a rigid body from a function")
{
std::vector<Nz::RigidBody2D> tmp;
tmp.push_back(CreateBody(world));
tmp.push_back(CreateBody(world));
world.Step(1.f);
THEN("They should be valid")
{
CHECK(tmp[0].GetAABB() == aabb);
CHECK(tmp[1].GetAABB() == aabb);
}
}
}
GIVEN("A physic world and a rigid body")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
Nz::Vector2f positionAABB(3.f, 4.f);
Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f);
std::shared_ptr<Nz::Collider2D> box = std::make_shared<Nz::BoxCollider2D>(aabb);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass);
body.SetGeom(box, true, false);
bool userData = false;
body.SetUserdata(&userData);
Nz::Vector2f position = Nz::Vector2f::Zero();
body.SetPosition(position);
world.Step(1.f);
WHEN("We retrieve standard information")
{
THEN("We expect those to be true")
{
CHECK(body.GetAABB() == aabb);
CHECK(body.GetAngularVelocity() == 0.f);
CHECK(body.GetMassCenter(Nz::CoordSys::Global) == position);
CHECK(body.GetGeom() == box);
CHECK(body.GetMass() == Catch::Approx(mass));
CHECK(body.GetPosition() == position);
CHECK(body.GetRotation().value == Catch::Approx(0.f));
CHECK(body.GetUserdata() == &userData);
CHECK(body.GetVelocity() == Nz::Vector2f::Zero());
CHECK(body.IsKinematic() == false);
CHECK(body.IsSleeping() == false);
}
}
WHEN("We set a velocity")
{
Nz::Vector2f velocity(Nz::Vector2f::Unit());
body.SetVelocity(velocity);
position += velocity;
world.Step(1.f);
THEN("We expect those to be true")
{
aabb.Translate(velocity);
CHECK(body.GetAABB() == aabb);
CHECK(body.GetMassCenter(Nz::CoordSys::Global) == position);
CHECK(body.GetPosition() == position);
CHECK(body.GetVelocity() == velocity);
}
AND_THEN("We apply an impulse in the opposite direction")
{
body.AddImpulse(-velocity);
world.Step(1.f);
REQUIRE(body.GetVelocity() == Nz::Vector2f::Zero());
}
}
WHEN("We set an angular velocity")
{
Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(90.f);
body.SetAngularVelocity(angularSpeed);
world.Step(1.f);
THEN("We expect those to be true")
{
CHECK(body.GetAngularVelocity() == angularSpeed);
CHECK(body.GetRotation() == angularSpeed);
CHECK(body.GetAABB() == Nz::Rectf(-6.f, 3.f, 2.f, 1.f));
world.Step(1.f);
CHECK(body.GetRotation() == 2.f * angularSpeed);
CHECK(body.GetAABB() == Nz::Rectf(-4.f, -6.f, 1.f, 2.f));
world.Step(1.f);
CHECK(body.GetRotation() == 3.f * angularSpeed);
CHECK(body.GetAABB() == Nz::Rectf(4.f, -4.f, 2.f, 1.f));
world.Step(1.f);
CHECK(body.GetRotation() == 4.f * angularSpeed);
}
}
WHEN("We apply a torque")
{
body.AddTorque(Nz::DegreeAnglef(90.f));
world.Step(1.f);
THEN("It is also counter-clockwise")
{
CHECK(body.GetAngularVelocity().value >= 0.f);
CHECK(body.GetRotation().value >= 0.f);
}
}
}
GIVEN("A physic world and a rigid body of circle")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
Nz::Vector2f position(3.f, 4.f);
float radius = 5.f;
std::shared_ptr<Nz::Collider2D> circle = std::make_shared<Nz::CircleCollider2D>(radius, position);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass);
body.SetGeom(circle, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the circle")
{
THEN("We expect this to be true")
{
Nz::Rectf circleAABB(position.x - radius, position.y - radius, 2.f * radius, 2.f* radius);
REQUIRE(body.GetAABB() == circleAABB);
}
}
}
GIVEN("A physic world and a rigid body of compound")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
Nz::Rectf aabb(0.f, 0.f, 1.f, 1.f);
std::shared_ptr<Nz::BoxCollider2D> box1 = std::make_shared<Nz::BoxCollider2D>(aabb);
aabb.Translate(Nz::Vector2f::Unit());
std::shared_ptr<Nz::BoxCollider2D> box2 = std::make_shared<Nz::BoxCollider2D>(aabb);
std::vector<std::shared_ptr<Nz::Collider2D>> colliders;
colliders.push_back(box1);
colliders.push_back(box2);
std::shared_ptr<Nz::CompoundCollider2D> compound = std::make_shared<Nz::CompoundCollider2D>(colliders);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass);
body.SetGeom(compound, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the compound")
{
THEN("We expect this to be true")
{
Nz::Rectf compoundAABB(0.f, 0.f, 2.f, 2.f);
REQUIRE(body.GetAABB() == compoundAABB);
}
}
}
GIVEN("A physic world and a rigid body of circle")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
std::vector<Nz::Vector2f> vertices;
vertices.emplace_back(0.f, 0.f);
vertices.emplace_back(0.f, 1.f);
vertices.emplace_back(1.f, 1.f);
vertices.emplace_back(1.f, 0.f);
Nz::SparsePtr<const Nz::Vector2f> sparsePtr(vertices.data());
std::shared_ptr<Nz::ConvexCollider2D> convex = std::make_shared<Nz::ConvexCollider2D>(sparsePtr, vertices.size());
float mass = 1.f;
Nz::RigidBody2D body(&world, mass);
body.SetGeom(convex, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the convex")
{
THEN("We expect this to be true")
{
Nz::Rectf convexAABB(0.f, 0.f, 1.f, 1.f);
REQUIRE(body.GetAABB() == convexAABB);
}
}
}
GIVEN("A physic world and a rigid body of segment")
{
Nz::PhysWorld2D world;
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
Nz::Vector2f positionA(3.f, 4.f);
Nz::Vector2f positionB(1.f, -4.f);
std::shared_ptr<Nz::Collider2D> segment = std::make_shared<Nz::SegmentCollider2D>(positionA, positionB, 0.f);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass);
body.SetGeom(segment, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the segment")
{
THEN("We expect this to be true")
{
Nz::Rectf segmentAABB = Nz::Rectf::FromExtends(positionA, positionB);
REQUIRE(body.GetAABB() == segmentAABB);
}
}
}
}
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world)
{
Nz::Vector2f positionAABB(3.f, 4.f);
Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f);
std::shared_ptr<Nz::Collider2D> box = std::make_shared<Nz::BoxCollider2D>(aabb);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, box);
body.SetPosition(Nz::Vector2f::Zero());
return body;
}
void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right)
{
CHECK(left.GetAABB() == right.GetAABB());
CHECK(left.GetAngularVelocity() == right.GetAngularVelocity());
CHECK(left.GetMassCenter() == right.GetMassCenter());
CHECK(left.GetGeom() == right.GetGeom());
CHECK(left.GetHandle() != right.GetHandle());
CHECK(left.GetMass() == Catch::Approx(right.GetMass()));
CHECK(left.GetPosition() == right.GetPosition());
CHECK(left.GetRotation().value == Catch::Approx(right.GetRotation().value));
CHECK(left.GetUserdata() == right.GetUserdata());
CHECK(left.GetVelocity() == right.GetVelocity());
}
void EQUALITY(const Nz::Rectf& left, const Nz::Rectf& right)
{
CHECK(left.x == Catch::Approx(right.x));
CHECK(left.y == Catch::Approx(right.y));
CHECK(left.width == Catch::Approx(right.width));
CHECK(left.height == Catch::Approx(right.height));
}