Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/collision.h @ 9894

Last change on this file since 9894 was 9892, checked in by patrick, 18 years ago

new interface to collision registers, more transparent. some more functionality

File size: 3.5 KB
Line 
1/*!
2 * @file collision.h
3 *  Definition of a collision relation of two WorldEntities
4 *
5 *  Is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one
6 *  of the two CollisionHandles will calculate the CollisionReaction and the bDispatched flag will be set afterwards
7 *  to signal that it's already cared about and should be ignored.
8 *
9 *  The collisions itself are saved in this container (CollisionEvent). Since there can be multiple collision events
10 *  for one collision. Imagine: two objects are intersecting (this throws a Collision): many collision boxes will fire
11 *  each of this boxes will "create" a CollisionEvent.
12 */
13
14#ifndef _COLLISION_H
15#define _COLLISION_H
16
17#include "vector.h"
18#include <vector>
19
20
21
22class WorldEntity;
23class BoundingVolume;
24
25namespace CoRe
26{
27
28  class CollisionEvent;
29
30  //! A class representing a simple collision
31  class Collision
32  {
33  public:
34    Collision();
35    virtual ~Collision();
36
37    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
38    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
39
40
41    /** @return Collision WorldEntity A */
42    inline WorldEntity* getEntityA() const { return this->entityA; }
43    /** @return Collision WorldEntity B */
44    inline WorldEntity* getEntityB() const { return this->entityB; }
45    /** @return true if Entity A collides */
46    inline bool isEntityACollide() const { return this->entityACollide; }
47    /** sets the flag if it reacts @param flag true if it should react on entityA*/
48    inline void setEntityACollide(bool flag) { this->entityACollide = flag; }
49    /** @return true if Entity B collides */
50    inline bool isEntityBCollide() const { return this->entityBCollide; }
51    /** sets the flag if it reacts @param flag true if it should react on entityB*/
52    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
53
54
55    inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const {
56      return ((this->entityA == &entityA && this->entityB == &entityB) || (this->entityA == &entityB && this->entityB == &entityA)); }
57    /** @returns true if this Collision has already been dispatched */
58    inline bool isDispatched() { return this->bDispatched; }
59    /** sets the dispatched flag to true */
60    inline void dispatched() { this->bDispatched = true; }
61
62    /** registers a @param event CollisionEvent to take place */
63    inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;}
64    /** @returns a vector of collision events */
65    inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; }
66
67
68    void flushCollisionEvents();
69
70
71  private:
72    WorldEntity*                 entityA;                       //!< the collision body A
73    WorldEntity*                 entityB;                       //!< the collision body B
74    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
75    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
76
77    bool                         bDispatched;                   //!< true if this collision has already been dispatched
78
79    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
80  };
81}
82
83#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.