Rename Physics2D to ChipmunkPhysics2D
This commit is contained in:
committed by
Jérôme Leclercq
parent
b1255ad2ad
commit
26b23ccce6
@@ -1,26 +1,26 @@
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.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);
|
||||
Nz::ChipmunkRigidBody2D CreateBody(Nz::ChipmunkPhysWorld2D& world);
|
||||
void EQUALITY(const Nz::ChipmunkRigidBody2D& left, const Nz::ChipmunkRigidBody2D& 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;
|
||||
Nz::ChipmunkPhysWorld2D 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);
|
||||
std::shared_ptr<Nz::ChipmunkCollider2D> box = std::make_shared<Nz::ChipmunkBoxCollider2D>(aabb);
|
||||
float mass = 1.f;
|
||||
Nz::RigidBody2D body(&world, mass, box);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass, box);
|
||||
float angularVelocity = 0.2f;
|
||||
body.SetAngularVelocity(angularVelocity);
|
||||
Nz::Vector2f massCenter(5.f, 7.f);
|
||||
@@ -39,7 +39,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
WHEN("We copy construct the body")
|
||||
{
|
||||
body.AddForce(Nz::Vector2f(3.f, 5.f));
|
||||
Nz::RigidBody2D copiedBody(body);
|
||||
Nz::ChipmunkRigidBody2D copiedBody(body);
|
||||
EQUALITY(copiedBody, body);
|
||||
world.Step(Nz::Time::Second());
|
||||
EQUALITY(copiedBody, body);
|
||||
@@ -47,22 +47,22 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
WHEN("We move construct the body")
|
||||
{
|
||||
Nz::RigidBody2D copiedBody(body);
|
||||
Nz::RigidBody2D movedBody(std::move(body));
|
||||
Nz::ChipmunkRigidBody2D copiedBody(body);
|
||||
Nz::ChipmunkRigidBody2D movedBody(std::move(body));
|
||||
EQUALITY(movedBody, copiedBody);
|
||||
}
|
||||
|
||||
WHEN("We copy assign the body")
|
||||
{
|
||||
Nz::RigidBody2D copiedBody(&world, 0.f);
|
||||
Nz::ChipmunkRigidBody2D 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);
|
||||
Nz::ChipmunkRigidBody2D copiedBody(body);
|
||||
Nz::ChipmunkRigidBody2D movedBody(&world, 0.f);
|
||||
movedBody = std::move(body);
|
||||
EQUALITY(movedBody, copiedBody);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
WHEN("We set a new geometry")
|
||||
{
|
||||
float radius = 5.f;
|
||||
body.SetGeom(std::make_shared<Nz::CircleCollider2D>(radius));
|
||||
body.SetGeom(std::make_shared<Nz::ChipmunkCircleCollider2D>(radius));
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
|
||||
@@ -85,14 +85,14 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
GIVEN("A physic world")
|
||||
{
|
||||
Nz::PhysWorld2D world;
|
||||
Nz::ChipmunkPhysWorld2D 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;
|
||||
std::vector<Nz::ChipmunkRigidBody2D> tmp;
|
||||
tmp.push_back(CreateBody(world));
|
||||
tmp.push_back(CreateBody(world));
|
||||
|
||||
@@ -108,14 +108,14 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
GIVEN("A physic world and a rigid body")
|
||||
{
|
||||
Nz::PhysWorld2D world;
|
||||
Nz::ChipmunkPhysWorld2D 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);
|
||||
std::shared_ptr<Nz::ChipmunkCollider2D> box = std::make_shared<Nz::ChipmunkBoxCollider2D>(aabb);
|
||||
float mass = 1.f;
|
||||
Nz::RigidBody2D body(&world, mass);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass);
|
||||
body.SetGeom(box, true, false);
|
||||
|
||||
bool userData = false;
|
||||
@@ -211,14 +211,14 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
GIVEN("A physic world and a rigid body of circle")
|
||||
{
|
||||
Nz::PhysWorld2D world;
|
||||
Nz::ChipmunkPhysWorld2D 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);
|
||||
std::shared_ptr<Nz::ChipmunkCollider2D> circle = std::make_shared<Nz::ChipmunkCircleCollider2D>(radius, position);
|
||||
float mass = 1.f;
|
||||
Nz::RigidBody2D body(&world, mass);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass);
|
||||
body.SetGeom(circle, true, false);
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
@@ -235,21 +235,21 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
GIVEN("A physic world and a rigid body of compound")
|
||||
{
|
||||
Nz::PhysWorld2D world;
|
||||
Nz::ChipmunkPhysWorld2D 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);
|
||||
std::shared_ptr<Nz::ChipmunkBoxCollider2D> box1 = std::make_shared<Nz::ChipmunkBoxCollider2D>(aabb);
|
||||
aabb.Translate(Nz::Vector2f::Unit());
|
||||
std::shared_ptr<Nz::BoxCollider2D> box2 = std::make_shared<Nz::BoxCollider2D>(aabb);
|
||||
std::shared_ptr<Nz::ChipmunkBoxCollider2D> box2 = std::make_shared<Nz::ChipmunkBoxCollider2D>(aabb);
|
||||
|
||||
std::vector<std::shared_ptr<Nz::Collider2D>> colliders;
|
||||
std::vector<std::shared_ptr<Nz::ChipmunkCollider2D>> colliders;
|
||||
colliders.push_back(box1);
|
||||
colliders.push_back(box2);
|
||||
std::shared_ptr<Nz::CompoundCollider2D> compound = std::make_shared<Nz::CompoundCollider2D>(colliders);
|
||||
std::shared_ptr<Nz::ChipmunkCompoundCollider2D> compound = std::make_shared<Nz::ChipmunkCompoundCollider2D>(colliders);
|
||||
|
||||
float mass = 1.f;
|
||||
Nz::RigidBody2D body(&world, mass);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass);
|
||||
body.SetGeom(compound, true, false);
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
@@ -266,7 +266,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
GIVEN("A physic world and a rigid body of circle")
|
||||
{
|
||||
Nz::PhysWorld2D world;
|
||||
Nz::ChipmunkPhysWorld2D world;
|
||||
world.SetMaxStepCount(std::numeric_limits<std::size_t>::max());
|
||||
|
||||
std::vector<Nz::Vector2f> vertices;
|
||||
@@ -276,9 +276,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
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());
|
||||
std::shared_ptr<Nz::ChipmunkConvexCollider2D> convex = std::make_shared<Nz::ChipmunkConvexCollider2D>(sparsePtr, vertices.size());
|
||||
float mass = 1.f;
|
||||
Nz::RigidBody2D body(&world, mass);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass);
|
||||
body.SetGeom(convex, true, false);
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
@@ -295,14 +295,14 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
|
||||
GIVEN("A physic world and a rigid body of segment")
|
||||
{
|
||||
Nz::PhysWorld2D world;
|
||||
Nz::ChipmunkPhysWorld2D 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);
|
||||
std::shared_ptr<Nz::ChipmunkCollider2D> segment = std::make_shared<Nz::ChipmunkSegmentCollider2D>(positionA, positionB, 0.f);
|
||||
float mass = 1.f;
|
||||
Nz::RigidBody2D body(&world, mass);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass);
|
||||
body.SetGeom(segment, true, false);
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
@@ -318,20 +318,20 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
}
|
||||
}
|
||||
|
||||
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world)
|
||||
Nz::ChipmunkRigidBody2D CreateBody(Nz::ChipmunkPhysWorld2D& 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);
|
||||
std::shared_ptr<Nz::ChipmunkCollider2D> box = std::make_shared<Nz::ChipmunkBoxCollider2D>(aabb);
|
||||
float mass = 1.f;
|
||||
|
||||
Nz::RigidBody2D body(&world, mass, box);
|
||||
Nz::ChipmunkRigidBody2D body(&world, mass, box);
|
||||
body.SetPosition(Nz::Vector2f::Zero());
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right)
|
||||
void EQUALITY(const Nz::ChipmunkRigidBody2D& left, const Nz::ChipmunkRigidBody2D& right)
|
||||
{
|
||||
CHECK(left.GetAABB() == right.GetAABB());
|
||||
CHECK(left.GetAngularVelocity() == right.GetAngularVelocity());
|
||||
|
||||
Reference in New Issue
Block a user