Fix wrong aabb returned from PhysicsComponent2D (#127)
This commit is contained in:
parent
6ff510ad4a
commit
47a22c2785
|
|
@ -121,11 +121,14 @@ namespace Nz
|
|||
|
||||
Rectf RigidBody2D::GetAABB() const
|
||||
{
|
||||
cpBB bb = cpBBNew(0.f, 0.f, 0.f, 0.f);
|
||||
for (cpShape* shape : m_shapes)
|
||||
bb = cpBBMerge(bb, cpShapeGetBB(shape));
|
||||
if (m_shapes.empty())
|
||||
return Rectf::Zero();
|
||||
|
||||
return Rectf(Rect<cpFloat>(bb.l, bb.t, bb.r - bb.l, bb.b - bb.t));
|
||||
cpBB bb = cpShapeGetBB(*m_shapes.begin());
|
||||
for (auto it = ++m_shapes.begin(); it != m_shapes.end(); ++it)
|
||||
bb = cpBBMerge(bb, cpShapeGetBB(*it));
|
||||
|
||||
return Rectf(Rect<cpFloat>(bb.l, bb.b, bb.r - bb.l, bb.t - bb.b));
|
||||
}
|
||||
|
||||
float RigidBody2D::GetAngularVelocity() const
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
#include <NDK/Systems/PhysicsSystem2D.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <NDK/Components/CollisionComponent2D.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]")
|
||||
{
|
||||
GIVEN("A world and an entity")
|
||||
{
|
||||
Ndk::World world;
|
||||
const Ndk::EntityHandle& entity = world.CreateEntity();
|
||||
Ndk::NodeComponent& nodeComponent = entity->AddComponent<Ndk::NodeComponent>();
|
||||
Nz::Vector2f position(2.f, 3.f);
|
||||
nodeComponent.SetPosition(position);
|
||||
Nz::Rectf aabb(0.f, 0.f, 16.f, 18.f);
|
||||
Nz::BoxCollider2DRef collisionBox = Nz::BoxCollider2D::New(aabb);
|
||||
Ndk::CollisionComponent2D& collisionComponent = entity->AddComponent<Ndk::CollisionComponent2D>(collisionBox);
|
||||
Ndk::PhysicsComponent2D& physicsComponent = entity->AddComponent<Ndk::PhysicsComponent2D>();
|
||||
|
||||
WHEN("We update the world")
|
||||
{
|
||||
world.Update(1.f);
|
||||
|
||||
THEN("Entity should have correct bounding box")
|
||||
{
|
||||
REQUIRE(nodeComponent.GetPosition() == position);
|
||||
aabb.Translate(position);
|
||||
REQUIRE(physicsComponent.GetAABB() == aabb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("PhysicsSystem", "[NDK][PHYSICSSYSTEM]")
|
||||
SCENARIO("PhysicsSystem3D", "[NDK][PHYSICSSYSTEM3D]")
|
||||
{
|
||||
GIVEN("A world and a static entity & a dynamic entity")
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue