From 00ca0248c6e6ebc72ff5f5e1ff9be64bf052fcac Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 Mar 2019 19:05:41 +0100 Subject: [PATCH] Fix unit tests (WIP) --- tests/Engine/Physics2D/RigidBody2D.cpp | 33 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/Engine/Physics2D/RigidBody2D.cpp b/tests/Engine/Physics2D/RigidBody2D.cpp index 7eae99908..e554746d8 100644 --- a/tests/Engine/Physics2D/RigidBody2D.cpp +++ b/tests/Engine/Physics2D/RigidBody2D.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world); @@ -93,6 +94,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") std::vector tmp; tmp.push_back(CreateBody(world)); tmp.push_back(CreateBody(world)); + world.Step(1.f); THEN("They should be valid") @@ -112,11 +114,14 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f); Nz::Collider2DRef box = Nz::BoxCollider2D::New(aabb); float mass = 1.f; - Nz::RigidBody2D body(&world, mass, box); + 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); @@ -126,7 +131,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") { CHECK(body.GetAABB() == aabb); CHECK(body.GetAngularVelocity() == 0.f); - CHECK(body.GetMassCenter() == Nz::Vector2f::Zero()); + CHECK(body.GetMassCenter(Nz::CoordSys_Global) == position); CHECK(body.GetGeom() == box); CHECK(body.GetMass() == Approx(mass)); CHECK(body.GetPosition() == position); @@ -150,7 +155,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") { aabb.Translate(velocity); CHECK(body.GetAABB() == aabb); - CHECK(body.GetMassCenter() == Nz::Vector2f::Zero()); + CHECK(body.GetMassCenter(Nz::CoordSys_Global) == position); CHECK(body.GetPosition() == position); CHECK(body.GetVelocity() == velocity); } @@ -211,7 +216,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") float radius = 5.f; Nz::Collider2DRef circle = Nz::CircleCollider2D::New(radius, position); float mass = 1.f; - Nz::RigidBody2D body(&world, mass, circle); + Nz::RigidBody2D body(&world, mass); + body.SetGeom(circle, true, false); + world.Step(1.f); WHEN("We ask for the aabb of the circle") @@ -240,7 +247,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") Nz::CompoundCollider2DRef compound = Nz::CompoundCollider2D::New(colliders); float mass = 1.f; - Nz::RigidBody2D body(&world, mass, compound); + Nz::RigidBody2D body(&world, mass); + body.SetGeom(compound, true, false); + world.Step(1.f); WHEN("We ask for the aabb of the compound") @@ -267,7 +276,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") Nz::SparsePtr sparsePtr(vertices.data()); Nz::ConvexCollider2DRef convex = Nz::ConvexCollider2D::New(sparsePtr, vertices.size()); float mass = 1.f; - Nz::RigidBody2D body(&world, mass, convex); + Nz::RigidBody2D body(&world, mass); + body.SetGeom(convex, true, false); + world.Step(1.f); WHEN("We ask for the aabb of the convex") @@ -289,7 +300,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") Nz::Vector2f positionB(1.f, -4.f); Nz::Collider2DRef segment = Nz::SegmentCollider2D::New(positionA, positionB, 0.f); float mass = 1.f; - Nz::RigidBody2D body(&world, mass, segment); + Nz::RigidBody2D body(&world, mass); + body.SetGeom(segment, true, false); + world.Step(1.f); WHEN("We ask for the aabb of the segment") @@ -309,7 +322,11 @@ Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world) Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f); Nz::Collider2DRef box = Nz::BoxCollider2D::New(aabb); float mass = 1.f; - return Nz::RigidBody2D(&world, mass, box); + + Nz::RigidBody2D body(&world, mass, box); + body.SetPosition(Nz::Vector2f::Zero()); + + return body; } void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right)