Files
IAEngine/Src/IAEngine/imp/cpp/Physics/Physics.cpp
Isuru Samarathunga 5f112f7531 Collision 1/2
2025-09-29 03:36:31 +05:30

62 lines
1.8 KiB
C++

// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <IAEngine/IAEngine.hpp>
#include <IAEngine/Physics/Physics.hpp>
#include <IAEngine/Nodes/Node.hpp>
#include <map>
namespace ia::iae
{
Vector<PhysicsComponent *> g_physicsComponents;
VOID Physics::Initialize()
{
}
VOID Physics::Terminate()
{
}
VOID Physics::Update()
{
}
Handle Physics::RegisterComponent(IN PhysicsComponent *component)
{
g_physicsComponents.pushBack(component);
return g_physicsComponents.size() - 1;
}
BOOL Physics::CanMove(IN Handle handle, IN CONST PhysicsComponent::Collider &collider, IN glm::vec2 movement)
{
const auto comp = g_physicsComponents[handle];
const auto middle = comp->GetNode()->GetPosition() + movement + collider.Position + collider.Size / 2.0f;
for (const auto &t : g_physicsComponents)
{
if (t == comp)
continue;
for(const auto& tc: t->Colliders())
{
const auto tMiddle = t->GetNode()->GetPosition() + tc.Position + tc.Size / 2.0f;
}
}
return true;
}
} // namespace ia::iae