Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cr/src/lib/collision_reaction/collision.h @ 8124

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

cr: some bugs found and solved, minor cleanup

File size: 2.9 KB
Line 
1/*!
2 * @file collision.h
3 *  Definition of a collision as a two WE hit each other
4 *
5 *  A 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
10#ifndef _COLLISION_H
11#define _COLLISION_H
12
13#include "vector.h"
14#include <vector>
15
16class WorldEntity;
17class BoundingVolume;
18class CollisionEvent;
19
20//! A class representing a simple collision
21class Collision
22{
23
24  public:
25    Collision();
26    virtual ~Collision();
27
28    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
29    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; }
30
31
32    /** @return Collision WorldEntity A */
33    inline WorldEntity* getEntityA() const { return this->entityA; }
34    /** @return Collision WorldEntity B */
35    inline WorldEntity* getEntityB() const { return this->entityB; }
36    /** @return true if Entity A collides */
37    inline bool isEntityACollide() const { return this->entityACollide; }
38    /** sets the flag if it reacts @param flag true if it should react on entityA*/
39    inline void setEntityACollide(bool flag) { this->entityACollide = flag; }
40    /** @return true if Entity B collides */
41    inline bool isEntityBCollide() const { return this->entityBCollide; }
42    /** sets the flag if it reacts @param flag true if it should react on entityB*/
43    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
44
45    /** @returns true if this Collision has already been dispatched */
46    inline bool isDispatched() { return this->bDispatched; }
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
54    void handleCollisionEvents();
55
56
57  private:
58    void flushCollisionEvents();
59
60
61  private:
62    WorldEntity*                 entityA;                       //!< the collision body A
63    WorldEntity*                 entityB;                       //!< the collision body B
64    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
65    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
66
67    bool                         bDispatched;                   //!< true if this collision has already been dispatched
68
69    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
70};
71
72#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.