1 | /*! |
---|
2 | * @file collision_tube.h |
---|
3 | * |
---|
4 | * collision tube collects all collisions from all entities |
---|
5 | * |
---|
6 | * The collision events are saved in the _collisionList vector in a fixed hirarchy: a collision is defined by the world entities |
---|
7 | * that collide. For each collision there is an entry in _collisionList. Each collision itself again contains collision events which are |
---|
8 | * defined as collisions between the boundibg volumes (BV) of the world entities. This could look like this: |
---|
9 | * |
---|
10 | * - Collision (WorldEntity_i <=> WorldEntity_j) |
---|
11 | * +- CollisionEvent( some BV <=> some other BV) |
---|
12 | * +- CollisionEvent( some BV <=> some other BV) |
---|
13 | * - Collision (WorldEntity_k <=> WorldEntity_l) |
---|
14 | * +- CollisionEvent( some BV <=> some other BV) |
---|
15 | * +- CollisionEvent( some BV <=> some other BV) |
---|
16 | * +- CollisionEvent( some BV <=> some other BV) |
---|
17 | * +- CollisionEvent( some BV <=> some other BV) |
---|
18 | * - ... etc ... |
---|
19 | * |
---|
20 | * |
---|
21 | * When the collisions are processed by the handleCollision() function each collision pair is checked for their reactions (since each |
---|
22 | * WorldEntity can define several reactions to a collision). After all the reactions are calculated and applied the collision object is |
---|
23 | * put back. |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef _COLLISION_TUBE_H |
---|
27 | #define _COLLISION_TUBE_H |
---|
28 | |
---|
29 | #include "base_object.h" |
---|
30 | #include "cr_engine.h" |
---|
31 | #include "world_entity.h" |
---|
32 | |
---|
33 | #include "vector.h" |
---|
34 | #include <vector> |
---|
35 | |
---|
36 | class Collision; |
---|
37 | class WorldEntity; |
---|
38 | class BoundingVolume; |
---|
39 | |
---|
40 | namespace CoRe |
---|
41 | { |
---|
42 | |
---|
43 | class CollisionReaction; |
---|
44 | |
---|
45 | //! A class containing all CollisionEvents (structured as defined in the file doxygen tags) |
---|
46 | class CollisionTube : public BaseObject |
---|
47 | { |
---|
48 | ObjectListDeclaration(CollisionTube); |
---|
49 | |
---|
50 | typedef std::vector<Collision*>::iterator CollisionIterator; |
---|
51 | typedef std::vector<Collision*> CollisionVector; |
---|
52 | |
---|
53 | |
---|
54 | /* Constructor/Deconstructor/Singleton Interface */ |
---|
55 | public: |
---|
56 | inline static CollisionTube* getInstance() { if( !singletonRef) singletonRef = new CollisionTube(); return singletonRef; } |
---|
57 | |
---|
58 | virtual ~CollisionTube(); |
---|
59 | |
---|
60 | private: |
---|
61 | CollisionTube(); |
---|
62 | CollisionTube(const CollisionTube& tube) {} |
---|
63 | |
---|
64 | static CollisionTube* singletonRef; //!< the singleton instance |
---|
65 | |
---|
66 | |
---|
67 | /* Collision Handling */ |
---|
68 | public: |
---|
69 | void registerCollisionEvent(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB); |
---|
70 | void registerCollisionEvent(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, |
---|
71 | const Vector& normal, const Vector& position, bool bInWall = false); |
---|
72 | Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB); |
---|
73 | |
---|
74 | void reset(); |
---|
75 | |
---|
76 | /** @returns an iterator pointing to the beginning of the list */ |
---|
77 | CollisionIterator begin() { return this->_collisionList.begin(); } |
---|
78 | /** @returns an iterator pointing to the end of the list */ |
---|
79 | CollisionIterator end() { return this->_collisionList.end(); } |
---|
80 | |
---|
81 | |
---|
82 | private: |
---|
83 | CollisionVector _collisionList; //!< the list of collisions since the last processing |
---|
84 | |
---|
85 | |
---|
86 | /* Misc State Informations */ |
---|
87 | public: |
---|
88 | /** @returns true if at least one of both WorldEntities are subscribed for a collision reaction */ |
---|
89 | inline bool isReactive(const WorldEntity& entityA, const WorldEntity& entityB) const |
---|
90 | { return (entityA.isReactive(entityB) && entityB.isReactive(entityA)); } |
---|
91 | |
---|
92 | }; |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | #endif /* _COLLISION_TUBE_H */ |
---|