Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed some comilation problems.

File size: 4.6 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
35    Collision();
36    virtual ~Collision();
37
38    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
39    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
40
41
42    /* list stuff */
43  public:
44    typedef std::vector<CollisionEvent*>                  collisionVector;  //!< the vector containing all collision events
45    typedef std::vector<CollisionEvent*>::iterator        iterator;         //!< iterator definition
46    typedef std::vector<CollisionEvent*>::const_iterator  const_iterator;   //!< constant iterator definition
47
48    /** registers a @param event CollisionEvent to take place */
49    inline void registerCollisionEvent(CollisionEvent* event) { this->_collisionEvents.push_back(event); this->bDispatched = false;}
50    /** @returns a vector of collision events */
51    inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->_collisionEvents; }
52
53    void flushCollisionEvents();
54
55
56    /** @returns iterator pointing to the beginning of the collision event vector */
57    inline iterator       begin()        { return this->_collisionEvents.begin(); }
58    /** @returns const iterator pointing to the beginning of the collision event vector */
59    inline const_iterator begin() const  { return this->_collisionEvents.begin(); }
60    /** @returns iterator pointing to the end of the collision event vector */
61    inline iterator       end()          { return this->_collisionEvents.end(); }
62    /** @returns const iterator pointing to the end of the collision event vector */
63    inline const_iterator end() const    { return this->_collisionEvents.end(); }
64
65
66  private:
67    collisionVector  _collisionEvents;               //!< the collision event list
68
69
70
71    /* misc interface functions */
72  public:
73    /** @return Collision WorldEntity A */
74    inline WorldEntity* getEntityA() const { return this->entityA; }
75    /** @return Collision WorldEntity B */
76    inline WorldEntity* getEntityB() const { return this->entityB; }
77    inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const {
78      return ((this->entityA == &entityA && this->entityB == &entityB) || (this->entityA == &entityB && this->entityB == &entityA)); }
79
80    /** @return true if Entity A collides */
81    inline bool isEntityACollide() const { return this->entityACollide; }
82    /** sets the flag if it reacts @param flag true if it should react on entityA*/
83    inline void setEntityACollide(bool flag) { this->entityACollide = flag; }
84    /** @return true if Entity B collides */
85    inline bool isEntityBCollide() const { return this->entityBCollide; }
86    /** sets the flag if it reacts @param flag true if it should react on entityB*/
87    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
88
89
90
91    /** @returns true if this Collision has already been dispatched */
92    inline bool isDispatched() { return this->bDispatched; }
93    /** sets the dispatched flag to true */
94    inline void dispatched() { this->bDispatched = true; }
95
96  private:
97    WorldEntity*                 entityA;                       //!< the collision body A
98    WorldEntity*                 entityB;                       //!< the collision body B
99    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
100    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
101
102    bool                         bDispatched;                   //!< true if this collision has already been dispatched
103
104  };
105}
106
107#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.