Fixes
This commit is contained in:
@ -16,9 +16,11 @@
|
||||
|
||||
#include <IAEngine/Physics/Physics.hpp>
|
||||
|
||||
#include <IAEngine/Nodes/Node.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
Vector<BoxCollider2DComponent *> g_colliders;
|
||||
|
||||
VOID Physics::Initialize()
|
||||
{
|
||||
@ -28,26 +30,40 @@ namespace ia::iae
|
||||
{
|
||||
}
|
||||
|
||||
INLINE BOOL IsIntersectingH(IN CONST glm::vec4 &shape, IN FLOAT32 x)
|
||||
{
|
||||
return (x >= shape.x) && (x <= shape.z);
|
||||
}
|
||||
|
||||
INLINE BOOL IsIntersectingV(IN CONST glm::vec4 &shape, IN FLOAT32 y)
|
||||
{
|
||||
return (y >= shape.y) && (y <= shape.w);
|
||||
}
|
||||
|
||||
VOID Physics::Update()
|
||||
{
|
||||
for (SIZE_T i = 0; i < g_colliders.size(); i++)
|
||||
{
|
||||
for (SIZE_T j = i + 1; j < g_colliders.size(); j++)
|
||||
{
|
||||
const auto boxA = g_colliders[i]->AbsoluteShape();
|
||||
const auto boxB = g_colliders[j]->AbsoluteShape();
|
||||
const auto nodeA = g_colliders[i]->GetNode();
|
||||
|
||||
if(IsIntersectingH(boxB, boxA.z) && (IsIntersectingV(boxB, boxA.y) || IsIntersectingV(boxB, boxA.w)))
|
||||
nodeA->SetLocalPosition(nodeA->GetLocalPosition() + glm::vec3(-boxA.z + boxB.x, 0, 0));
|
||||
else if(IsIntersectingH(boxB, boxA.x) && (IsIntersectingV(boxB, boxA.y) || IsIntersectingV(boxB, boxA.w)))
|
||||
nodeA->SetLocalPosition(nodeA->GetLocalPosition() + glm::vec3(-boxA.x + boxB.z, 0, 0));
|
||||
else if(IsIntersectingV(boxB, boxA.w) && (IsIntersectingH(boxB, boxA.x) || IsIntersectingH(boxB, boxA.z)))
|
||||
nodeA->SetLocalPosition(nodeA->GetLocalPosition() + glm::vec3(0, -boxA.w + boxB.y, 0));
|
||||
else if(IsIntersectingV(boxB, boxA.y) && (IsIntersectingH(boxB, boxA.x) || IsIntersectingH(boxB, boxA.z)))
|
||||
nodeA->SetLocalPosition(nodeA->GetLocalPosition() + glm::vec3(0, -boxA.y + boxB.w, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handle Physics::CreateStaticBody(IN glm::vec3 position)
|
||||
VOID Physics::AddCollider(IN BoxCollider2DComponent *collider)
|
||||
{
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
Handle Physics::CreateDynamicBody(IN glm::vec3 position)
|
||||
{
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
VOID Physics::AddBoxCollider(IN Handle body, IN glm::vec3 size)
|
||||
{
|
||||
}
|
||||
|
||||
glm::vec3 Physics::GetBodyPosition(IN Handle body)
|
||||
{
|
||||
return {};
|
||||
g_colliders.pushBack(collider);
|
||||
}
|
||||
} // namespace ia::iae
|
||||
Reference in New Issue
Block a user