1 | /*! |
---|
2 | * @file collision.h |
---|
3 | * Definition of a collision as a two WE hit each other |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _COLLISION_H |
---|
7 | #define _COLLISION_H |
---|
8 | |
---|
9 | #include "vector.h" |
---|
10 | #include <vector> |
---|
11 | |
---|
12 | class WorldEntity; |
---|
13 | class BoundingVolume; |
---|
14 | class CollisionEvent; |
---|
15 | |
---|
16 | //! A class representing a simple collision |
---|
17 | class Collision |
---|
18 | { |
---|
19 | |
---|
20 | public: |
---|
21 | Collision(); |
---|
22 | virtual ~Collision(); |
---|
23 | |
---|
24 | /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ |
---|
25 | inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; } |
---|
26 | |
---|
27 | |
---|
28 | /** @return Collision WorldEntity A */ |
---|
29 | inline WorldEntity* getEntityA() const { return this->entityA; } |
---|
30 | /** @return Collision WorldEntity B */ |
---|
31 | inline WorldEntity* getEntityB() const { return this->entityB; } |
---|
32 | /** @return true if Entity A collides */ |
---|
33 | inline bool isEntityACollide() { return this->entityACollide; } |
---|
34 | /** @return true if Entity B collides */ |
---|
35 | inline bool isEntityBCollide() { return this->entityBCollide; } |
---|
36 | |
---|
37 | /** @returns true if this Collision has already been dispatched */ |
---|
38 | inline bool isDispatched() { return this->bDispatched; } |
---|
39 | |
---|
40 | /** registers a @param event CollisionEvent to take place */ |
---|
41 | inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); } |
---|
42 | /** @returns a vector of collision events */ |
---|
43 | inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; } |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | void handleCollisionEvents(); |
---|
48 | |
---|
49 | |
---|
50 | private: |
---|
51 | void flushCollisionEvents(); |
---|
52 | |
---|
53 | |
---|
54 | private: |
---|
55 | WorldEntity* entityA; //!< the collision body A |
---|
56 | WorldEntity* entityB; //!< the collision body B |
---|
57 | bool entityACollide; //!< true if entity A is subscribed for collision reaction |
---|
58 | bool entityBCollide; //!< true if entity B is subscribed for collision reaction |
---|
59 | |
---|
60 | bool bDispatched; //!< true if this collision has already been dispatched |
---|
61 | |
---|
62 | std::vector<CollisionEvent*> collisionEvents; //!< the collision event list |
---|
63 | }; |
---|
64 | |
---|
65 | #endif /* _COLLISION_H */ |
---|