Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

new structure in docs

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
20class WorldEntity;
21class BoundingVolume;
22class CollisionEvent;
23
24//! A class representing a simple collision
25class Collision
26{
27  public:
28    Collision();
29    virtual ~Collision();
30
31    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
32    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
33
34
35    /** @return Collision WorldEntity A */
36    inline WorldEntity* getEntityA() const { return this->entityA; }
37    /** @return Collision WorldEntity B */
38    inline WorldEntity* getEntityB() const { return this->entityB; }
39    /** @return true if Entity A collides */
40    inline bool isEntityACollide() const { return this->entityACollide; }
41    /** sets the flag if it reacts @param flag true if it should react on entityA*/
42    inline void setEntityACollide(bool flag) { this->entityACollide = flag; }
43    /** @return true if Entity B collides */
44    inline bool isEntityBCollide() const { return this->entityBCollide; }
45    /** sets the flag if it reacts @param flag true if it should react on entityB*/
46    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
47
48
49    /** @returns true if this Collision has already been dispatched */
50    inline bool isDispatched() { return this->bDispatched; }
51    /** sets the dispatched flag to true */
52    inline void dispatched() { this->bDispatched = true; }
53
54    /** registers a @param event CollisionEvent to take place */
55    inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;}
56    /** @returns a vector of collision events */
57    inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; }
58
59
60    void flushCollisionEvents();
61
62
63  private:
64    WorldEntity*                 entityA;                       //!< the collision body A
65    WorldEntity*                 entityB;                       //!< the collision body B
66    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
67    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
68
69    bool                         bDispatched;                   //!< true if this collision has already been dispatched
70
71    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
72};
73
74#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.