Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_reaction/collision.h @ 10715

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

merged the collision reaction branche back to trunk

File size: 4.0 KB
RevLine 
[7934]1/*!
[5039]2 * @file collision.h
[10013]3 *  Definition of a collision relation of two WorldEntities
[8124]4 *
[10013]5 *  Is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one
[8124]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.
[10013]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.
[7934]12 */
[4510]13
[4511]14#ifndef _COLLISION_H
15#define _COLLISION_H
[4510]16
[4520]17#include "vector.h"
[7964]18#include <vector>
[4510]19
[10013]20
21
[4520]22class WorldEntity;
23class BoundingVolume;
[4510]24
[10013]25namespace CoRe
[7968]26{
[10013]27
28  class CollisionEvent;
29
30  //! A class representing a simple collision
31  class Collision
32  {
33
34    typedef std::vector<CollisionEvent*>                  CollisionVector;  //!< the vector containing all collision events
35    typedef std::vector<CollisionEvent*>::iterator        Iterator;         //!< iterator definition
36    typedef std::vector<CollisionEvent*>::const_iterator  ConstIterator;   //!< constant iterator definition
37
38
[7968]39  public:
[10013]40
[7968]41    Collision();
42    virtual ~Collision();
[4510]43
[7968]44    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
[10013]45    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->_entityA = entityA; this->_entityB = entityB; }
[7934]46
47
[10013]48    /* list stuff */
49  public:
50
51    /** registers a @param event CollisionEvent to take place */
52    inline void registerCollisionEvent(CollisionEvent* event) { this->_collisionEvents.push_back(event); }
53
54    void reset();
55
56
57    /** @returns iterator pointing to the beginning of the collision event vector */
58    inline Iterator       begin()        { return this->_collisionEvents.begin(); }
59    /** @returns const iterator pointing to the beginning of the collision event vector */
60    inline ConstIterator  begin() const  { return this->_collisionEvents.begin(); }
61    /** @returns iterator pointing to the end of the collision event vector */
62    inline Iterator       end()          { return this->_collisionEvents.end(); }
63    /** @returns const iterator pointing to the end of the collision event vector */
64    inline ConstIterator  end() const    { return this->_collisionEvents.end(); }
65
66
67    /* misc interface functions */
68  public:
[7968]69    /** @return Collision WorldEntity A */
[10013]70    inline WorldEntity* getEntityA() const { return this->_entityA; }
[7968]71    /** @return Collision WorldEntity B */
[10013]72    inline WorldEntity* getEntityB() const { return this->_entityB; }
73    inline bool same(const WorldEntity& entityA, WorldEntity& entityB) const {
74      return ((this->_entityA == &entityA && this->_entityB == &entityB) || (this->_entityA == &entityB && this->_entityB == &entityA)); }
75
[8106]76    /** @return true if Entity A collides */
[10013]77    inline bool isEntityACollide() const { return this->_entityACollide; }
[8108]78    /** sets the flag if it reacts @param flag true if it should react on entityA*/
[10013]79    inline void setEntityACollide(bool flag) { this->_entityACollide = flag; }
[8106]80    /** @return true if Entity B collides */
[10013]81    inline bool isEntityBCollide() const { return this->_entityBCollide; }
[8108]82    /** sets the flag if it reacts @param flag true if it should react on entityB*/
[10013]83    inline void setEntityBCollide(bool flag) { this->_entityBCollide = flag; }
[7940]84
[8490]85
[7968]86  private:
[10013]87    WorldEntity*                 _entityA;                       //!< the collision body A
88    WorldEntity*                 _entityB;                       //!< the collision body B
89    bool                         _entityACollide;                //!< true if entity A is subscribed for collision reaction
90    bool                         _entityBCollide;                //!< true if entity B is subscribed for collision reaction
[7968]91
[10013]92    CollisionVector              _collisionEvents;               //!< the collision event list
[8029]93
[10013]94  };
95}
[4510]96
[4511]97#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.