Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added namspacing to collision reaction. now comes the harder part :D

File size: 3.3 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    /** @returns true if this Collision has already been dispatched */
56    inline bool isDispatched() { return this->bDispatched; }
57    /** sets the dispatched flag to true */
58    inline void dispatched() { this->bDispatched = true; }
59
60    /** registers a @param event CollisionEvent to take place */
61    inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;}
62    /** @returns a vector of collision events */
63    inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; }
64
65
66    void flushCollisionEvents();
67
68
69  private:
70    WorldEntity*                 entityA;                       //!< the collision body A
71    WorldEntity*                 entityB;                       //!< the collision body B
72    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
73    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
74
75    bool                         bDispatched;                   //!< true if this collision has already been dispatched
76
77    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
78  };
79}
80
81#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.