Physics Debug Draw
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
#include <IAEngine/Physics/Physics.hpp>
|
||||
#include <IAEngine/Rendering/DebugDraw.hpp>
|
||||
|
||||
#include <IAEngine/Nodes/Node.hpp>
|
||||
|
||||
@ -23,6 +24,8 @@
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
BOOL g_physicsDebugDrawEnabled = false;
|
||||
|
||||
Vector<PhysicsComponent *> g_physicsComponents;
|
||||
|
||||
FLOAT32 Sq(IN FLOAT32 v)
|
||||
@ -45,7 +48,7 @@ namespace ia::iae
|
||||
const auto dY = abs(d.y);
|
||||
if (d.x >= 0)
|
||||
{
|
||||
if (dX >= dY)
|
||||
if (dX > dY)
|
||||
{
|
||||
return RectSide::RIGHT;
|
||||
}
|
||||
@ -56,7 +59,7 @@ namespace ia::iae
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dX >= dY)
|
||||
if (dX > dY)
|
||||
{
|
||||
return RectSide::LEFT;
|
||||
}
|
||||
@ -80,6 +83,23 @@ namespace ia::iae
|
||||
{
|
||||
}
|
||||
|
||||
VOID Physics::DebugDraw()
|
||||
{
|
||||
if(!g_physicsDebugDrawEnabled)
|
||||
return;
|
||||
|
||||
for(const auto& t: g_physicsComponents)
|
||||
{
|
||||
for(const auto& c: t->Colliders())
|
||||
{
|
||||
auto color = glm::vec4{0.75f, 0.0f, 0.0f, 1.0f};
|
||||
if(c.IsTrigger)
|
||||
color = {0.25f, 0.45f, 0.75f, 0.75f};
|
||||
DebugDraw::DrawRect(t->GetNode()->GetPosition() + c.Position, c.Size, color, 2.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handle Physics::RegisterComponent(IN PhysicsComponent *component)
|
||||
{
|
||||
g_physicsComponents.pushBack(component);
|
||||
@ -101,17 +121,16 @@ namespace ia::iae
|
||||
const auto tMiddle = t->GetNode()->GetPosition() + tc.Position + tc.Size / 2.0f;
|
||||
const auto tHalfSize = tc.Size / 2.0f;
|
||||
const auto rectSide = GetRectSide(tMiddle - middle);
|
||||
const auto distance = Sq(tMiddle.x - middle.x) + Sq(tMiddle.y - middle.y);
|
||||
switch (rectSide)
|
||||
{
|
||||
case RectSide::LEFT:
|
||||
case RectSide::RIGHT:
|
||||
isColliding = (Sq(tHalfSize.x + halfSize.x) >= distance);
|
||||
isColliding = ((tHalfSize.x + halfSize.x) >= abs(tMiddle.x - middle.x));
|
||||
break;
|
||||
|
||||
case RectSide::TOP:
|
||||
case RectSide::BOTTOM:
|
||||
isColliding = (Sq(tHalfSize.y + halfSize.y) >= distance);
|
||||
isColliding = ((tHalfSize.y + halfSize.y) >= abs(tMiddle.y - middle.y));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user