Added a TriggerSystem, seems to work as intended.

This commit is contained in:
William Moberg
2015-12-15 14:49:52 +01:00
parent ae7d4b9097
commit 170610bcb1
9 changed files with 178 additions and 24 deletions
+1
View File
@@ -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);
}
+1 -1
View File
@@ -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. */
+17 -1
View File
@@ -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