Files
Seele/src/Engine/Physics/CollisionSystem.h
T

50 lines
1.3 KiB
C++
Raw Normal View History

2022-11-29 16:34:42 +01:00
#pragma once
#include <entt/entt.hpp>
#include "BVH.h"
#include "Containers/Map.h"
#include "Containers/Array.h"
#include "Component/Collider.h"
#include "Component/Transform.h"
namespace Seele
{
struct Collision
{
entt::entity a, b;
};
class CollisionSystem
{
public:
2023-01-21 18:43:21 +01:00
CollisionSystem(entt::registry& registry);
2022-11-29 16:34:42 +01:00
virtual ~CollisionSystem();
2023-01-21 18:43:21 +01:00
void detectCollisions(Array<Collision>& collisions);
2022-11-29 16:34:42 +01:00
private:
struct Witness
{
2023-01-21 18:43:21 +01:00
Vector p;
Vector n;
2022-11-29 16:34:42 +01:00
// for finding p
uint32_t point1Index;
// and the face where the plane lies on
uint32_t point2Index;
uint32_t point3Index;
uint32_t point4Index = UINT32_MAX;
entt::entity source;
entt::entity other;
};
BVH bvh;
2023-01-21 18:43:21 +01:00
entt::registry& registry;
2022-11-29 16:34:42 +01:00
Map<Pair<entt::entity, entt::entity>, Witness> cachedWitness;
2023-01-21 18:43:21 +01:00
bool checkCollision(Pair<entt::entity, entt::entity> pair);
2022-11-29 16:34:42 +01:00
2023-01-21 18:43:21 +01:00
void updateWitness(Witness& witness, const Vector& point, const Vector& v1, const Vector& v2);
2022-11-29 16:34:42 +01:00
// returns true if a collision was found
bool createWitness(Witness& witness, const Component::ShapeBase& source, const Component::ShapeBase& other);
// returns true if a collision was found
bool witnessValid(const Witness& witness, const Component::ShapeBase& shape1, const Component::ShapeBase& shape2);
};
} // namespace Seele