Added a TriggerSystem, seems to work as intended.
This commit is contained in:
@@ -37,6 +37,7 @@ bool RayVsModel(const Ray& ray,
|
||||
|
||||
//Return true if the boxes are intersecting.
|
||||
bool AABBVsAABB(const AABB& a, const AABB& b);
|
||||
bool IsSameBoxProbably(const AABB& first, const AABB& second, const float epsilon = 0.0001f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ struct TriggerLeave : Event
|
||||
EntityID Trigger;
|
||||
};
|
||||
|
||||
/** Thrown when an entity is completely inside a trigger. */
|
||||
/** Thrown once, when an entity is completely inside a trigger. */
|
||||
struct TriggerEnter : Event
|
||||
{
|
||||
/** The id of the entity that entered the trigger. */
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "Core/EventBroker.h"
|
||||
#include "ETrigger.h"
|
||||
|
||||
class AABB;
|
||||
|
||||
class TriggerSystem : public System
|
||||
{
|
||||
public:
|
||||
@@ -18,7 +20,21 @@ public:
|
||||
virtual void Update(World* world, ComponentWrapper& collision, double dt) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<EntityID, std::unordered_set<EntityID>> m_EntitiesInTrigger;
|
||||
std::unordered_map<EntityID, std::unordered_set<EntityID>> m_EntitiesTouchingTrigger;
|
||||
std::unordered_map<EntityID, std::unordered_set<EntityID>> m_EntitiesCompletelyInTrigger;
|
||||
|
||||
bool getEntityBox(World* world, EntityID id, AABB& outBox);
|
||||
//True if leave event was thrown.
|
||||
bool throwLeaveIfWasInTrigger(std::unordered_set<EntityID>& triggerSet, EntityID pId, EntityID tId);
|
||||
void attachAABBComponentFromModel(World* world, EntityID id);
|
||||
template<typename Event>
|
||||
void publish(EntityID pId, EntityID tId)
|
||||
{
|
||||
Event e;
|
||||
e.Trigger = tId;
|
||||
e.Entity = pId;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user