Replace floating point angle by Angle class instance

This commit is contained in:
Lynix
2018-10-09 23:20:53 +02:00
parent f02f206aff
commit dc6fbfc90f
17 changed files with 87 additions and 90 deletions

View File

@@ -125,12 +125,12 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
THEN("We expect those to be true")
{
CHECK(body.GetAABB() == aabb);
CHECK(body.GetAngularVelocity() == Approx(0.f));
CHECK(body.GetAngularVelocity() == 0.f);
CHECK(body.GetMassCenter() == Nz::Vector2f::Zero());
CHECK(body.GetGeom() == box);
CHECK(body.GetMass() == Approx(mass));
CHECK(body.GetPosition() == position);
CHECK(body.GetRotation() == Approx(0.f));
CHECK(body.GetRotation().angle == Approx(0.f));
CHECK(body.GetUserdata() == &userData);
CHECK(body.GetVelocity() == Nz::Vector2f::Zero());
@@ -166,39 +166,38 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
WHEN("We set an angular velocity")
{
float angularSpeed = Nz::FromDegrees(90.f);
Nz::RadianAnglef angularSpeed = Nz::RadianAnglef(Nz::DegreeToRadian(90.f));
body.SetAngularVelocity(angularSpeed);
world.Step(1.f);
THEN("We expect those to be true")
{
CHECK(body.GetAngularVelocity() == Approx(angularSpeed));
CHECK(body.GetRotation() == Approx(angularSpeed));
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() == Approx(2.f * angularSpeed));
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() == Approx(3.f * angularSpeed));
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() == Approx(4.f * angularSpeed));
CHECK(body.GetRotation() == 4.f * angularSpeed);
}
}
WHEN("We apply a torque")
{
float angularSpeed = Nz::DegreeToRadian(90.f);
body.AddTorque(angularSpeed);
body.AddTorque(Nz::DegreeToRadian(90.f));
world.Step(1.f);
THEN("It is also counter-clockwise")
{
CHECK(body.GetAngularVelocity() >= 0.f);
CHECK(body.GetRotation() >= 0.f);
CHECK(body.GetAngularVelocity().angle >= 0.f);
CHECK(body.GetRotation().angle >= 0.f);
}
}
}
@@ -316,13 +315,13 @@ Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world)
void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right)
{
CHECK(left.GetAABB() == right.GetAABB());
CHECK(left.GetAngularVelocity() == Approx(right.GetAngularVelocity()));
CHECK(left.GetAngularVelocity() == right.GetAngularVelocity());
CHECK(left.GetMassCenter() == right.GetMassCenter());
CHECK(left.GetGeom() == right.GetGeom());
CHECK(left.GetHandle() != right.GetHandle());
CHECK(left.GetMass() == Approx(right.GetMass()));
CHECK(left.GetPosition() == right.GetPosition());
CHECK(left.GetRotation() == Approx(right.GetRotation()));
CHECK(left.GetRotation().angle == Approx(right.GetRotation().angle));
CHECK(left.GetUserdata() == right.GetUserdata());
CHECK(left.GetVelocity() == right.GetVelocity());
}