From dc6fbfc90f3eca2c89cf3f811091bd93c0d6cbce Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 9 Oct 2018 23:20:53 +0200 Subject: [PATCH] Replace floating point angle by Angle class instance --- .../NDK/Components/PhysicsComponent2D.hpp | 8 ++--- .../NDK/Components/PhysicsComponent2D.inl | 21 ++++-------- SDK/include/NDK/Systems/PhysicsSystem2D.hpp | 2 +- .../NDK/Components/CollisionComponent2D.cpp | 1 - SDK/src/NDK/Systems/PhysicsSystem2D.cpp | 2 +- include/Nazara/Graphics/Billboard.hpp | 7 ++-- include/Nazara/Graphics/Billboard.inl | 8 +++-- include/Nazara/Physics2D/Constraint2D.hpp | 21 ++++++------ include/Nazara/Physics2D/PhysWorld2D.hpp | 3 +- include/Nazara/Physics2D/RigidBody2D.hpp | 1 + src/Nazara/Physics2D/Constraint2D.cpp | 32 +++++++++---------- src/Nazara/Physics2D/PhysWorld2D.cpp | 2 +- src/Nazara/Physics2D/RigidBody2D.cpp | 18 ++++++----- tests/Engine/Graphics/Billboard.cpp | 2 +- tests/Engine/Physics2D/RigidBody2D.cpp | 27 ++++++++-------- tests/SDK/NDK/Systems/PhysicsSystem2D.cpp | 10 +++--- tests/SDK/NDK/Systems/RenderSystem.cpp | 12 +++---- 17 files changed, 87 insertions(+), 90 deletions(-) diff --git a/SDK/include/NDK/Components/PhysicsComponent2D.hpp b/SDK/include/NDK/Components/PhysicsComponent2D.hpp index 74b6d630e..79204fbdd 100644 --- a/SDK/include/NDK/Components/PhysicsComponent2D.hpp +++ b/SDK/include/NDK/Components/PhysicsComponent2D.hpp @@ -38,25 +38,25 @@ namespace Ndk inline Nz::Rectf GetAABB() const; inline float GetAngularDamping() const; - inline float GetAngularVelocity() const; + inline Nz::RadianAnglef GetAngularVelocity() const; NAZARA_DEPRECATED("Name error, please use GetMassCenter") inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; inline float GetMass() const; inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; inline float GetMomentOfInertia() const; inline Nz::Vector2f GetPosition() const; - inline float GetRotation() const; + inline Nz::RadianAnglef GetRotation() const; inline Nz::Vector2f GetVelocity() const; inline bool IsSleeping() const; inline void SetAngularDamping(float angularDamping); - inline void SetAngularVelocity(float angularVelocity); + inline void SetAngularVelocity(const Nz::RadianAnglef& angularVelocity); inline void SetMass(float mass); inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys_Local); inline void SetMomentOfInertia(float moment); inline void SetPosition(const Nz::Vector2f& position); - inline void SetRotation(float rotation); + inline void SetRotation(const Nz::RadianAnglef& rotation); inline void SetVelocity(const Nz::Vector2f& velocity); static ComponentIndex componentIndex; diff --git a/SDK/include/NDK/Components/PhysicsComponent2D.inl b/SDK/include/NDK/Components/PhysicsComponent2D.inl index b60ac5047..075bd0ff3 100644 --- a/SDK/include/NDK/Components/PhysicsComponent2D.inl +++ b/SDK/include/NDK/Components/PhysicsComponent2D.inl @@ -151,7 +151,7 @@ namespace Ndk * \remark Produces a NazaraAssert if the physics object is invalid */ - inline float PhysicsComponent2D::GetAngularVelocity() const + inline Nz::RadianAnglef PhysicsComponent2D::GetAngularVelocity() const { NazaraAssert(m_object, "Invalid physics object"); @@ -180,7 +180,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline float PhysicsComponent2D::GetMass() const { NazaraAssert(m_object, "Invalid physics object"); @@ -240,8 +239,7 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - - inline float PhysicsComponent2D::GetRotation() const + inline Nz::RadianAnglef PhysicsComponent2D::GetRotation() const { NazaraAssert(m_object, "Invalid physics object"); @@ -300,8 +298,7 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - - inline void PhysicsComponent2D::SetAngularVelocity(float angularVelocity) + inline void PhysicsComponent2D::SetAngularVelocity(const Nz::RadianAnglef& angularVelocity) { NazaraAssert(m_object, "Invalid physics object"); @@ -313,10 +310,8 @@ namespace Ndk * * \param mass Mass of the object * - * \remark Produces a NazaraAssert if the physics object is invalid - * \remark Produces a NazaraAssert if the mass is negative + * \remark Mass must be positive or zero */ - inline void PhysicsComponent2D::SetMass(float mass) { NazaraAssert(m_object, "Invalid physics object"); @@ -332,13 +327,13 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline void PhysicsComponent2D::SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys) { NazaraAssert(m_object, "Invalid physics object"); m_object->SetMassCenter(center, coordSys); } + /*! * \brief Sets the angular damping or moment of inertia of the physics object * @@ -348,7 +343,6 @@ namespace Ndk * * \see SetAngularDamping */ - inline void PhysicsComponent2D::SetMomentOfInertia(float moment) { NazaraAssert(m_object, "Invalid physics object"); @@ -363,7 +357,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline void PhysicsComponent2D::SetPosition(const Nz::Vector2f& position) { NazaraAssert(m_object, "Invalid physics object"); @@ -378,8 +371,7 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - - inline void PhysicsComponent2D::SetRotation(float rotation) + inline void PhysicsComponent2D::SetRotation(const Nz::RadianAnglef& rotation) { NazaraAssert(m_object, "Invalid physics object"); @@ -405,7 +397,6 @@ namespace Ndk * \brief Gets the underlying physics object * \return A reference to the physics object */ - inline Nz::RigidBody2D* PhysicsComponent2D::GetRigidBody() { return m_object.get(); diff --git a/SDK/include/NDK/Systems/PhysicsSystem2D.hpp b/SDK/include/NDK/Systems/PhysicsSystem2D.hpp index 0bbe8d907..a919abbd5 100644 --- a/SDK/include/NDK/Systems/PhysicsSystem2D.hpp +++ b/SDK/include/NDK/Systems/PhysicsSystem2D.hpp @@ -24,7 +24,7 @@ namespace Ndk using ContactPostSolveCallback = std::function; using ContactStartCallback = std::function; - using DebugDrawCircleCallback = std::function; + using DebugDrawCircleCallback = std::function; using DebugDrawDotCallback = std::function; using DebugDrawPolygonCallback = std::function; using DebugDrawSegmentCallback = std::function; diff --git a/SDK/src/NDK/Components/CollisionComponent2D.cpp b/SDK/src/NDK/Components/CollisionComponent2D.cpp index fd78e6c97..5cdfd1589 100644 --- a/SDK/src/NDK/Components/CollisionComponent2D.cpp +++ b/SDK/src/NDK/Components/CollisionComponent2D.cpp @@ -24,7 +24,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the entity has no physics component and has no static body */ - void CollisionComponent2D::SetGeom(Nz::Collider2DRef geom) { m_geom = std::move(geom); diff --git a/SDK/src/NDK/Systems/PhysicsSystem2D.cpp b/SDK/src/NDK/Systems/PhysicsSystem2D.cpp index a5bed6d28..69d6a99b1 100644 --- a/SDK/src/NDK/Systems/PhysicsSystem2D.cpp +++ b/SDK/src/NDK/Systems/PhysicsSystem2D.cpp @@ -181,7 +181,7 @@ namespace Ndk PhysicsComponent2D& phys = entity->GetComponent(); Nz::RigidBody2D* body = phys.GetRigidBody(); - node.SetRotation(Nz::EulerAnglesf(0.f, 0.f, body->GetRotation()), Nz::CoordSys_Global); + node.SetRotation(body->GetRotation(), Nz::CoordSys_Global); node.SetPosition(Nz::Vector3f(body->GetPosition(), node.GetPosition(Nz::CoordSys_Global).z), Nz::CoordSys_Global); } diff --git a/include/Nazara/Graphics/Billboard.hpp b/include/Nazara/Graphics/Billboard.hpp index f875bc23e..1a151ca69 100644 --- a/include/Nazara/Graphics/Billboard.hpp +++ b/include/Nazara/Graphics/Billboard.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace Nz { @@ -34,14 +35,14 @@ namespace Nz std::unique_ptr Clone() const override; inline const Color& GetColor() const; - inline float GetRotation() const; + inline const RadianAnglef& GetRotation() const; inline const Vector2f& GetSize() const; inline void SetColor(const Color& color); inline void SetDefaultMaterial(); inline void SetMaterial(MaterialRef material, bool resizeBillboard = true); inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeBillboard = true); - inline void SetRotation(float rotation); + inline void SetRotation(const RadianAnglef& rotation); inline void SetSize(const Vector2f& size); inline void SetSize(float sizeX, float sizeY); inline void SetTexture(TextureRef texture, bool resizeBillboard = true); @@ -58,7 +59,7 @@ namespace Nz Color m_color; Vector2f m_sinCos; Vector2f m_size; - float m_rotation; + RadianAnglef m_rotation; static BillboardLibrary::LibraryMap s_library; }; diff --git a/include/Nazara/Graphics/Billboard.inl b/include/Nazara/Graphics/Billboard.inl index 6bbf9b143..be1a47918 100644 --- a/include/Nazara/Graphics/Billboard.inl +++ b/include/Nazara/Graphics/Billboard.inl @@ -84,7 +84,7 @@ namespace Nz * \return Current rotation */ - inline float Billboard::GetRotation() const + inline const RadianAnglef& Billboard::GetRotation() const { return m_rotation; } @@ -161,10 +161,12 @@ namespace Nz * \param rotation Rotation for the billboard */ - inline void Billboard::SetRotation(float rotation) + inline void Billboard::SetRotation(const RadianAnglef& rotation) { m_rotation = rotation; - m_sinCos.Set(std::sin(m_rotation), std::cos(m_rotation)); + + auto sincos = rotation.GetSinCos(); + m_sinCos.Set(sincos.first, sincos.second); } /*! diff --git a/include/Nazara/Physics2D/Constraint2D.hpp b/include/Nazara/Physics2D/Constraint2D.hpp index 9b2bf814b..74cded64d 100644 --- a/include/Nazara/Physics2D/Constraint2D.hpp +++ b/include/Nazara/Physics2D/Constraint2D.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -95,15 +96,15 @@ namespace Nz class NAZARA_PHYSICS2D_API DampedRotarySpringConstraint2D : public Constraint2D { public: - DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping); + DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping); ~DampedRotarySpringConstraint2D() = default; float GetDamping() const; - float GetRestAngle() const; + RadianAnglef GetRestAngle() const; float GetStiffness() const; void SetDamping(float newDamping); - void SetRestAngle(float newAngle); + void SetRestAngle(const RadianAnglef& newAngle); void SetStiffness(float newStiffness); template static DampedRotarySpringConstraint2DRef New(Args&&... args); @@ -200,11 +201,11 @@ namespace Nz RatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet); ~RatchetConstraint2D() = default; - float GetAngle() const; + RadianAnglef GetAngle() const; float GetPhase() const; float GetRatchet() const; - void SetAngle(float angle); + void SetAngle(const RadianAnglef& angle); void SetPhase(float phase); void SetRatchet(float ratchet); @@ -219,14 +220,14 @@ namespace Nz class NAZARA_PHYSICS2D_API RotaryLimitConstraint2D : public Constraint2D { public: - RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle); + RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle); ~RotaryLimitConstraint2D() = default; - float GetMaxAngle() const; - float GetMinAngle() const; + RadianAnglef GetMaxAngle() const; + RadianAnglef GetMinAngle() const; - void SetMaxAngle(float maxAngle); - void SetMinAngle(float minAngle); + void SetMaxAngle(const RadianAnglef& maxAngle); + void SetMinAngle(const RadianAnglef& minAngle); template static RotaryLimitConstraint2DRef New(Args&&... args); }; diff --git a/include/Nazara/Physics2D/PhysWorld2D.hpp b/include/Nazara/Physics2D/PhysWorld2D.hpp index 3e726de00..42e9288a1 100644 --- a/include/Nazara/Physics2D/PhysWorld2D.hpp +++ b/include/Nazara/Physics2D/PhysWorld2D.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ namespace Nz using ContactPostSolveCallback = std::function; using ContactStartCallback = std::function; - using DebugDrawCircleCallback = std::function; + using DebugDrawCircleCallback = std::function; using DebugDrawDotCallback = std::function; using DebugDrawPolygonCallback = std::function; using DebugDrawSegmentCallback = std::function; diff --git a/include/Nazara/Physics2D/RigidBody2D.hpp b/include/Nazara/Physics2D/RigidBody2D.hpp index 30eac8f43..ee5ff3cf0 100644 --- a/include/Nazara/Physics2D/RigidBody2D.hpp +++ b/include/Nazara/Physics2D/RigidBody2D.hpp @@ -64,6 +64,7 @@ namespace Nz inline void SetAngularDamping(float angularDamping); void SetAngularVelocity(float angularVelocity); + void SetFriction(std::size_t shapeIndex, float friction); void SetGeom(Collider2DRef geom, bool recomputeMoment = true); void SetMass(float mass, bool recomputeMoment = true); void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys_Local); diff --git a/src/Nazara/Physics2D/Constraint2D.cpp b/src/Nazara/Physics2D/Constraint2D.cpp index a17119545..c4c92fd4c 100644 --- a/src/Nazara/Physics2D/Constraint2D.cpp +++ b/src/Nazara/Physics2D/Constraint2D.cpp @@ -163,8 +163,8 @@ namespace Nz } - DampedRotarySpringConstraint2D::DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) : - Constraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping)) + DampedRotarySpringConstraint2D::DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping) : + Constraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle.angle, stiffness, damping)) { } @@ -173,7 +173,7 @@ namespace Nz return float(cpDampedRotarySpringGetDamping(m_constraint)); } - float DampedRotarySpringConstraint2D::GetRestAngle() const + RadianAnglef DampedRotarySpringConstraint2D::GetRestAngle() const { return float(cpDampedRotarySpringGetRestAngle(m_constraint)); } @@ -188,9 +188,9 @@ namespace Nz cpDampedSpringSetDamping(m_constraint, newDamping); } - void DampedRotarySpringConstraint2D::SetRestAngle(float newAngle) + void DampedRotarySpringConstraint2D::SetRestAngle(const RadianAnglef& newAngle) { - cpDampedRotarySpringSetRestAngle(m_constraint, newAngle); + cpDampedRotarySpringSetRestAngle(m_constraint, newAngle.angle); } void DampedRotarySpringConstraint2D::SetStiffness(float newStiffness) @@ -317,7 +317,7 @@ namespace Nz { } - float RatchetConstraint2D::GetAngle() const + RadianAnglef RatchetConstraint2D::GetAngle() const { return float(cpRatchetJointGetAngle(m_constraint)); } @@ -332,9 +332,9 @@ namespace Nz return float(cpRatchetJointGetRatchet(m_constraint)); } - void RatchetConstraint2D::SetAngle(float angle) + void RatchetConstraint2D::SetAngle(const RadianAnglef& angle) { - cpRatchetJointSetAngle(m_constraint, angle); + cpRatchetJointSetAngle(m_constraint, angle.angle); } void RatchetConstraint2D::SetPhase(float phase) @@ -348,29 +348,29 @@ namespace Nz } - RotaryLimitConstraint2D::RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) : - Constraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle)) + RotaryLimitConstraint2D::RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle) : + Constraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle.angle, maxAngle.angle)) { } - float RotaryLimitConstraint2D::GetMaxAngle() const + RadianAnglef RotaryLimitConstraint2D::GetMaxAngle() const { return float(cpRotaryLimitJointGetMax(m_constraint)); } - float RotaryLimitConstraint2D::GetMinAngle() const + RadianAnglef RotaryLimitConstraint2D::GetMinAngle() const { return float(cpRotaryLimitJointGetMax(m_constraint)); } - void RotaryLimitConstraint2D::SetMaxAngle(float maxAngle) + void RotaryLimitConstraint2D::SetMaxAngle(const RadianAnglef& maxAngle) { - cpRotaryLimitJointSetMax(m_constraint, maxAngle); + cpRotaryLimitJointSetMax(m_constraint, maxAngle.angle); } - void RotaryLimitConstraint2D::SetMinAngle(float minAngle) + void RotaryLimitConstraint2D::SetMinAngle(const RadianAnglef& minAngle) { - cpRotaryLimitJointSetMin(m_constraint, minAngle); + cpRotaryLimitJointSetMin(m_constraint, minAngle.angle); } diff --git a/src/Nazara/Physics2D/PhysWorld2D.cpp b/src/Nazara/Physics2D/PhysWorld2D.cpp index 764ca1cf8..7383510f8 100644 --- a/src/Nazara/Physics2D/PhysWorld2D.cpp +++ b/src/Nazara/Physics2D/PhysWorld2D.cpp @@ -26,7 +26,7 @@ namespace Nz { auto drawOptions = static_cast(userdata); if (drawOptions->circleCallback) - drawOptions->circleCallback(Vector2f(float(pos.x), float(pos.y)), float(angle), float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata); + drawOptions->circleCallback(Vector2f(float(pos.x), float(pos.y)), RadianAnglef(float(angle)), float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata); } void DrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor color, cpDataPointer userdata) diff --git a/src/Nazara/Physics2D/RigidBody2D.cpp b/src/Nazara/Physics2D/RigidBody2D.cpp index b12bc7e2e..16e737e30 100644 --- a/src/Nazara/Physics2D/RigidBody2D.cpp +++ b/src/Nazara/Physics2D/RigidBody2D.cpp @@ -185,9 +185,9 @@ namespace Nz return Rectf(Rect(bb.l, bb.b, bb.r - bb.l, bb.t - bb.b)); } - float RigidBody2D::GetAngularVelocity() const + RadianAnglef RigidBody2D::GetAngularVelocity() const + return float(cpBodyGetAngularVelocity(m_handle)); { - return FromRadians(static_cast(cpBodyGetAngularVelocity(m_handle))); } const Collider2DRef& RigidBody2D::GetGeom() const @@ -233,9 +233,9 @@ namespace Nz return Vector2f(static_cast(pos.x), static_cast(pos.y)); } - float RigidBody2D::GetRotation() const + RadianAnglef RigidBody2D::GetRotation() const { - return FromRadians(static_cast(cpBodyGetAngle(m_handle))); + return float(cpBodyGetAngle(m_handle)); } std::size_t RigidBody2D::GetShapeIndex(cpShape* shape) const @@ -283,9 +283,11 @@ namespace Nz return m_isStatic; } - void RigidBody2D::SetAngularVelocity(float angularVelocity) + void RigidBody2D::SetAngularVelocity(const RadianAnglef& angularVelocity) { - cpBodySetAngularVelocity(m_handle, ToRadians(angularVelocity)); + cpBodySetAngularVelocity(m_handle, angularVelocity.angle); + { + assert(shapeIndex < m_shapes.size()); } void RigidBody2D::SetGeom(Collider2DRef geom, bool recomputeMoment) @@ -400,9 +402,9 @@ namespace Nz } } - void RigidBody2D::SetRotation(float rotation) + void RigidBody2D::SetRotation(const RadianAnglef& rotation) { - cpBodySetAngle(m_handle, ToRadians(rotation)); + cpBodySetAngle(m_handle, rotation.angle); if (m_isStatic) { m_world->RegisterPostStep(this, [](Nz::RigidBody2D* body) diff --git a/tests/Engine/Graphics/Billboard.cpp b/tests/Engine/Graphics/Billboard.cpp index 5136e3af6..de0bc8d02 100644 --- a/tests/Engine/Graphics/Billboard.cpp +++ b/tests/Engine/Graphics/Billboard.cpp @@ -20,7 +20,7 @@ SCENARIO("Billboard", "[GRAPHICS][BILLBOARD]") { REQUIRE(billboard.GetColor() == materialColor); REQUIRE(billboard.GetMaterial().Get() == materialRef.Get()); - REQUIRE(billboard.GetRotation() == Approx(0.f)); + REQUIRE(billboard.GetRotation().angle == Approx(0.f)); REQUIRE(billboard.GetSize() == Nz::Vector2f(64.f, 64.f)); // Default sizes } diff --git a/tests/Engine/Physics2D/RigidBody2D.cpp b/tests/Engine/Physics2D/RigidBody2D.cpp index e801cc849..421a2b083 100644 --- a/tests/Engine/Physics2D/RigidBody2D.cpp +++ b/tests/Engine/Physics2D/RigidBody2D.cpp @@ -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()); } diff --git a/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp b/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp index 33871be57..bb6bf250a 100644 --- a/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp +++ b/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp @@ -85,15 +85,15 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") WHEN("We make rotate our entity") { - float angularSpeed = Nz::FromDegrees(45.f); + Nz::RadianAnglef angularSpeed = Nz::DegreeToRadian(45.f); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(2.f); THEN("It should have been rotated") { - CHECK(physicsComponent2D.GetAngularVelocity() == Approx(angularSpeed)); + CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(-2.f, 0.f, 2.f, 1.f)); - CHECK(physicsComponent2D.GetRotation() == Approx(Nz::FromDegrees(90.f))); + CHECK(physicsComponent2D.GetRotation() == Nz::RadianAnglef(Nz::DegreeToRadian(90.f))); CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Approx(Nz::FromDegrees(90.f))); } } @@ -129,7 +129,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") WHEN("We make rotate our entity") { - float angularSpeed = Nz::FromDegrees(45.f); + Nz::RadianAnglef angularSpeed(Nz::DegreeToRadian(45.f)); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(2.f); @@ -137,7 +137,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") { CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(1.f, 4.f, 2.f, 1.f)); - CHECK(physicsComponent2D.GetRotation() == Approx(Nz::FromDegrees(90.f))); + CHECK(physicsComponent2D.GetRotation() == 2.f * angularSpeed); CHECK(nodeComponent.GetPosition() == position); CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Approx(Nz::FromDegrees(90.f))); } diff --git a/tests/SDK/NDK/Systems/RenderSystem.cpp b/tests/SDK/NDK/Systems/RenderSystem.cpp index 09fb6add2..d68f544ab 100644 --- a/tests/SDK/NDK/Systems/RenderSystem.cpp +++ b/tests/SDK/NDK/Systems/RenderSystem.cpp @@ -82,29 +82,29 @@ SCENARIO("RenderSystem", "[NDK][RenderSystem]") WHEN("We set an angular velocity") { - float angularSpeed = Nz::FromDegrees(90.f); + Nz::RadianAnglef angularSpeed(Nz::DegreeToRadian(90.f)); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(1.f); THEN("We expect those to be true") { - CHECK(physicsComponent2D.GetAngularVelocity() == Approx(angularSpeed)); - CHECK(physicsComponent2D.GetRotation() == Approx(angularSpeed)); + CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed); + CHECK(physicsComponent2D.GetRotation() == angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(1.f, 4.f, 2.f, 1.f)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); world.Update(1.f); - CHECK(physicsComponent2D.GetRotation() == Approx(2.f * angularSpeed)); + CHECK(physicsComponent2D.GetRotation() == 2.f * angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.f, 2.f, 1.f, 2.f)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); world.Update(1.f); - CHECK(physicsComponent2D.GetRotation() == Approx(3.f * angularSpeed)); + CHECK(physicsComponent2D.GetRotation() == 3.f * angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(3.f, 3.f, 2.f, 1.f)); CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); world.Update(1.f); - CHECK(physicsComponent2D.GetRotation() == Approx(4.f * angularSpeed)); + CHECK(physicsComponent2D.GetRotation() == 4.f * angularSpeed); } } }