2023-01-18 14:42:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ecs_system.hpp"
|
|
|
|
|
2023-02-02 17:32:19 +00:00
|
|
|
#include "components/collider.hpp"
|
|
|
|
|
|
|
|
#include <glm/mat4x4.hpp>
|
|
|
|
|
2023-01-18 14:42:09 +00:00
|
|
|
namespace engine {
|
|
|
|
|
|
|
|
class PhysicsSystem : public System {
|
|
|
|
|
|
|
|
public:
|
|
|
|
PhysicsSystem(Scene* scene);
|
|
|
|
|
|
|
|
void onUpdate(float ts) override;
|
|
|
|
|
2023-02-02 17:32:19 +00:00
|
|
|
void onComponentInsert(uint32_t entity) override;
|
2023-02-09 15:21:37 +00:00
|
|
|
|
|
|
|
struct CollisionEvent {
|
|
|
|
bool isCollisionEnter; // false == collision exit
|
|
|
|
uint32_t collidedEntity; // the entity that this entity collided with
|
|
|
|
glm::vec3 normal; // the normal of the surface this entity collided with; ignored on collision exit
|
2023-02-12 14:50:29 +00:00
|
|
|
glm::vec3 point; // where the collision was detected
|
2023-02-09 15:21:37 +00:00
|
|
|
};
|
2023-02-02 17:32:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2023-02-09 15:21:37 +00:00
|
|
|
// dynamic arrays to avoid realloc on every frame
|
|
|
|
|
|
|
|
// entity, aabb, isTrigger
|
|
|
|
std::vector<std::tuple<uint32_t, AABB, bool>> m_staticAABBs{};
|
|
|
|
std::vector<std::tuple<uint32_t, AABB, bool>> m_dynamicAABBs{};
|
|
|
|
|
|
|
|
struct PossibleCollision {
|
|
|
|
uint32_t staticEntity;
|
|
|
|
AABB staticAABB;
|
|
|
|
bool staticTrigger;
|
|
|
|
uint32_t dynamicEntity;
|
|
|
|
AABB dynamicAABB;
|
|
|
|
bool dynamicTrigger;
|
2023-02-02 17:32:19 +00:00
|
|
|
};
|
2023-02-09 15:21:37 +00:00
|
|
|
std::vector<PossibleCollision> m_possibleCollisions{};
|
|
|
|
std::vector<std::pair<uint32_t, CollisionEvent>> m_collisionInfos{}; // target entity, event info
|
2023-02-02 17:32:19 +00:00
|
|
|
|
2023-01-18 14:42:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|