Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

collision tube register collision events interface

File size: 3.4 KB
RevLine 
[7934]1/*!
[5039]2 * @file collision.h
[9888]3 *  Definition of a collision relation of two WorldEntities
[8124]4 *
[9888]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.
[9888]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
[9889]20
21
[4520]22class WorldEntity;
23class BoundingVolume;
[4510]24
[9889]25namespace CoRe
[7968]26{
[9889]27
28  class CollisionEvent;
29
30  //! A class representing a simple collision
31  class Collision
32  {
[7968]33  public:
34    Collision();
35    virtual ~Collision();
[4510]36
[7968]37    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
[8490]38    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
[7934]39
40
[7968]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; }
[8106]45    /** @return true if Entity A collides */
[8108]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; }
[8106]49    /** @return true if Entity B collides */
[8108]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; }
[7940]53
[8490]54
[9891]55    inline bool match(const WorldEntity& entityA, WorldEntity& entityB) const { return (this->entityA == &entityA && this->entityB == &entityB); }
[8029]56    /** @returns true if this Collision has already been dispatched */
57    inline bool isDispatched() { return this->bDispatched; }
[8129]58    /** sets the dispatched flag to true */
59    inline void dispatched() { this->bDispatched = true; }
[8029]60
[7968]61    /** registers a @param event CollisionEvent to take place */
[8108]62    inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;}
[8006]63    /** @returns a vector of collision events */
64    inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; }
[7940]65
[8106]66
[7968]67    void flushCollisionEvents();
68
69
70  private:
71    WorldEntity*                 entityA;                       //!< the collision body A
72    WorldEntity*                 entityB;                       //!< the collision body B
[8106]73    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
74    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
[7968]75
[8029]76    bool                         bDispatched;                   //!< true if this collision has already been dispatched
77
[7968]78    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
[9889]79  };
80}
[4510]81
[4511]82#endif /* _COLLISION_H */
Note: See TracBrowser for help on using the repository browser.