Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9983 was 9983, checked in by patrick, 17 years ago

collision object adjustements

File size: 4.1 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  ConstIterator;   //!< 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
51    void flushCollisionEvents();
52
53
54    /** @returns iterator pointing to the beginning of the collision event vector */
55    inline Iterator       begin()        { return this->_collisionEvents.begin(); }
56    /** @returns const iterator pointing to the beginning of the collision event vector */
57    inline ConstIterator  begin() const  { return this->_collisionEvents.begin(); }
58    /** @returns iterator pointing to the end of the collision event vector */
59    inline Iterator       end()          { return this->_collisionEvents.end(); }
60    /** @returns const iterator pointing to the end of the collision event vector */
61    inline ConstIterator  end() const    { return this->_collisionEvents.end(); }
62
63
64    /* misc interface functions */
65  public:
66    /** @return Collision WorldEntity A */
67    inline WorldEntity* getEntityA() const { return this->_entityA; }
68    /** @return Collision WorldEntity B */
69    inline WorldEntity* getEntityB() const { return this->_entityB; }
70    inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const {
71      return ((this->_entityA == &entityA && this->_entityB == &entityB) || (this->_entityA == &entityB && this->_entityB == &entityA)); }
72
73    /** @return true if Entity A collides */
74    inline bool isEntityACollide() const { return this->_entityACollide; }
75    /** sets the flag if it reacts @param flag true if it should react on entityA*/
76    inline void setEntityACollide(bool flag) { this->_entityACollide = flag; }
77    /** @return true if Entity B collides */
78    inline bool isEntityBCollide() const { return this->_entityBCollide; }
79    /** sets the flag if it reacts @param flag true if it should react on entityB*/
80    inline void setEntityBCollide(bool flag) { this->_entityACollide = flag; }
81
82
83  private:
84    WorldEntity*                 _entityA;                       //!< the collision body A
85    WorldEntity*                 _entityB;                       //!< the collision body B
86    bool                         _entityACollide;                //!< true if entity A is subscribed for collision reaction
87    bool                         _entityBCollide;                //!< true if entity B is subscribed for collision reaction
88
89    collisionVector              _collisionEvents;               //!< the collision event list
90
91  };
92}
93
94#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.