Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10010 in orxonox.OLD for branches/coll_rect.merge/src


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

merged the temp branch

Location:
branches/coll_rect.merge/src
Files:
2 deleted
26 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/coll_rect.merge/src/lib/collision_detection/aabb_tree_node.cc

    r9869 r10010  
    1717#include "aabb_tree_node.h"
    1818#include "aabb.h"
    19 
    2019#include "bv_tree.h"
     20
     21#include "collision_tube.h"
    2122
    2223#include "matrix.h"
     
    532533        (treeNode->nodeRight == NULL && treeNode->nodeLeft == NULL)) )
    533534    {
    534       nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
     535      CoRe::CollisionTube::getInstance()->registerCollisionEvent( nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
    535536    }
    536537
  • branches/coll_rect.merge/src/lib/collision_detection/obb_tree_node.cc

    r9869 r10010  
    1818#include "obb_tree.h"
    1919#include "obb.h"
     20
     21#include "collision_tube.h"
    2022
    2123#include "matrix.h"
     
    477479    return;
    478480
     481  if( !CoRe::CollisionTube::getInstance()->isReactive( *nodeA, *nodeB) )
     482    return;
     483
    479484//   float distanceMax = this->bvElement->radius + ((OBBTreeNode*)treeNode)->bvElement->radius;
    480485//   float distance = fabs((nodeA->getAbsCoor() - nodeB->getAbsCoor()).len());
     
    566571        (treeNode->nodeRight == NULL && treeNode->nodeLeft == NULL)) )
    567572    {
    568 //       PRINTF(0)("----------------------------------------------\n\n\n\n\n\n--------------------------------\n\n\n");
    569       nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
     573      PRINTF(0)("----------------------------------------------\n\n\n\n\n\n--------------------------------\n\n\n");
     574      CoRe::CollisionTube::getInstance()->registerCollisionEvent( nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);
    570575    }
    571576
  • branches/coll_rect.merge/src/lib/collision_reaction/Makefile.am

    r9235 r10010  
    55
    66libORXcr_a_SOURCES = cr_engine.cc \
     7                     collision_tube.cc \
    78                     collision.cc \
    89                     collision_event.cc \
    9                      collision_handle.cc \
     10                     collision_filter.cc \
    1011                     collision_reaction.cc \
    1112                     cr_object_damage.cc \
     
    1617
    1718noinst_HEADERS =     cr_engine.h \
     19                     collision_tube.h \
    1820                     collision.h \
    1921                     collision_event.h \
    20                      collision_handle.h \
     22                     collision_filter.h \
    2123                     cr_defs.h \
    2224                     collision_reaction.h \
  • branches/coll_rect.merge/src/lib/collision_reaction/collision.cc

    r9869 r10010  
    1919#include "debug.h"
    2020
    21 /**
    22  *  standard constructor
    23  */
    24 Collision::Collision ()
     21namespace CoRe
    2522{
    26   this->flushCollisionEvents();
    27 }
     23
     24  /**
     25   *  standard constructor
     26   */
     27  Collision::Collision ()
     28  {
     29    this->reset();
     30  }
    2831
    2932
    30 /**
    31  *  standard deconstructor
    32  */
    33 Collision::~Collision ()
    34 {
    35 }
     33  /**
     34   *  standard deconstructor
     35   */
     36  Collision::~Collision ()
     37  {}
    3638
    3739
    38 /**
    39  * flushes the CollisionEvent list
    40  */
    41 void Collision::flushCollisionEvents()
    42 {
    43   this->entityA = NULL;
    44   this->entityB = NULL;
     40  /**
     41   * resets all variable states to initial values
     42   */
     43  void Collision::reset()
     44  {
     45    this->_entityA = NULL;
     46    this->_entityB = NULL;
    4547
    46   this->entityACollide = false;
    47   this->entityBCollide = false;
     48    this->_entityACollide = false;
     49    this->_entityBCollide = false;
    4850
    49   this->bDispatched = true;
     51    this->_collisionEvents.clear();
     52  }
    5053
    51   this->collisionEvents.clear();
    5254}
    53 
  • 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 */
  • branches/coll_rect.merge/src/lib/collision_reaction/collision_event.cc

    r9869 r10010  
    1919#include "debug.h"
    2020
    21 /**
    22  *  standard constructor
    23  */
    24 CollisionEvent::CollisionEvent ()
     21namespace CoRe
    2522{
    26   this->entityA = NULL;
    27   this->entityB = NULL;
    28   this->bvA = NULL;
    29   this->bvB = NULL;
     23
     24  /**
     25   *  standard constructor
     26   */
     27  CollisionEvent::CollisionEvent ()
     28  {
     29    this->entityA = NULL;
     30    this->entityB = NULL;
     31    this->bvA = NULL;
     32    this->bvB = NULL;
     33  }
     34
     35
     36  /**
     37   *  standard deconstructor
     38   */
     39  CollisionEvent::~CollisionEvent ()
     40  {}
     41
    3042}
    3143
    32 
    33 /**
    34  *  standard deconstructor
    35  */
    36 CollisionEvent::~CollisionEvent ()
    37 {
    38 }
    39 
    40 
    41 
  • branches/coll_rect.merge/src/lib/collision_reaction/collision_event.h

    r9869 r10010  
    22 * @file collision_event.h
    33 *  Definition of a collision event
     4 *
     5 *  A collision event represents a collision of two bouning boxes. Every CollisionEvent belongs to a Collision object that
     6 *  represents the collision of two WorldEntities.
     7 *
     8 *  There are different types of collisions: obb collisions and bsp collisions. Both collision types use different techniques
     9 *  to represent collisions. This is why this class saves bounding boxes from the OBB as well as the planes from BSP.
    410 */
    511
     
    814
    915#include "vector.h"
     16#include "cr_engine.h"
    1017
    1118#include "cr_defs.h"
     
    1623class Plane;
    1724
     25namespace CoRe
     26{
     27
     28  //! A class representing a simple collision
     29  class CollisionEvent
     30  {
     31  public:
     32    CollisionEvent();
     33    virtual ~CollisionEvent();
     34
     35    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
     36    inline void collide(CREngine::CollisionType type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
     37    { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
     38    /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
     39    inline void collide(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
     40    {
     41      this->collisionType = type;
     42      this->entityA = entity;
     43      this->entityB = groundEntity;
     44      this->groundNormal = normal;
     45      this->position = position;
     46      this->bInWall = bInWall;
     47    }
    1848
    1949
    20 //! A class representing a simple collision
    21 class CollisionEvent {
    22  public:
    23    CollisionEvent();
    24   virtual ~CollisionEvent();
     50    /** @return CollisionEvent WorldEntity A */
     51    inline const WorldEntity* getEntityA() const  { return this->entityA; }
     52    /** @return CollisionEvent WorldEntity B */
     53    inline const WorldEntity* getEntityB() const  { return this->entityB; }
     54    /** @return Bounding Volume from EntityA */
     55    inline const BoundingVolume* getBVA() const { return this->bvA; }
     56    /** @return Bounding Volume from EntityB */
     57    inline const BoundingVolume* getBVB() const {  return this->bvB;  }
    2558
    26   /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    27   inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    28   { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
    29   /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
    30   inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
    31   { this->collisionType = type; this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; this->bInWall = bInWall; }
     59    /** @return ground plane if collided with bsp model */
     60    inline const Vector& getGroundNormal() const  { return this->groundNormal; }
     61
     62    /** @return position of the position, only accurate if this is a collision with the ground!!! */
     63    inline const Vector& getCollisionPosition() const  {  return this->position;  }
     64
     65    /** @return the type of the collision */
     66    inline int getType() const  {  return this->collisionType;  }
     67
     68    /** @return true if the entity is in the wall */
     69    inline bool isInWall() const  {  return this->bInWall;  }
    3270
    3371
    34   /** @return CollisionEvent WorldEntity A */
    35   inline WorldEntity* getEntityA() const { return this->entityA; }
    36   /** @return CollisionEvent WorldEntity B */
    37   inline WorldEntity* getEntityB() const { return this->entityB; }
    38   /** @return Bounding Volume from EntityA */
    39   inline BoundingVolume* getBVA() const { return this->bvA; }
    40   /** @return Bounding Volume from EntityB */
    41   inline BoundingVolume* getBVB() const { return this->bvB; }
     72  private:
     73    WorldEntity*      entityA;                       //!< the collision body A
     74    WorldEntity*      entityB;                       //!< the collision body B
    4275
    43   /** @return ground plane if collided with bsp model */
    44   inline Vector getGroundNormal() { return this->groundNormal; }
     76    BoundingVolume*   bvA;                           //!< reference to the bounding volume A
     77    BoundingVolume*   bvB;                           //!< reference to the bounding volume B
    4578
    46   /** @return position of the position, only accurate if this is a collision with the ground!!! */
    47   inline Vector getCollisionPosition() { return this->position; }
     79    Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
     80    Vector            position;                      //!< position of the collision on the ground plane
    4881
    49   /** @return the type of the collision */
    50   inline int getType() { return this->collisionType; }
     82    bool              bInWall;                       //!< true if is in wall
     83    int               collisionType;                 //!< collision type
     84  };
    5185
    52   /** @return true if the entity is in the wall */
    53   inline bool isInWall() { return this->bInWall; }
    54 
    55 
    56  private:
    57   WorldEntity*      entityA;                       //!< the collision body A
    58   WorldEntity*      entityB;                       //!< the collision body B
    59 
    60   BoundingVolume*   bvA;                           //!< reference to the bounding volume A
    61   BoundingVolume*   bvB;                           //!< reference to the bounding volume B
    62 
    63   Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
    64   Vector            position;                      //!< position of the collision on the ground plane
    65 
    66   bool              bInWall;                       //!< true if is in wall
    67   int               collisionType;                 //!< collision type
    68 };
    69 
     86}
    7087#endif /* _COLLISION_EVENT_H */
  • branches/coll_rect.merge/src/lib/collision_reaction/collision_reaction.cc

    r9869 r10010  
    1111   ### File Specific:
    1212   main-programmer: Patrick Boenzli
    13    co-programmer: ...
    1413*/
    1514
     
    1817#include "collision_reaction.h"
    1918
     19namespace CoRe
     20{
     21
     22  ObjectListDefinition(CollisionReaction);
     23
     24  /**
     25   *  standard constructor
     26   */
     27  CollisionReaction::CollisionReaction ()
     28      : BaseObject()
     29  {
     30    this->registerObject(this, CollisionReaction::_objectList);
     31  }
    2032
    2133
    22 ObjectListDefinition(CollisionReaction);
     34  /**
     35   *  standard deconstructor
     36   */
     37  CollisionReaction::~CollisionReaction ()
     38  {}
    2339
    24 /**
    25  *  standard constructor
    26  */
    27 CollisionReaction::CollisionReaction ()
    28   : BaseObject()
    29 {
    30   this->registerObject(this, CollisionReaction::_objectList);
    3140}
    32 
    33 
    34 /**
    35  *  standard deconstructor
    36  */
    37 CollisionReaction::~CollisionReaction ()
    38 {
    39 }
    40 
  • branches/coll_rect.merge/src/lib/collision_reaction/collision_reaction.h

    r9869 r10010  
    99#include "base_object.h"
    1010
    11 
    12 
    13 class Collision;
    1411class WorldEntity;
    1512
     13namespace CoRe
     14{
    1615
    17 //! A class representing a simple collision
    18 class CollisionReaction : public BaseObject
    19 {
    20   ObjectListDeclaration(CollisionReaction);
     16  class Collision;
     17
     18  //! A class representing a simple collision
     19  class CollisionReaction : public BaseObject
     20  {
     21    ObjectListDeclaration(CollisionReaction);
    2122  public:
    2223    CollisionReaction();
     
    2526    virtual void reactToCollision(Collision* collision) = 0;
    2627
    27     virtual void update(WorldEntity* owner) {}
    28 
    2928    /** use this to do some collision offline calculations, only called for bContinuousPoll == true */
    3029    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
     
    3231  private:
    3332    bool                    bContinuousPoll;       //!< if true the collision rection function is also called, if there was no collision
    34 };
     33  };
    3534
     35}
    3636#endif /* _COLLISION_REACTION_H */
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_defs.h

    r9062 r10010  
    2828
    2929
    30 //!< the collision axis x collision event
    31 #define COLLISION_TYPE_AXIS_X      1
    32 #define COLLISION_TYPE_AXIS_X_NEG  2
    33 //!< the collision axis y collision event
    34 #define COLLISION_TYPE_AXIS_Y      3
    35 #define COLLISION_TYPE_AXIS_Y_NEG  4
    36 //!< the collision axis z collision event
    37 #define COLLISION_TYPE_AXIS_Z      5
    38 #define COLLISION_TYPE_AXIS_Z_NEG  6
    39 //!< the collision is a obb collision
    40 #define COLLISION_TYPE_OBB      8
    4130
    42 
    43 #endif /* _NETWORK_MANAGER */
     31#endif /* _CR_DEFS_H */
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_engine.cc

    r9869 r10010  
    1717
    1818
     19#include "cr_object_damage.h"
     20#include "cr_physics_full_walk.h"
     21#include "cr_physics_ground_walk.h"
    1922
    2023#include "collision.h"
    2124#include "collision_event.h"
    22 #include "collision_handle.h"
     25#include "collision_filter.h"
     26#include "collision_tube.h"
    2327#include "cr_defs.h"
    2428
     
    2731#include "debug.h"
    2832
    29 
    30 
    31 ObjectListDefinition(CREngine);
    32 /**
    33  * standard constructor
    34  */
    35 CREngine::CREngine ()
    36   : BaseObject()
     33namespace CoRe
    3734{
    38   this->registerObject(this, CREngine::_objectList);
    39    this->setName("CREngine");
    40 
    41    this->init();
     35
     36  ObjectListDefinition(CREngine);
     37
     38
     39  /**
     40   * standard constructor
     41   */
     42  CREngine::CREngine ()
     43      : BaseObject()
     44  {
     45    this->registerObject(this, CREngine::_objectList);
     46    this->setName("CREngine");
     47
     48    this->init();
     49  }
     50
     51  /**
     52   *  the singleton reference to this class
     53   */
     54  CREngine* CREngine::singletonRef = NULL;
     55
     56  /**
     57     @brief standard deconstructor
     58   */
     59  CREngine::~CREngine ()
     60  {
     61    CREngine::singletonRef = NULL;
     62
     63    if( this->collisionsUnused.size() != CR_MAX_COLLISIONS)
     64      PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS);
     65    if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS)
     66      PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);
     67
     68    this->reset();
     69
     70    CollisionIterator it1 = this->collisionsUnused.begin();
     71    for(; it1 < this->collisionsUnused.end(); it1++)
     72      delete *it1;
     73    CollisionEventIterator it2 = this->collisionEventsUnused.begin();
     74    for(; it2 < this->collisionEventsUnused.end(); it2++)
     75      delete *it2;
     76
     77    this->collisionsUnused.clear();
     78    this->collisionEventsUnused.clear();
     79  }
     80
     81
     82  /**
     83   * inits the CREngine to a working state
     84   */
     85  void CREngine::init()
     86  {
     87    // precaching:
     88    // create a list of Collisions and CollisionEvents for fast object recycling purposes
     89    for( int i = 0; i < CR_MAX_COLLISIONS; i++)
     90      this->collisionsUnused.push_back(new Collision());
     91    for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)
     92      this->collisionEventsUnused.push_back(new CollisionEvent());
     93
     94
     95    // push the collision reaction object on the list in the right order
     96
     97    // physical reactions
     98    this->_reactionList[CREngine::CR_PHYSICS_MOMENTUM]      = NULL;
     99    this->_reactionList[CREngine::CR_PHYSICS_STEP_BACK]     = NULL;
     100    this->_reactionList[CREngine::CR_PHYSICS_GROUND_WALK]   = new CRPhysicsGroundWalk();
     101    this->_reactionList[CREngine::CR_PHYSICS_FULL_WALK]     = new CRPhysicsFullWalk();
     102    this->_reactionList[CREngine::CR_PHYSICS_DAMAGE]        = NULL;
     103    // object based reactions
     104    this->_reactionList[CREngine::CR_OBJECT_DAMAGE]         = new CRObjectDamage();
     105    this->_reactionList[CREngine::CR_OBJECT_PICKUP]         = NULL;
     106    // misc reactions
     107    this->_reactionList[CREngine::CR_VERTEX_TRAFO]          = NULL;
     108    this->_reactionList[CREngine::CR_SPECIAL_CALLBACK]      = NULL;
     109  }
     110
     111
     112  /**
     113   * @returns an instance to a collision object. instead of creating new object this ones can be resycled
     114   */
     115  Collision* CREngine::popCollisionObject()
     116  {
     117    if( !this->collisionsUnused.empty())
     118    {
     119      this->collisionsUsed.push_back(this->collisionsUnused.back());
     120      this->collisionsUnused.pop_back();
     121      return this->collisionsUsed.back();
     122    }
     123    else
     124    {
     125      PRINTF(0)("There is no Collision Object left in the precache table, fatal error will cause segfault, change CR_MAX_COLLISIONS\n");
     126      assert(false);
     127      return NULL;
     128    }
     129  }
     130
     131
     132  /**
     133   * @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled
     134   */
     135  CollisionEvent* CREngine::popCollisionEventObject()
     136  {
     137    if( !this->collisionEventsUnused.empty())
     138    {
     139      this->collisionEventsUsed.push_back(this->collisionEventsUnused.back());
     140      this->collisionEventsUnused.pop_back();
     141      return this->collisionEventsUsed.back();
     142    }
     143    else
     144    {
     145      PRINTF(0)("There is no Collision Object left in the precache table, fatal error will cause segfault, change CR_MAX_COLLISION_EVENTS\n");
     146      assert(false);
     147      return NULL;
     148    }
     149  }
     150
     151
     152  /**
     153   * handles all collisions in registered in this tube
     154   */
     155  void CREngine::handleCollisions()
     156  {
     157    // for all collisions:
     158    CollisionIterator ci = CollisionTube::getInstance()->begin();
     159    for(; ci < CollisionTube::getInstance()->end(); ci++)
     160    {
     161      for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUMBER; i++)
     162      {
     163        if( _reactionList[i] == NULL)
     164          continue;
     165
     166        assert((*ci)->getEntityA() != NULL && (*ci)->getEntityB() != NULL);
     167
     168//         PRINTF(0)("CR CHECK: collision between: %s, %s\n", (*ci)->getEntityA()->getClassName().c_str(), (*ci)->getEntityB()->getClassName().c_str());
     169
     170        // check if entity A or B is subscibed for this event
     171        if( (*ci)->getEntityA()->isReactive(*(*ci)->getEntityB(), (CREngine::ReactionType)i) ||
     172            (*ci)->getEntityB()->isReactive(*(*ci)->getEntityA(), (CREngine::ReactionType)i))
     173        {
     174          this->_reactionList[i]->reactToCollision(*ci);
     175          PRINTF(0)("executing reaction: %s, between %s - %s\n", this->_reactionList[i]->getClassName().c_str(), (*ci)->getEntityA()->getClassName().c_str(), (*ci)->getEntityB()->getClassName().c_str());
     176        }
     177      }
     178      (*ci)->reset();
     179    }
     180
     181    this->reset();
     182  }
     183
     184
     185  /**
     186   * flushes all the collision lists and puts them to their initial state
     187   */
     188  void CREngine::reset()
     189  {
     190    CollisionIterator it1 = this->collisionsUsed.begin();
     191    for(; it1 < this->collisionsUsed.end(); it1++)
     192      this->collisionsUnused.push_back(*it1);
     193
     194    CollisionEventIterator it2 = this->collisionEventsUsed.begin();
     195    for(; it2 < this->collisionEventsUsed.end(); it2++)
     196      this->collisionEventsUnused.push_back(*it2);
     197
     198    this->collisionsUsed.clear();
     199    this->collisionEventsUsed.clear();
     200
     201    CollisionTube::getInstance()->reset();
     202  }
     203
     204
     205  void CREngine::debug()
     206  {
     207  }
     208
    42209}
    43 
    44 /**
    45  *  the singleton reference to this class
    46  */
    47 CREngine* CREngine::singletonRef = NULL;
    48 
    49 /**
    50    @brief standard deconstructor
    51  */
    52 CREngine::~CREngine ()
    53 {
    54   CREngine::singletonRef = NULL;
    55 
    56   if( this->collisionsUnused.size() != CR_MAX_COLLISIONS)
    57     PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS);
    58   if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS)
    59     PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);
    60 
    61   this->reset();
    62 
    63   std::vector<Collision*>::iterator it1 = this->collisionsUnused.begin();
    64   for(; it1 < this->collisionsUnused.end(); it1++)
    65     delete *it1;
    66   std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin();
    67   for(; it2 < this->collisionEventsUnused.end(); it2++)
    68     delete *it2;
    69 
    70   this->collisionsUnused.clear();
    71   this->collisionEventsUnused.clear();
    72 }
    73 
    74 /**
    75  * inits the CREngine to a working state
    76  */
    77 void CREngine::init()
    78 {
    79   // create a list of Collision events (precaching)
    80   for( int i = 0; i < CR_MAX_COLLISIONS; i++)
    81     this->collisionsUnused.push_back(new Collision());
    82   for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)
    83     this->collisionEventsUnused.push_back(new CollisionEvent());
    84 }
    85 
    86 
    87 /**
    88  * flushes the CollisionHandles and restores the CREngine to the initial state
    89  */
    90 void CREngine::reset()
    91 {
    92   // first clear all CollisionHandles
    93 
    94   std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();
    95   for(; it < this->collisionHandles.end(); it++)
    96   {
    97     (*it)->reset();
    98     delete *it;
    99   }
    100 
    101   this->collisionHandles.clear();
    102 }
    103 
    104 
    105 /**
    106  * subscribes a WorldEntity for a CollisionReaction
    107  *  @param owner: the WE to subscribe
    108  *  @param type: the type of collision reaction to perform
    109  *  @return the newly created CollisionHandle
    110  */
    111 CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type)
    112 {
    113   CollisionHandle* ch = new CollisionHandle(owner, type);
    114   this->collisionHandles.push_back(ch);
    115 
    116   return ch;
    117 }
    118 
    119 
    120 /**
    121  * unsubscribe reaction from the reaction list
    122  *  @param collisionHandle the CollisionHandle to remove
    123  *  @param returns true if worked collrectly
    124  */
    125 bool CREngine::unsubscribeReaction(CollisionHandle* collisionHandle)
    126 {
    127   std::vector<CollisionHandle*>::iterator it;
    128   for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)  {
    129     if( *it == collisionHandle) {
    130       this->collisionHandles.erase(it);
    131       delete collisionHandle;
    132       return true;
    133     }
    134   }
    135   return false;
    136 }
    137 
    138 
    139 /**
    140  * processes the collisions by calling the EventHandlers
    141  */
    142 void CREngine::handleCollisions()
    143 {
    144   std::vector<CollisionHandle*>::iterator it;
    145   for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
    146   {
    147     if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
    148     {
    149       (*it)->handleCollisions();
    150     }
    151   }
    152   this->flushCollisions();
    153 }
    154 
    155 
    156 /**
    157  * flushes all the collision lists and puts them to their initial state
    158  */
    159 void CREngine::flushCollisions()
    160 {
    161   std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin();
    162   for(; it1 < this->collisionsUsed.end(); it1++)
    163     this->collisionsUnused.push_back(*it1);
    164 
    165   std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();
    166   for(; it2 < this->collisionEventsUsed.end(); it2++)
    167     this->collisionEventsUnused.push_back(*it2);
    168 
    169   this->collisionsUsed.clear();
    170   this->collisionEventsUsed.clear();
    171 }
    172 
    173 
    174 void CREngine::debug()
    175 {
    176 
    177 }
    178 
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_engine.h

    r9869 r10010  
    1616#include <vector>
    1717
    18 // FORWARD DECLARATION
    19 class CollisionHandle;
    20 class Collision;
    21 class CollisionEvent;
    2218class WorldEntity;
    2319
    24 //! A default singleton class.
    25 class CREngine : public BaseObject
     20
     21namespace CoRe
    2622{
    27   ObjectListDeclaration(CREngine);
     23  class Collision;
     24  class CollisionEvent;
     25  class CollisionReaction;
     26
     27
     28  //! A default singleton class.
     29  class CREngine : public BaseObject
     30  {
     31    ObjectListDeclaration(CREngine);
     32
     33    typedef std::vector<CollisionEvent*>             CollisionEventVector;
     34    typedef std::vector<Collision*>                  CollisionVector;
     35    typedef std::vector<Collision*>::iterator        CollisionIterator;
     36    typedef std::vector<CollisionEvent*>::iterator   CollisionEventIterator;
     37
    2838
    2939  public:
    30   typedef enum CRType {
    31     CR_PHYSICS_MOMENTUM   = 0,    //!< physical reaction: conservervation of momentum
    32     CR_PHYSICS_STEP_BACK,         //!< physical reaction: just go to the last position without collisions
    33     CR_PHYSICS_GROUND_WALK,       //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
    34     CR_PHYSICS_FULL_WALK,         //!< physical reaction: walking on the ground (inkl. hills etc)
    35     CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
     40    typedef enum ReactionType {
     41      CR_PHYSICS_MOMENTUM   = 0,           //!< physical reaction: conservervation of momentum
     42      CR_PHYSICS_STEP_BACK,                //!< physical reaction: just go to the last position without collisions
     43      CR_PHYSICS_GROUND_WALK,              //!< physical reaction: stand on the ground, no movement: simple normal force away from the gravity force
     44      CR_PHYSICS_FULL_WALK,                //!< physical reaction: walking on the ground (inkl. hills etc)
     45      CR_PHYSICS_DAMAGE,                   //!< physical reaction: daling damage according to the object energy and their structural stability
    3646
    37     CR_OBJECT_DAMAGE,             //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)
    38     CR_OBJECT_PICKUP,             //!< object rection: calling the objects pickup functions, let them handle the collision (once!)
     47      CR_OBJECT_DAMAGE,                    //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)
     48      CR_OBJECT_PICKUP,                    //!< object rection: calling the objects pickup functions, let them handle the collision (once!)
    3949
    40     CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
     50      CR_VERTEX_TRAFO,                     //!< vertex trafo: transforming the vertex according to the damage
    4151
    42     CR_SPECIAL_CALLBACK,          //!< special: call a callback function
     52      CR_SPECIAL_CALLBACK,                 //!< special: call a callback function
    4353
    44     CR_NUMBER
     54      CR_NUMBER
     55    };
     56
     57    typedef enum CollisionType {
     58      CR_COLLISION_TYPE_AXIS_X       = 0,  //!< collision on x axis
     59      CR_COLLISION_TYPE_AXIS_X_NEG,        //!< collision on negative x axis
     60      CR_COLLISION_TYPE_AXIS_Y,            //!< collision on y axis
     61      CR_COLLISION_TYPE_AXIS_Y_NEG,        //!< collision on negative y axis
     62      CR_COLLISION_TYPE_AXIS_Z,            //!< collision on z axis
     63      CR_COLLISION_TYPE_AXIS_Z_NEG,        //!< collision on negative z axis
     64      CR_COLLISION_TYPE_OBB,               //!< object aligned bounding box collide
     65
     66      CR_COLLISION_TYPE_NUMBER
     67    };
     68
     69
     70    virtual ~CREngine(void);
     71
     72    /** @returns a Pointer to the only object of this Class */
     73    inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
     74
     75    Collision* popCollisionObject();
     76    CollisionEvent* popCollisionEventObject();
     77
     78    void handleCollisions();
     79
     80    void debug();
     81
     82
     83  private:
     84    CREngine();
     85    void init();
     86
     87    void reset();
     88
     89
     90  private:
     91    static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
     92
     93    CollisionVector                     collisionsUsed;           //!< a list of used, cached collisions
     94    CollisionVector                     collisionsUnused;         //!< a list of unused, cached collisions
     95
     96    CollisionEventVector                collisionEventsUsed;      //!< a list of used, cached collision events
     97    CollisionEventVector                collisionEventsUnused;    //!< a list of unused, cached collision events
     98
     99    CollisionReaction*                  _reactionList[CREngine::CR_NUMBER];  //!< the collision reaction list containing all reactions types
     100
     101
    45102  };
    46103
    47   virtual ~CREngine(void);
    48 
    49   /** @returns a Pointer to the only object of this Class */
    50   inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
    51 
    52   void reset();
    53 
    54 
    55   CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
    56 
    57   bool unsubscribeReaction(CollisionHandle* collisionHandle);
    58 
    59   void handleCollisions();
    60 
    61   /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
    62   inline Collision* popCollisionObject() {
    63     if( !this->collisionsUnused.empty()) {
    64       this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; }
    65 
    66 
    67   /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */
    68   inline CollisionEvent* popCollisionEventObject() {
    69     if( !this->collisionEventsUnused.empty()) {
    70       this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; }
    71 
    72   void debug();
    73 
    74 
    75 private:
    76   CREngine();
    77   void init();
    78 
    79   void flushCollisions();
    80 
    81 
    82 private:
    83   std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
    84 
    85   std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
    86   std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
    87 
    88   std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
    89   std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
    90 
    91   static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
    92 };
    93 
     104}
    94105#endif /* _CR_ENGINE_ */
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_object_damage.cc

    r9869 r10010  
    2626#include "debug.h"
    2727
     28namespace CoRe
     29{
     30
     31  ObjectListDefinition(CRObjectDamage);
     32  /**
     33   *  standard constructor
     34   */
     35  CRObjectDamage::CRObjectDamage ()
     36      : CollisionReaction()
     37  {
     38    this->registerObject(this, CRObjectDamage::_objectList);
     39  }
    2840
    2941
    30 ObjectListDefinition(CRObjectDamage);
    31 /**
    32  *  standard constructor
    33  */
    34 CRObjectDamage::CRObjectDamage ()
    35   : CollisionReaction()
    36 {
    37   this->registerObject(this, CRObjectDamage::_objectList);
    38 }
     42  /**
     43   *  standard deconstructor
     44   */
     45  CRObjectDamage::~CRObjectDamage ()
     46  {}
    3947
    4048
    41 /**
    42  *  standard deconstructor
    43  */
    44 CRObjectDamage::~CRObjectDamage ()
    45 {
    46 }
     49  /**
     50   * caluculates and applys the reaction to a specific collision
     51   *  @param collision the collision
     52   */
     53  void CRObjectDamage::reactToCollision(Collision* collision)
     54  {
     55    float damage = 0.0f;
    4756
     57    PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n",
     58              collision->getEntityA()->getClassCName(),
     59              collision->getEntityB()->getClassCName());
    4860
    49 /**
    50  * caluculates and applys the reaction to a specific collision
    51  *  @param collision the collision
    52  */
    53 void CRObjectDamage::reactToCollision(Collision* collision)
    54 {
    55   float damage = 0.0f;
     61    // the collision damage been dealed by the entity
     62    if( collision->isEntityACollide())
     63    {
     64      damage = collision->getEntityB()->getDamage();
     65      collision->getEntityA()->hit(damage, collision->getEntityB());
     66      PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassCName());
     67    }
    5668
    57   PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n",
    58             collision->getEntityA()->getClassCName(),
    59             collision->getEntityB()->getClassCName());
     69    if( collision->isEntityBCollide())
     70    {
     71      damage = collision->getEntityA()->getDamage();
     72      collision->getEntityB()->hit(damage, collision->getEntityA());
     73      PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassCName());
     74    }
    6075
    61   // the collision damage been dealed by the entity
    62   if( collision->isEntityACollide()) {
    63     damage = collision->getEntityB()->getDamage();
    64     collision->getEntityA()->hit(damage, collision->getEntityB());
    65     PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassCName());
     76    //   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     77    //   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     78    //   for(; it != collisionEvents->end(); it++)
     79    //   {
     80    //     // go through the collisions and try to estimate the damage
     81    //     mass = (*it)->getEntityA()->getMass();
     82    //   }
     83
    6684  }
    6785
    68   if( collision->isEntityBCollide()) {
    69     damage = collision->getEntityA()->getDamage();
    70     collision->getEntityB()->hit(damage, collision->getEntityA());
    71     PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassCName());
    72   }
    73 
    74   collision->flushCollisionEvents();
    75   collision->dispatched();
    76 
    77 //   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
    78 //   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
    79 //   for(; it != collisionEvents->end(); it++)
    80 //   {
    81 //     // go through the collisions and try to estimate the damage
    82 //     mass = (*it)->getEntityA()->getMass();
    83 //   }
    84 
    8586}
    86 
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_object_damage.h

    r9869 r10010  
    77#define _CR_OBJECT_DAMAGE_H
    88
     9
    910#include "collision_reaction.h"
    1011
    1112
    12 class Collision;
     13namespace CoRe
     14{
    1315
    14 //! A class representing a reaction to a collision: dealing damage to an object
    15 class CRObjectDamage : public CollisionReaction
    16 {
    17   ObjectListDeclaration(CRObjectDamage);
     16  class Collision;
     17
     18  //! A class representing a reaction to a collision: dealing damage to an object
     19  class CRObjectDamage : public CollisionReaction
     20  {
     21    ObjectListDeclaration(CRObjectDamage);
    1822  public:
    1923    CRObjectDamage();
     
    2226    virtual void reactToCollision(Collision* collision);
    2327
    24   private:
    25 
    26 };
     28  };
     29}
    2730
    2831#endif /* _CR_OBJECT_DAMAGE_H */
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_physics_full_walk.cc

    r9869 r10010  
    3333#include "cr_defs.h"
    3434
    35 
    36 
    37 ObjectListDefinition(CRPhysicsFullWalk);
    38 /**
    39  *  standard constructor
    40  */
    41 CRPhysicsFullWalk::CRPhysicsFullWalk ()
    42     : CollisionReaction()
     35namespace CoRe
    4336{
    44   this->registerObject(this, CRPhysicsFullWalk::_objectList);
     37
     38  ObjectListDefinition(CRPhysicsFullWalk);
     39  /**
     40   *  standard constructor
     41   */
     42  CRPhysicsFullWalk::CRPhysicsFullWalk ()
     43      : CollisionReaction()
     44  {
     45    this->registerObject(this, CRPhysicsFullWalk::_objectList);
     46  }
     47
     48
     49  /**
     50   *  standard deconstructor
     51   */
     52  CRPhysicsFullWalk::~CRPhysicsFullWalk ()
     53  {}
     54
     55
     56  /**
     57   * caluculates and applys the reaction to a specific collision
     58   *  @param collision the collision
     59   */
     60  void CRPhysicsFullWalk::reactToCollision(Collision* collision)
     61  {
     62
     63    AABB* box = collision->getEntityA()->getModelAABB();
     64    WorldEntity* entity = collision->getEntityA();
     65
     66    if( box == NULL)
     67    {
     68      PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");
     69      return;
     70    }
     71
     72
     73    float CR_MAX_WALK_HEIGHT = 15.0f;
     74//    float CR_THRESHOLD = 0.2f;
     75
     76    float height = 0.0f;
     77    float front = 0.0f;
     78    float back = 0.0f;
     79    float right = 0.0f;
     80    float left = 0.0f;
     81
     82
     83    std::vector<CollisionEvent*>::const_iterator it = collision->begin();
     84    for(; it != collision->end(); it++)
     85    {
     86
     87      CollisionEvent* ce = (*it);
     88      Vector normal = ce->getGroundNormal();
     89
     90      // calculate the collision position
     91      Vector collPos =  collision->getEntityA()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     92
     93      // test the 3 axis differently
     94      switch( ce->getType())
     95      {
     96          /* collision in the X-AXIS */
     97        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X:
     98          front = collPos.len() - box->halfLength[0];
     99
     100          // object is beneath the plane (ground)
     101          if( front <= 0.0f )
     102          {
     103            Vector dirX = entity->getAbsDirX();
     104            dirX.y = 0.0f;
     105            dirX.normalize();
     106            Vector backoff = dirX * front;
     107
     108            entity->shiftCoor(backoff);
     109          }
     110          else if( ce->isInWall())
     111          {
     112            // object is already in the wall
     113            entity->setAbsCoor(entity->getLastAbsCoor());
     114          }
     115          break;
     116
     117        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG:
     118          back = collPos.len() - box->halfLength[0];
     119
     120          // object is beneath the plane (ground)
     121          if( back <= 0.0f)
     122          {
     123            Vector dirX = entity->getAbsDirX();
     124            dirX.y = 0.0f;
     125            dirX.normalize();
     126            Vector backoff = dirX * back * -1.0f;
     127
     128            entity->shiftCoor(backoff);
     129          }
     130          else if( ce->isInWall())
     131          {
     132            // object is already in the wall
     133            entity->setAbsCoor(entity->getLastAbsCoor());
     134          }
     135          break;
     136
     137
     138          /* collision in the Y-AXIS */
     139        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG:
     140          // calulate the height above ground
     141          height = collPos.len() - box->halfLength[1];
     142
     143
     144          // object is beneath the plane (ground)
     145          //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
     146          if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
     147          {
     148            entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
     149            entity->setOnGround(true);
     150          }
     151          // object is already in the wall
     152          else if( ce->isInWall())
     153          {
     154            entity->setAbsCoor(entity->getLastAbsCoor());
     155            PRINTF(0)("ground collision: reset pos\n");
     156          }
     157          else
     158          {
     159            // entity is not on ground
     160            entity->setOnGround(false);
     161          }
     162          break;
     163
     164
     165          /* collision in the Z-AXIS */
     166        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z:
     167
     168          right = collPos.len()  - box->halfLength[2];
     169
     170          // object is beneath the plane (ground)
     171          if( right <= 0.0f )
     172          {
     173            Vector dirZ = entity->getAbsDirZ();
     174            dirZ.y = 0.0f;
     175            dirZ.normalize();
     176            Vector backoff = dirZ * right;
     177            entity->shiftCoor(backoff);
     178          }
     179          else if( ce->isInWall())
     180          {
     181            // object is already in the wall
     182            entity->setAbsCoor(entity->getLastAbsCoor());
     183          }
     184          break;
     185
     186
     187          // collision in the z-axis
     188        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG:
     189
     190          left = collPos.len()  - box->halfLength[2];
     191
     192          // object is beneath the plane (ground)
     193          if( left <= 0.0f )
     194          {
     195            Vector dirZ = entity->getAbsDirZ();
     196            dirZ.y = 0.0f;
     197            dirZ.normalize();
     198            Vector backoff = dirZ * left*-1.0f;
     199            entity->shiftCoor(backoff);
     200          }
     201          // object is already in the wall
     202          else if( ce->isInWall())
     203          {
     204            entity->setAbsCoor(entity->getLastAbsCoor());
     205          }
     206          break;
     207      }
     208    }
     209    //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
     210  }
     211
     212
     213
     214
    45215}
    46216
    47 
    48 /**
    49  *  standard deconstructor
    50  */
    51 CRPhysicsFullWalk::~CRPhysicsFullWalk ()
    52 {}
    53 
    54 
    55 /**
    56  * caluculates and applys the reaction to a specific collision
    57  *  @param collision the collision
    58  */
    59 void CRPhysicsFullWalk::reactToCollision(Collision* collision)
    60 {
    61 
    62   AABB* box = collision->getEntityB()->getModelAABB();
    63   WorldEntity* entity = collision->getEntityB();
    64 
    65   if( box == NULL)
    66   {
    67     PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");
    68     return;
    69   }
    70 
    71 
    72   float CR_MAX_WALK_HEIGHT = 15.0f;
    73   float CR_THRESHOLD = 0.2f;
    74 
    75   float height = 0.0f;
    76   float front = 0.0f;
    77   float back = 0.0f;
    78   float right = 0.0f;
    79   float left = 0.0f;
    80 
    81 
    82   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
    83   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
    84   for(; it != collisionEvents->end(); it++)
    85   {
    86 
    87     CollisionEvent* ce = (*it);
    88     Vector normal = ce->getGroundNormal();
    89 
    90     // calculate the collision position
    91     Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
    92 
    93     // test the 3 axis differently
    94     switch( ce->getType())
    95     {
    96         /* collision in the X-AXIS */
    97       case COLLISION_TYPE_AXIS_X:
    98         front = collPos.len() - box->halfLength[0];
    99 
    100         // object is beneath the plane (ground)
    101         if( front <= 0.0f )
    102         {
    103           Vector dirX = entity->getAbsDirX();
    104           dirX.y = 0.0f;
    105           dirX.normalize();
    106           Vector backoff = dirX * front;
    107 
    108           entity->shiftCoor(backoff);
    109         }
    110         else if( ce->isInWall())
    111         {
    112           // object is already in the wall
    113           entity->setAbsCoor(entity->getLastAbsCoor());
    114         }
    115         break;
    116 
    117       case COLLISION_TYPE_AXIS_X_NEG:
    118         back = collPos.len() - box->halfLength[0];
    119 
    120         // object is beneath the plane (ground)
    121         if( back <= 0.0f)
    122         {
    123           Vector dirX = entity->getAbsDirX();
    124           dirX.y = 0.0f;
    125           dirX.normalize();
    126           Vector backoff = dirX * back * -1.0f;
    127 
    128           entity->shiftCoor(backoff);
    129         }
    130         else if( ce->isInWall())
    131         {
    132           // object is already in the wall
    133           entity->setAbsCoor(entity->getLastAbsCoor());
    134         }
    135         break;
    136 
    137 
    138         /* collision in the Y-AXIS */
    139       case COLLISION_TYPE_AXIS_Y_NEG:
    140         // calulate the height above ground
    141         height = collPos.len() - box->halfLength[1];
    142 
    143 
    144         // object is beneath the plane (ground)
    145         //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
    146         if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
    147         {
    148           entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
    149           entity->setOnGround(true);
    150         }
    151         // object is already in the wall
    152         else if( ce->isInWall())
    153         {
    154           entity->setAbsCoor(entity->getLastAbsCoor());
    155           PRINTF(0)("ground collision: reset pos\n");
    156         }
    157         else
    158         {
    159           // entity is not on ground
    160           entity->setOnGround(false);
    161         }
    162         break;
    163 
    164 
    165         /* collision in the Z-AXIS */
    166       case COLLISION_TYPE_AXIS_Z:
    167 
    168         right = collPos.len()  - box->halfLength[2];
    169 
    170         // object is beneath the plane (ground)
    171         if( right <= 0.0f )
    172         {
    173           Vector dirZ = entity->getAbsDirZ();
    174           dirZ.y = 0.0f;
    175           dirZ.normalize();
    176           Vector backoff = dirZ * right;
    177           entity->shiftCoor(backoff);
    178         }
    179         else if( ce->isInWall())
    180         {
    181           // object is already in the wall
    182           entity->setAbsCoor(entity->getLastAbsCoor());
    183         }
    184         break;
    185 
    186 
    187         // collision in the z-axis
    188       case COLLISION_TYPE_AXIS_Z_NEG:
    189 
    190         left = collPos.len()  - box->halfLength[2];
    191 
    192         // object is beneath the plane (ground)
    193         if( left <= 0.0f )
    194         {
    195           Vector dirZ = entity->getAbsDirZ();
    196           dirZ.y = 0.0f;
    197           dirZ.normalize();
    198           Vector backoff = dirZ * left*-1.0f;
    199           entity->shiftCoor(backoff);
    200         }
    201         // object is already in the wall
    202         else if( ce->isInWall())
    203         {
    204           entity->setAbsCoor(entity->getLastAbsCoor());
    205         }
    206         break;
    207     }
    208   }
    209   //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
    210 
    211 
    212 
    213 
    214 
    215 
    216 
    217 }
    218 
    219 
    220 
    221 
    222 /**
    223  * use this to do some collision offline calculations, only called for bContinuousPoll == true
    224  */
    225 void CRPhysicsFullWalk::update(WorldEntity* owner)
    226 {}
    227 
    228 
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_physics_full_walk.h

    r9869 r10010  
    99#include "collision_reaction.h"
    1010
     11namespace CoRe
     12{
    1113
    12 class Collision;
     14  class Collision;
    1315
    14 //! A class representing a reaction to a collision: dealing damage to an object
    15 class CRPhysicsFullWalk : public CollisionReaction
    16 {
    17   ObjectListDeclaration(CRPhysicsFullWalk);
     16  //! A class representing a reaction to a collision: dealing damage to an object
     17  class CRPhysicsFullWalk : public CollisionReaction
     18  {
     19    ObjectListDeclaration(CRPhysicsFullWalk);
    1820  public:
    1921    CRPhysicsFullWalk();
     
    2123
    2224    virtual void reactToCollision(Collision* collision);
    23 
    24     virtual void update(WorldEntity* entity);
    25 
    26 
    27   private:
    28     float        downspeed;
    29 };
    30 
     25  };
     26}
    3127#endif /* _CR_PHYSICS_FULL_WALK_H */
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r9869 r10010  
    3434
    3535
     36namespace CoRe
     37{
    3638
    37 ObjectListDefinition(CRPhysicsGroundWalk);
    38 /**
    39  *  standard constructor
    40  */
    41 CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
    42     : CollisionReaction()
    43 {
    44   this->registerObject(this, CRPhysicsGroundWalk::_objectList);
    45 }
     39  ObjectListDefinition(CRPhysicsGroundWalk);
    4640
    4741
    48 /**
    49  *  standard deconstructor
    50  */
    51 CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
    52 {}
    53 
    54 
    55 /**
    56  * caluculates and applys the reaction to a specific collision
    57  *  @param collision the collision
    58  */
    59 void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
    60 {
    61 
    62   AABB* box = collision->getEntityB()->getModelAABB();
    63   WorldEntity* entity = collision->getEntityB();
    64 
    65   if( box == NULL)
     42  /**
     43   *  standard constructor
     44   */
     45  CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
     46      : CollisionReaction()
    6647  {
    67     PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");
    68     return;
     48    this->registerObject(this, CRPhysicsGroundWalk::_objectList);
    6949  }
    7050
    7151
    72   float CR_MAX_WALK_HEIGHT = 15.0f;
    73 
    74   float height = 0.0f;
     52  /**
     53   *  standard deconstructor
     54   */
     55  CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
     56  {}
    7557
    7658
    77   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
    78   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
    79   for(; it != collisionEvents->end(); it++)
     59  /**
     60   * caluculates and applys the reaction to a specific collision
     61   *  @param collision the collision
     62   */
     63  void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
    8064  {
    8165
    82     CollisionEvent* ce = (*it);
    83     Vector normal = ce->getGroundNormal();
     66    AABB* box = collision->getEntityA()->getModelAABB();
     67    WorldEntity* entity = collision->getEntityA();
    8468
    85     // calculate the collision position
    86     Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
    87 
    88     // test the 3 axis differently
    89     switch( ce->getType())
     69    if( box == NULL)
    9070    {
    91         /* collision in the Y-AXIS */
    92       case COLLISION_TYPE_AXIS_Y_NEG:
    93         // calulate the height above ground
    94         height = collPos.len() - box->halfLength[1];
     71      PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");
     72      return;
     73    }
    9574
    9675
    97         // object is beneath the plane (ground)
    98         //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
    99         if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
    100         {
    101           entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
    102           entity->setOnGround(true);
    103         }
    104         // object is already in the wall
    105         else if( ce->isInWall())
    106         {
    107           entity->setAbsCoor(entity->getLastAbsCoor());
    108         }
    109         else
    110         {
    111           // entity is not on ground
    112           entity->setOnGround(false);
    113         }
    114         break;
     76    float CR_MAX_WALK_HEIGHT = 15.0f;
     77
     78    float height = 0.0f;
    11579
    11680
     81    std::vector<CollisionEvent*>::const_iterator it = collision->begin();
     82    for(; it != collision->end(); it++)
     83    {
     84
     85      CollisionEvent* ce = (*it);
     86      Vector normal = ce->getGroundNormal();
     87
     88      // calculate the collision position
     89      Vector collPos =  collision->getEntityA()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     90
     91      // test the 3 axis differently
     92      switch( ce->getType())
     93      {
     94          /* collision in the Y-AXIS */
     95        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG:
     96          // calulate the height above ground
     97          height = collPos.len() - box->halfLength[1];
     98
     99
     100          // object is beneath the plane (ground)
     101          //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
     102          if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
     103          {
     104            entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
     105            entity->setOnGround(true);
     106          }
     107          // object is already in the wall
     108          else if( ce->isInWall())
     109          {
     110            entity->setAbsCoor(entity->getLastAbsCoor());
     111          }
     112          else
     113          {
     114            // entity is not on ground
     115            entity->setOnGround(false);
     116          }
     117          break;
     118
     119
     120      }
    117121    }
     122    //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
     123
    118124  }
    119   //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
    120 
    121 }
    122125
    123126
    124127
    125 
    126 /**
    127  * use this to do some collision offline calculations, only called for bContinuousPoll == true
    128  */
    129 void CRPhysicsGroundWalk::update(WorldEntity* owner)
    130 {}
    131 
    132 
     128}
  • branches/coll_rect.merge/src/lib/collision_reaction/cr_physics_ground_walk.h

    r9869 r10010  
    99#include "collision_reaction.h"
    1010
     11namespace CoRe
     12{
    1113
    12 class Collision;
     14  class Collision;
    1315
    14 //! A class representing a reaction to a collision: dealing damage to an object
    15 class CRPhysicsGroundWalk : public CollisionReaction
    16 {
    17   ObjectListDeclaration(CRPhysicsGroundWalk);
     16  //! A class representing a reaction to a collision: dealing damage to an object
     17  class CRPhysicsGroundWalk : public CollisionReaction
     18  {
     19    ObjectListDeclaration(CRPhysicsGroundWalk);
    1820  public:
    1921    CRPhysicsGroundWalk();
     
    2224    virtual void reactToCollision(Collision* collision);
    2325
    24     virtual void update(WorldEntity* entity);
     26  };
    2527
    26 
    27   private:
    28     float        downspeed;
    29 };
    30 
     28}
    3129#endif /* _CR_PHYSICS_GROUND_WALK_H */
  • branches/coll_rect.merge/src/lib/graphics/importer/bsp_manager.cc

    r9869 r10010  
    4646
    4747#include "aabb.h"
    48 #include "cr_defs.h"
     48#include "cr_engine.h"
     49#include "collision_tube.h"
    4950
    5051
     
    12151216  if( xCollisionForward)
    12161217  {
    1217     entity->registerCollision(COLLISION_TYPE_AXIS_X ,
    1218                               this->parent, entity,
     1218    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X ,
     1219                              entity, this->parent,
    12191220                              Vector(testPlane->x, testPlane->y, testPlane->z),
    12201221                              collPos,
     
    12541255  if( xCollisionBackward)
    12551256  {
    1256     entity->registerCollision(COLLISION_TYPE_AXIS_X_NEG ,
    1257                               this->parent, entity,
     1257    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG,
     1258                              entity, this->parent,
    12581259                              Vector(testPlane->x, testPlane->y, testPlane->z),
    12591260                              collPos,
     
    13501351  if( yCollisionUp)
    13511352  {
    1352     entity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent,
    1353                               entity,
     1353    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y,
     1354                              entity, this->parent,
    13541355                              Vector(testPlane->x, testPlane->y, testPlane->z),
    13551356                              collPos, SolidFlag);
     
    14031404  if( yCollisionDown)
    14041405  {
    1405     entity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent,
    1406                               entity,
     1406    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG ,
     1407                              entity, this->parent,
    14071408                              Vector(testPlane->x, testPlane->y, testPlane->z),
    14081409                              collPos, SolidFlag);
    14091410  }
    1410 
    1411 
    14121411}
    14131412
     
    14841483
    14851484  if( zCollisionRight) {
    1486     entity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent,
    1487                               entity,
     1485    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z ,
     1486                              entity, this->parent,
    14881487                              Vector(testPlane->x, testPlane->y, testPlane->z),
    14891488                              collPos , SolidFlag);
     
    15231522
    15241523  if( zCollisionLeft) {
    1525     entity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent,
    1526                               entity,
    1527                               Vector(testPlane->x, testPlane->y, testPlane->z),
    1528                               collPos , SolidFlag);
     1524    CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG ,
     1525                               entity, this->parent,
     1526                               Vector(testPlane->x, testPlane->y, testPlane->z),
     1527                               collPos , SolidFlag);
    15291528  }
    15301529
  • branches/coll_rect.merge/src/story_entities/game_world.cc

    r9869 r10010  
    136136  AnimationPlayer::getInstance();
    137137  PhysicsEngine::getInstance();
    138   CREngine::getInstance();
     138  CoRe::CREngine::getInstance();
    139139
    140140  State::setScriptManager(&this->scriptManager);
     
    219219  delete AnimationPlayer::getInstance();
    220220  delete PhysicsEngine::getInstance();
    221   delete CREngine::getInstance();
     221  delete CoRe::CREngine::getInstance();
    222222
    223223  State::setCurrentStoryEntity(NULL);
     
    494494void GameWorld::collisionReaction()
    495495{
    496   CREngine::getInstance()->handleCollisions();
     496  CoRe::CREngine::getInstance()->handleCollisions();
    497497}
    498498
  • branches/coll_rect.merge/src/story_entities/game_world_data.cc

    r9869 r10010  
    232232  State::setPlayer(this->localPlayer);
    233233
    234   Playable* playable;
    235234  if (!Playable::objectList().empty())
    236235  {
  • branches/coll_rect.merge/src/world_entities/creatures/fps_player.cc

    r9869 r10010  
    167167
    168168    //subscribe to collision reaction
    169   this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());
     169  this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());
    170170
    171171  this->initWeapon = false;
  • branches/coll_rect.merge/src/world_entities/npcs/generic_npc.cc

    r9869 r10010  
    9696
    9797  // collision reaction registration
    98   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID());
     98  this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID());
    9999}
    100100
  • branches/coll_rect.merge/src/world_entities/weapons/aiming_system.cc

    r9869 r10010  
    6161
    6262  // registering default reactions:
    63   this->unsubscribeReaction(CREngine::CR_OBJECT_DAMAGE);
    64   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());
     63  this->unsubscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE);
     64  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());
    6565
    6666  this->range = 1000.0f;
  • branches/coll_rect.merge/src/world_entities/world_entity.cc

    r9869 r10010  
    3535#include "camera.h"
    3636
    37 #include "collision_handle.h"
     37#include "collision_filter.h"
    3838#include "collision_event.h"
    3939#include "game_rules.h"
     
    5858 */
    5959WorldEntity::WorldEntity()
    60     : Synchronizeable()
     60  : Synchronizeable(), _collisionFilter(this)
    6161{
    6262  this->registerObject(this, WorldEntity::_objectList);
     
    7777  this->lastObjectListNumber = OM_INIT;
    7878
    79   // reset all collision handles to NULL == unsubscribed state
    80   for(int i = 0; i < CREngine::CR_NUMBER; ++i)
    81     this->collisionHandles[i] = NULL;
    82   this->bReactive = false;
    83   this->bOnGround = false;
     79  this->_bOnGround = false;
    8480
    8581  // registering default reactions:
    86   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID());
     82  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID());
    8783
    8884  this->toList(OM_NULL);
    8985
    90   registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
    91   modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
    92   scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
    93   list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
    94 
    95   health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
    96   healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
     86  this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
     87  this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
     88  this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
     89  this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
     90
     91  this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
     92  this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
    9793}
    9894
     
    115111    delete this->healthWidget;
    116112
    117   this->unsubscribeReaction();
     113  this->unsubscribeReactions();
    118114}
    119115
     
    302298 *  @param target1 a filter target (classID)
    303299 */
    304 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1)
    305 {
    306   this->subscribeReaction(type);
    307 
    308   // add the target filter
    309   this->collisionHandles[type]->addTarget(target1);
     300void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
     301{
     302  this->_collisionFilter.subscribeReaction(type, target1);
    310303}
    311304
     
    316309 *  @param target1 a filter target (classID)
    317310 */
    318 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2)
    319 {
    320   this->subscribeReaction(type);
    321 
    322   // add the target filter
    323   this->collisionHandles[type]->addTarget(target1);
    324   this->collisionHandles[type]->addTarget(target2);
     311void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
     312{
     313  this->_collisionFilter.subscribeReaction(type, target1, target2);
    325314}
    326315
     
    331320 *  @param target1 a filter target (classID)
    332321 */
    333 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
    334 {
    335   this->subscribeReaction(type);
    336 
    337   // add the target filter
    338   this->collisionHandles[type]->addTarget(target1);
    339   this->collisionHandles[type]->addTarget(target2);
    340   this->collisionHandles[type]->addTarget(target3);
    341 }
    342 
    343 
    344 /**
    345  * subscribes this world entity to a collision reaction
    346  *  @param type the type of reaction to subscribe to
    347  *  @param target1 a filter target (classID)
    348  */
    349 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4)
    350 {
    351   this->subscribeReaction(type);
    352 
    353   // add the target filter
    354   this->collisionHandles[type]->addTarget(target1);
    355   this->collisionHandles[type]->addTarget(target2);
    356   this->collisionHandles[type]->addTarget(target3);
    357   this->collisionHandles[type]->addTarget(target4);
    358 }
    359 
    360 
    361 /**
    362  * subscribes this world entity to a collision reaction
    363  *  @param type the type of reaction to subscribe to
    364  *  @param nrOfTargets number of target filters
    365  *  @param ... the targets as classIDs
    366  */
    367 void WorldEntity::subscribeReaction(CREngine::CRType type)
    368 {
    369   if( this->collisionHandles[type] != NULL)
    370   {
    371     PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
    372     return;
    373   }
    374 
    375   this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
    376 
    377   // now there is at least one collision reaction subscribed
    378   this->bReactive = true;
     322void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
     323{
     324  this->_collisionFilter.subscribeReaction(type, target1, target2, target3);
    379325}
    380326
     
    384330 *  @param type the reaction to unsubscribe
    385331 */
    386 void WorldEntity::unsubscribeReaction(CREngine::CRType type)
    387 {
    388   if( this->collisionHandles[type] == NULL)
    389     return;
    390 
    391   CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
    392   this->collisionHandles[type] = NULL;
    393 
    394   // check if there is still any handler registered
    395   for(int i = 0; i < CREngine::CR_NUMBER; ++i)
    396   {
    397     if( this->collisionHandles[i] != NULL)
    398     {
    399       this->bReactive = true;
    400       return;
    401     }
    402   }
    403   this->bReactive = false;
     332void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
     333{
     334  this->_collisionFilter.unsubscribeReaction(type);
    404335}
    405336
     
    408339 * unsubscribes all collision reactions
    409340 */
    410 void WorldEntity::unsubscribeReaction()
    411 {
    412   for( int i = 0; i < CREngine::CR_NUMBER; i++)
    413     this->unsubscribeReaction((CREngine::CRType)i);
    414 
    415   // there are no reactions subscribed from now on
    416   this->bReactive = false;
    417 }
    418 
    419 
    420 /**
    421  * registers a new collision event to this world entity
    422  *  @param entityA entity of the collision
    423  *  @param entityB entity of the collision
    424  *  @param bvA colliding bounding volume of entityA
    425  *  @param bvB colliding bounding volume of entityA
    426  */
    427 bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    428 {
    429   PRINTF(5)("registering collision of type: %s vs %s\n", entityA->getClassCName(), entityB->getClassCName());
    430   // is there any handler listening?
    431   if( !this->bReactive)
    432     return false;
    433 
    434   // get a collision event
    435   CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
    436   assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    437   c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
    438 
    439   for( int i = 0; i < CREngine::CR_NUMBER; ++i)
    440     if( this->collisionHandles[i] != NULL)
    441       this->collisionHandles[i]->registerCollisionEvent(c);
    442   return true;
    443 }
    444 
    445 
    446 /**
    447  * registers a new collision event to this woeld entity
    448  *  @param entity the entity that collides
    449  *  @param plane it stands on
    450  *  @param position it collides on the plane
    451  */
    452 bool WorldEntity::registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
    453 {
    454   // is there any handler listening?
    455   if( !this->bReactive)
    456     return false;
    457 
    458   // get a collision event
    459   CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
    460   assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    461   c->collide(type, entity, groundEntity, normal, position, bInWall);
    462 
    463   for( int i = 0; i < CREngine::CR_NUMBER; ++i)
    464     if( this->collisionHandles[i] != NULL)
    465       this->collisionHandles[i]->registerCollisionEvent(c);
    466   return true;
     341void WorldEntity::unsubscribeReactions()
     342{
     343  this->_collisionFilter.unsubscribeReactions();
    467344}
    468345
  • branches/coll_rect.merge/src/world_entities/world_entity.h

    r9869 r10010  
    1212
    1313#include "cr_engine.h"
     14#include "collision_filter.h"
    1415#include "object_manager.h"
    1516#include "glincl.h"
     
    2526namespace OrxSound { class SoundBuffer; class SoundSource; }
    2627namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; };
     28namespace CoRe { class Collision; }
    2729
    2830class BVTree;
     
    3032class AABBTreeNode;
    3133class Model;
    32 class CollisionHandle;
    33 class Collision;
    34 
    35 
    36 //class CharacterAttributes;
    37 
    3834
    3935
     
    4238{
    4339  ObjectListDeclaration(WorldEntity);
     40
    4441public:
    4542  WorldEntity();
     
    5148  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
    5249  void setModel(Model* model, unsigned int modelNumber = 0);
    53 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
     50  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    5451
    5552  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
     
    7471  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
    7572
    76 
    7773  /** @returns a reference to the obb tree of this worldentity */
    7874  inline BVTree* getOBBTree() const { return this->obbTree; };
     
    8177  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
    8278
     79  virtual void hit(float damage, WorldEntity* killer);
     80
     81
    8382  /* --- Collision Reaction Block --- */
    84   void subscribeReaction(CREngine::CRType type);
    85   void subscribeReaction(CREngine::CRType type, const ClassID& target1);
    86   void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2);
    87   void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
    88   void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4);
    89 
    90   void unsubscribeReaction(CREngine::CRType type);
    91   void unsubscribeReaction();
    92 
    93   bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
    94   bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false);
     83  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
     84  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
     85  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
     86
     87  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
     88  void unsubscribeReactions();
     89
    9590  /** @return true if there is at least on collision reaction subscribed */
    96   inline bool isReactive() const { return this->bReactive; }
    97 
    98   CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
     91  inline bool isReactive() const { return this->_collisionFilter.isReactive(); }
     92
     93  /** @param worldEntity the world entity to be checked @returns true if there is a collisionreaction registered for the worldEntity */
     94  inline bool isReactive( const WorldEntity& worldEntity) const { return this->_collisionFilter(worldEntity); }
     95  /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */
     96  inline bool isReactive( const WorldEntity& worldEntity, const CoRe::CREngine::ReactionType& type) const
     97  { return this->_collisionFilter(worldEntity, type); }
     98
     99
     100  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; }
    99101
    100102  /** @returns true if this entity is standing on ground (BSP model) */
    101   bool isOnGround() const { return this->bOnGround; }
     103  bool isOnGround() const { return this->_bOnGround; }
    102104  /** @param flag: marks if this entity is standing on ground */
    103   void setOnGround(bool flag) { this->bOnGround = flag; }
    104 
    105   virtual void hit(float damage, WorldEntity* killer);
     105  void setOnGround(bool flag) { this->_bOnGround = flag; }
    106106
    107107  virtual void destroy( WorldEntity* killer );
     
    128128
    129129  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
    130 void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
     130  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
    131131
    132132
    133133  /* --- Character Attribute Block --- */
    134134  /** @returns the scaling of the model */
    135 float getScaling(){return this->scaling;}
     135  float getScaling(){return this->scaling;}
    136136  /** @returns the damage dealt by this world entity */
    137137  float getDamage() const { return this->damage; }
     
    170170  void setHealthMax(float healthMax);
    171171  void createHealthWidget();
    172 
    173   //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     172    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     173
     174
    174175private:
    175176  void updateHealthWidget();
     177
    176178
    177179private:
     
    195197  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
    196198
    197 
    198 
     199  /* collision reaction stuff */
     200  CoRe::CollisionFilter   _collisionFilter;                //!< filter for collision event filtering (not every entity listens to all collisions)
     201  bool                    _bOnGround;                      //!< flag true if the object is on the ground
     202
     203  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
     204
     205  /* network help structures */
    199206  float                   scaling;                         //!< model's scaling factor
    200207  int                     scaling_handle;                  //!< handle for syncing var
     
    212219  int                     healthMax_handle;
    213220
    214   CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
    215   bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
    216 
    217   PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
    218   bool                    bOnGround;                       //!< true if this entity is standing on the ground
     221
    219222
    220223protected:
Note: See TracChangeset for help on using the changeset viewer.