Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 4, 2006, 4:39:45 PM (17 years ago)
Author:
patrick
Message:

merged the temp branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/coll_rect.merge/src/lib/collision_reaction/collision.h

    r9869 r10010  
    11/*!
    22 * @file collision.h
    3  *  Definition of a collision as a two WE hit each other
     3 *  Definition of a collision relation of two WorldEntities
    44 *
    5  *  A is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one
     5 *  Is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one
    66 *  of the two CollisionHandles will calculate the CollisionReaction and the bDispatched flag will be set afterwards
    77 *  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.
    812 */
    913
     
    1418#include <vector>
    1519
     20
     21
    1622class WorldEntity;
    1723class BoundingVolume;
    18 class CollisionEvent;
    1924
    20 //! A class representing a simple collision
    21 class Collision
     25namespace CoRe
    2226{
     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
    2339  public:
     40
    2441    Collision();
    2542    virtual ~Collision();
    2643
    2744    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    28     inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
     45    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->_entityA = entityA; this->_entityB = entityB; }
    2946
    3047
    31     /** @return Collision WorldEntity A */
    32     inline WorldEntity* getEntityA() const { return this->entityA; }
    33     /** @return Collision WorldEntity B */
    34     inline WorldEntity* getEntityB() const { return this->entityB; }
    35     /** @return true if Entity A collides */
    36     inline bool isEntityACollide() const { return this->entityACollide; }
    37     /** sets the flag if it reacts @param flag true if it should react on entityA*/
    38     inline void setEntityACollide(bool flag) { this->entityACollide = flag; }
    39     /** @return true if Entity B collides */
    40     inline bool isEntityBCollide() const { return this->entityBCollide; }
    41     /** sets the flag if it reacts @param flag true if it should react on entityB*/
    42     inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
     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();
    4355
    4456
    45     /** @returns true if this Collision has already been dispatched */
    46     inline bool isDispatched() { return this->bDispatched; }
    47     /** sets the dispatched flag to true */
    48     inline void dispatched() { this->bDispatched = true; }
    49 
    50     /** registers a @param event CollisionEvent to take place */
    51     inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;}
    52     /** @returns a vector of collision events */
    53     inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; }
     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(); }
    5465
    5566
    56     void flushCollisionEvents();
     67    /* misc interface functions */
     68  public:
     69    /** @return Collision WorldEntity A */
     70    inline WorldEntity* getEntityA() const { return this->_entityA; }
     71    /** @return Collision WorldEntity B */
     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
     76    /** @return true if Entity A collides */
     77    inline bool isEntityACollide() const { return this->_entityACollide; }
     78    /** sets the flag if it reacts @param flag true if it should react on entityA*/
     79    inline void setEntityACollide(bool flag) { this->_entityACollide = flag; }
     80    /** @return true if Entity B collides */
     81    inline bool isEntityBCollide() const { return this->_entityBCollide; }
     82    /** sets the flag if it reacts @param flag true if it should react on entityB*/
     83    inline void setEntityBCollide(bool flag) { this->_entityACollide = flag; }
    5784
    5885
    5986  private:
    60     WorldEntity*                 entityA;                       //!< the collision body A
    61     WorldEntity*                 entityB;                       //!< the collision body B
    62     bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
    63     bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
     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
    6491
    65     bool                         bDispatched;                   //!< true if this collision has already been dispatched
     92    CollisionVector              _collisionEvents;               //!< the collision event list
    6693
    67     std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
    68 };
     94  };
     95}
    6996
    7097#endif /* _COLLISION_H */
Note: See TracChangeset for help on using the changeset viewer.