engine/include/systems/collisions.hpp

61 lines
1.5 KiB
C++
Raw Normal View History

2023-01-18 14:42:09 +00:00
#pragma once
2023-04-29 14:22:25 +00:00
#include <cstdint>
#include <vector>
2023-02-02 17:32:19 +00:00
#include <glm/mat4x4.hpp>
2023-04-29 14:22:25 +00:00
#include "components/collider.hpp"
#include "ecs_system.hpp"
2023-01-18 14:42:09 +00:00
namespace engine {
class PhysicsSystem : public System {
public:
PhysicsSystem(Scene* scene);
2023-04-29 14:22:25 +00:00
void OnUpdate(float ts) override;
2023-01-18 14:42:09 +00:00
2023-04-29 14:22:25 +00:00
void OnComponentInsert(uint32_t entity) override;
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-02 17:32:19 +00:00
private:
// 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 {
2023-02-18 15:54:31 +00:00
PossibleCollision(uint32_t staticEntity, AABB staticAABB, bool staticTrigger, uint32_t dynamicEntity, AABB dynamicAABB, bool dynamicTrigger) :
staticEntity(staticEntity),
staticAABB(staticAABB),
staticTrigger(staticTrigger),
dynamicEntity(dynamicEntity),
dynamicAABB(dynamicAABB),
dynamicTrigger(dynamicTrigger) {}
uint32_t staticEntity;
AABB staticAABB;
bool staticTrigger;
uint32_t dynamicEntity;
AABB dynamicAABB;
bool dynamicTrigger;
2023-02-02 17:32:19 +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
};
}