Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9889 in orxonox.OLD


Ignore:
Timestamp:
Oct 13, 2006, 3:57:44 PM (18 years ago)
Author:
patrick
Message:

added namspacing to collision reaction. now comes the harder part :D

Location:
branches/coll_rect/src
Files:
23 edited

Legend:

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

    r9869 r9889  
    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->flushCollisionEvents();
     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   * flushes the CollisionEvent list
     42   */
     43  void Collision::flushCollisionEvents()
     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->bDispatched = true;
    5052
    51   this->collisionEvents.clear();
     53    this->collisionEvents.clear();
     54  }
     55
    5256}
    53 
  • branches/coll_rect/src/lib/collision_reaction/collision.h

    r9888 r9889  
    1818#include <vector>
    1919
     20
     21
    2022class WorldEntity;
    2123class BoundingVolume;
    22 class CollisionEvent;
    2324
    24 //! A class representing a simple collision
    25 class Collision
     25namespace CoRe
    2626{
     27
     28  class CollisionEvent;
     29
     30  //! A class representing a simple collision
     31  class Collision
     32  {
    2733  public:
    2834    Collision();
     
    7076
    7177    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
    72 };
     78  };
     79}
    7380
    7481#endif /* _COLLISION_H */
  • branches/coll_rect/src/lib/collision_reaction/collision_event.cc

    r9869 r9889  
    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/src/lib/collision_reaction/collision_event.h

    r9888 r9889  
    2222class Plane;
    2323
     24namespace CoRe
     25{
     26
     27  //! A class representing a simple collision
     28  class CollisionEvent
     29  {
     30  public:
     31    CollisionEvent();
     32    virtual ~CollisionEvent();
     33
     34    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
     35    inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
     36    { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
     37    /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
     38    inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
     39    {
     40      this->collisionType = type;
     41      this->entityA = entity;
     42      this->entityB = groundEntity;
     43      this->groundNormal = normal;
     44      this->position = position;
     45      this->bInWall = bInWall;
     46    }
    2447
    2548
    26 //! A class representing a simple collision
    27 class CollisionEvent {
    28  public:
    29    CollisionEvent();
    30   virtual ~CollisionEvent();
     49    /** @return CollisionEvent WorldEntity A */
     50    inline WorldEntity* getEntityA() const
     51    {
     52      return this->entityA;
     53    }
     54    /** @return CollisionEvent WorldEntity B */
     55    inline WorldEntity* getEntityB() const
     56    {
     57      return this->entityB;
     58    }
     59    /** @return Bounding Volume from EntityA */
     60    inline BoundingVolume* getBVA() const
     61    {
     62      return this->bvA;
     63    }
     64    /** @return Bounding Volume from EntityB */
     65    inline BoundingVolume* getBVB() const
     66    {
     67      return this->bvB;
     68    }
    3169
    32   /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    33   inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    34   { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
    35   /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
    36   inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
    37   { this->collisionType = type; this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; this->bInWall = bInWall; }
     70    /** @return ground plane if collided with bsp model */
     71    inline Vector getGroundNormal()
     72    {
     73      return this->groundNormal;
     74    }
     75
     76    /** @return position of the position, only accurate if this is a collision with the ground!!! */
     77    inline Vector getCollisionPosition()
     78    {
     79      return this->position;
     80    }
     81
     82    /** @return the type of the collision */
     83    inline int getType()
     84    {
     85      return this->collisionType;
     86    }
     87
     88    /** @return true if the entity is in the wall */
     89    inline bool isInWall()
     90    {
     91      return this->bInWall;
     92    }
    3893
    3994
    40   /** @return CollisionEvent WorldEntity A */
    41   inline WorldEntity* getEntityA() const { return this->entityA; }
    42   /** @return CollisionEvent WorldEntity B */
    43   inline WorldEntity* getEntityB() const { return this->entityB; }
    44   /** @return Bounding Volume from EntityA */
    45   inline BoundingVolume* getBVA() const { return this->bvA; }
    46   /** @return Bounding Volume from EntityB */
    47   inline BoundingVolume* getBVB() const { return this->bvB; }
     95  private:
     96    WorldEntity*      entityA;                       //!< the collision body A
     97    WorldEntity*      entityB;                       //!< the collision body B
    4898
    49   /** @return ground plane if collided with bsp model */
    50   inline Vector getGroundNormal() { return this->groundNormal; }
     99    BoundingVolume*   bvA;                           //!< reference to the bounding volume A
     100    BoundingVolume*   bvB;                           //!< reference to the bounding volume B
    51101
    52   /** @return position of the position, only accurate if this is a collision with the ground!!! */
    53   inline Vector getCollisionPosition() { return this->position; }
     102    Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
     103    Vector            position;                      //!< position of the collision on the ground plane
    54104
    55   /** @return the type of the collision */
    56   inline int getType() { return this->collisionType; }
     105    bool              bInWall;                       //!< true if is in wall
     106    int               collisionType;                 //!< collision type
     107  };
    57108
    58   /** @return true if the entity is in the wall */
    59   inline bool isInWall() { return this->bInWall; }
    60 
    61 
    62  private:
    63   WorldEntity*      entityA;                       //!< the collision body A
    64   WorldEntity*      entityB;                       //!< the collision body B
    65 
    66   BoundingVolume*   bvA;                           //!< reference to the bounding volume A
    67   BoundingVolume*   bvB;                           //!< reference to the bounding volume B
    68 
    69   Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
    70   Vector            position;                      //!< position of the collision on the ground plane
    71 
    72   bool              bInWall;                       //!< true if is in wall
    73   int               collisionType;                 //!< collision type
    74 };
    75 
     109}
    76110#endif /* _COLLISION_EVENT_H */
  • branches/coll_rect/src/lib/collision_reaction/collision_handle.cc

    r9869 r9889  
    2929#include "debug.h"
    3030
    31 
    32 ObjectListDefinition(CollisionHandle);
    33 
    34 /**
    35  * standard constructor
    36  * @todo this constructor is not jet implemented - do it
    37 */
    38 CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type)
     31namespace CoRe
    3932{
    40   this->registerObject(this, CollisionHandle::_objectList);
    41 
    42   this->owner = owner;
    43   this->type = type;
    44 
    45   this->bCollided = false;
    46   this->bDispatched = true;
    47 
    48   this->collisionReaction = NULL;
    49   this->bContinuousPoll = false;
    50   this->bStopOnFirstCollision = false;
    51 
    52 
    53   switch( type)
    54   {
    55     case CREngine::CR_PHYSICS_FULL_WALK:
    56       this->collisionReaction = new CRPhysicsFullWalk();
    57       this->bContinuousPoll = true;
    58       break;
    59     case CREngine::CR_PHYSICS_GROUND_WALK:
    60       this->collisionReaction = new CRPhysicsGroundWalk();
    61       this->bContinuousPoll = true;
    62       break;
    63     case CREngine::CR_OBJECT_DAMAGE:
    64       this->collisionReaction = new CRObjectDamage();
    65       this->bStopOnFirstCollision = true;
    66       break;
    67     default:
    68       break;
    69   };
     33
     34  ObjectListDefinition(CollisionHandle);
     35
     36  /**
     37   * standard constructor
     38   * @todo this constructor is not jet implemented - do it
     39  */
     40  CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type)
     41  {
     42    this->registerObject(this, CollisionHandle::_objectList);
     43
     44    this->owner = owner;
     45    this->type = type;
     46
     47    this->bCollided = false;
     48    this->bDispatched = true;
     49
     50    this->collisionReaction = NULL;
     51    this->bContinuousPoll = false;
     52    this->bStopOnFirstCollision = false;
     53
     54
     55    switch( type)
     56    {
     57        case CREngine::CR_PHYSICS_FULL_WALK:
     58        this->collisionReaction = new CRPhysicsFullWalk();
     59        this->bContinuousPoll = true;
     60        break;
     61        case CREngine::CR_PHYSICS_GROUND_WALK:
     62        this->collisionReaction = new CRPhysicsGroundWalk();
     63        this->bContinuousPoll = true;
     64        break;
     65        case CREngine::CR_OBJECT_DAMAGE:
     66        this->collisionReaction = new CRObjectDamage();
     67        this->bStopOnFirstCollision = true;
     68        break;
     69        default:
     70        break;
     71    };
     72  }
     73
     74
     75  /**
     76   * standard deconstructor
     77  */
     78  CollisionHandle::~CollisionHandle ()
     79  {
     80    // delete what has to be deleted here
     81    if( this->collisionReaction != NULL)
     82      delete this->collisionReaction;
     83  }
     84
     85  /**
     86   * restores the CollisionHandle to its initial state
     87   */
     88  void CollisionHandle::reset()
     89  {
     90    this->flushCollisions();
     91  }
     92
     93
     94  /**
     95   * add more filter targets to this collision handle
     96   *  @param classID the classid to look for
     97   */
     98  void CollisionHandle::addTarget(const ClassID& target)
     99  {
     100    // make sure there is no dublicate
     101    std::vector<ClassID>::iterator it = this->targetList.begin();
     102    for( ; it < this->targetList.end(); it++)
     103      if( (*it) == target)
     104        return;
     105
     106
     107    // add element
     108    this->targetList.push_back(target);
     109    PRINTF(5)("addTarget: %i \n", target.id());
     110  }
     111
     112
     113  /**
     114   * registers a new Collision Object
     115   *  @param entityA WorldEntity A of the collision
     116   *  @param entityB WorldEntity B of the collision
     117   * if a there is already a collision object with the same stats
     118   * registration will be skipped and the last collision object is returned
     119   */
     120  Collision* CollisionHandle::registerCollision(WorldEntity* entityA, WorldEntity* entityB)
     121  {
     122    //first get the collision object, multiple sources
     123    Collision* c;
     124    if( this->collisionList.empty() ||
     125        ((this->collisionList.back())->getEntityA() != entityA && (this->collisionList.back())->getEntityB() != entityB ))
     126    {
     127      c = CREngine::getInstance()->popCollisionObject();
     128      c->collide(entityA, entityB);
     129      this->collisionList.push_back(c);
     130
     131      // now register it as a shared collision with the other collision entity
     132      CollisionHandle* ch = entityB->getCollisionHandle(this->type);
     133      if( ch != NULL)
     134        ch->registerSharedCollision(c);
     135    }
     136    else
     137      c = this->collisionList.back();
     138
     139    return c;
     140  }
     141
     142
     143  /**
     144   * register a Collision to the Collision handle.
     145   *  @param collision the collision object to register
     146   *
     147   * This is used for internal collision registration: sharing the collision objects between Collision Reactions
     148   * Therefore dispatching it only once
     149   */
     150  void CollisionHandle::registerSharedCollision(Collision* collision)
     151  {
     152    // fist check if we are listening for this Collision
     153    if( !this->filterCollision(collision))
     154      return;
     155
     156    // set the state to not dispatched
     157    this->bDispatched = false;
     158    this->bCollided = true;
     159    collision->setEntityBCollide(true);
     160
     161    this->collisionList.push_back(collision);
     162  }
     163
     164
     165  /**
     166   * this is the function to be called on a collision event for this handle
     167   *  @param collision the collision objects containing all collision informations
     168   */
     169  void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent)
     170  {
     171    if( !this->filterCollisionEvent(collisionEvent))
     172      return;
     173
     174    // set the state to not dispatched
     175    this->bDispatched = false;
     176    this->bCollided = true;
     177
     178    // checks if these WorldEntities have already collided or if its a new collision -> create a new Collision object
     179    Collision* c = this->registerCollision(collisionEvent->getEntityA(), collisionEvent->getEntityB());
     180    c->setEntityACollide(true);
     181
     182    c->registerCollisionEvent(collisionEvent);
     183    PRINTF(5)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassCName(), collisionEvent->getEntityB()->getClassCName());
     184  }
     185
     186
     187  /**
     188   * flushes the collision list
     189   */
     190  void CollisionHandle::flushCollisions()
     191  {
     192    this->collisionList.clear();
     193  }
     194
     195
     196  /**
     197   * handles the collisions and react according to algorithm
     198   */
     199  void CollisionHandle::handleCollisions()
     200  {
     201    // if continuous poll poll the reaction
     202    if( this->bContinuousPoll && !this->bCollided)
     203    {
     204      this->collisionReaction->update(this->owner);
     205      return;
     206    }
     207
     208    // collision reaction calculations (for every collision there will be a reaction)
     209    std::vector<Collision*>::iterator it = this->collisionList.begin();
     210    for(; it < this->collisionList.end(); it++)
     211    {
     212      if( !(*it)->isDispatched())
     213      {
     214        this->collisionReaction->reactToCollision(*it);
     215        (*it)->flushCollisionEvents();
     216      }
     217    }
     218
     219    // now set state to dispatched
     220    this->bDispatched = true;
     221    this->bCollided = false;
     222
     223    this->flushCollisions();
     224  }
     225
     226
     227  /**
     228   * filter out the CollisionEvents that are not wanted
     229   *  @param collisionEvent the collision event to filter
     230   */
     231  bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent)
     232  {
     233    std::vector<ClassID>::iterator it = this->targetList.begin();
     234    for(; it < this->targetList.end(); it++)
     235    {
     236      //     if(collisionEvent->getEntityB()->isA(CL_AIMING_SYSTEM) || collisionEvent->getEntityA()->isA(CL_AIMING_SYSTEM))
     237      //     {
     238      //        PRINTF(0)("I am: %s colliding with: %s\n", owner->getClassCName(), collisionEvent->getEntityB()->getClassCName(), *it);
     239      //        if( collisionEvent->getEntityA() == this->owner) {
     240      //          PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
     241      //          collisionEvent->getEntityB()->getClassCName(), *it);
     242      //          if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
     243      //            PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
     244      //            collisionEvent->getEntityB()->getClassCName(), *it);
     245      //             }
     246      //        }
     247      //        else {
     248      //          PRINTF(0)("I am not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
     249      //          collisionEvent->getEntityB()->getClassCName(), *it);
     250      //          if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
     251      //            PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
     252      //            collisionEvent->getEntityA()->getClassCName(), *it);
     253      //             }
     254      //        }
     255      //
     256      //     }
     257
     258      if( collisionEvent->getEntityA() == this->owner)
     259      {
     260        if( collisionEvent->getEntityB()->isA((*it)))
     261        {
     262          PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
     263                    collisionEvent->getEntityB()->getClassCName(), (*it).id());
     264          return true;
     265        }
     266      }
     267      else
     268      {
     269        if( collisionEvent->getEntityA()->isA((*it)))
     270        {
     271          PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
     272                    collisionEvent->getEntityA()->getClassCName(), (*it).id());
     273          return true;
     274        }
     275      }
     276    }
     277
     278    return false;
     279  }
     280
     281
     282  /**
     283   * filter Collisions that are not wanted to be reacted to
     284   *  @param collision the collision object to filter
     285   */
     286  bool CollisionHandle::filterCollision(Collision* collision)
     287  {
     288    std::vector<ClassID>::iterator it = this->targetList.begin();
     289    for(; it < this->targetList.end(); it++)
     290    {
     291
     292      //     if(collision->getEntityB()->isA(CL_AIMING_SYSTEM) || collision->getEntityA()->isA(CL_AIMING_SYSTEM))
     293      //     {
     294      //       PRINTF(0)("Shared!!! I am: %s colliding with: %s\n", owner->getClassCName(), collision->getEntityB()->getClassCName(), *it);
     295      //       if( collision->getEntityA() == this->owner) {
     296      //         PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
     297      //         collision->getEntityB()->getClassCName(), *it);
     298      //         if( collision->getEntityB()->isA((ClassID)(*it))) {
     299      //           PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
     300      //           collision->getEntityB()->getClassCName(), *it);
     301      //         }
     302      //       }
     303      //       else {
     304      //         PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
     305      //         collision->getEntityB()->getClassCName(), *it);
     306      //         if( collision->getEntityA()->isA((ClassID)(*it))) {
     307      //           PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
     308      //           collision->getEntityA()->getClassCName(), *it);
     309      //         }
     310      //       }
     311      //     }
     312
     313      if( collision->getEntityA() == this->owner)
     314      {
     315        if( collision->getEntityA()->isA(*it))
     316          return true;
     317      }
     318      else
     319      {
     320        if( collision->getEntityB()->isA(*it))
     321          return true;
     322      }
     323    }
     324
     325    return false;
     326  }
     327
     328
     329
    70330}
    71331
    72332
    73 /**
    74  * standard deconstructor
    75 */
    76 CollisionHandle::~CollisionHandle ()
    77 {
    78   // delete what has to be deleted here
    79   if( this->collisionReaction != NULL)
    80     delete this->collisionReaction;
    81 }
    82 
    83 /**
    84  * restores the CollisionHandle to its initial state
    85  */
    86 void CollisionHandle::reset()
    87 {
    88   this->flushCollisions();
    89 }
    90 
    91 
    92 /**
    93  * add more filter targets to this collision handle
    94  *  @param classID the classid to look for
    95  */
    96 void CollisionHandle::addTarget(const ClassID& target)
    97 {
    98   // make sure there is no dublicate
    99   std::vector<ClassID>::iterator it = this->targetList.begin();
    100   for( ; it < this->targetList.end(); it++)
    101     if( (*it) == target)
    102       return;
    103 
    104 
    105   // add element
    106   this->targetList.push_back(target);
    107    PRINTF(5)("addTarget: %i \n", target.id());
    108 }
    109 
    110 
    111 /**
    112  * registers a new Collision Object
    113  *  @param entityA WorldEntity A of the collision
    114  *  @param entityB WorldEntity B of the collision
    115  * if a there is already a collision object with the same stats
    116  * registration will be skipped and the last collision object is returned
    117  */
    118 Collision* CollisionHandle::registerCollision(WorldEntity* entityA, WorldEntity* entityB)
    119 {
    120   //first get the collision object, multiple sources
    121   Collision* c;
    122   if( this->collisionList.empty() ||
    123       ((this->collisionList.back())->getEntityA() != entityA && (this->collisionList.back())->getEntityB() != entityB )) {
    124     c = CREngine::getInstance()->popCollisionObject();
    125     c->collide(entityA, entityB);
    126     this->collisionList.push_back(c);
    127 
    128     // now register it as a shared collision with the other collision entity
    129     CollisionHandle* ch = entityB->getCollisionHandle(this->type);
    130     if( ch != NULL)
    131       ch->registerSharedCollision(c);
    132   }
    133   else
    134     c = this->collisionList.back();
    135 
    136   return c;
    137 }
    138 
    139 
    140 /**
    141  * register a Collision to the Collision handle.
    142  *  @param collision the collision object to register
    143  *
    144  * This is used for internal collision registration: sharing the collision objects between Collision Reactions
    145  * Therefore dispatching it only once
    146  */
    147 void CollisionHandle::registerSharedCollision(Collision* collision)
    148 {
    149   // fist check if we are listening for this Collision
    150   if( !this->filterCollision(collision))
    151     return;
    152 
    153   // set the state to not dispatched
    154   this->bDispatched = false;
    155   this->bCollided = true;
    156   collision->setEntityBCollide(true);
    157 
    158   this->collisionList.push_back(collision);
    159 }
    160 
    161 
    162 /**
    163  * this is the function to be called on a collision event for this handle
    164  *  @param collision the collision objects containing all collision informations
    165  */
    166 void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent)
    167 {
    168   if( !this->filterCollisionEvent(collisionEvent))
    169     return;
    170 
    171   // set the state to not dispatched
    172   this->bDispatched = false;
    173   this->bCollided = true;
    174 
    175   // checks if these WorldEntities have already collided or if its a new collision -> create a new Collision object
    176  Collision* c = this->registerCollision(collisionEvent->getEntityA(), collisionEvent->getEntityB());
    177  c->setEntityACollide(true);
    178 
    179  c->registerCollisionEvent(collisionEvent);
    180  PRINTF(5)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassCName(), collisionEvent->getEntityB()->getClassCName());
    181 }
    182 
    183 
    184 /**
    185  * flushes the collision list
    186  */
    187 void CollisionHandle::flushCollisions()
    188 {
    189   this->collisionList.clear();
    190 }
    191 
    192 
    193 /**
    194  * handles the collisions and react according to algorithm
    195  */
    196 void CollisionHandle::handleCollisions()
    197 {
    198   // if continuous poll poll the reaction
    199   if( this->bContinuousPoll && !this->bCollided)
    200   {
    201     this->collisionReaction->update(this->owner);
    202     return;
    203   }
    204 
    205   // collision reaction calculations (for every collision there will be a reaction)
    206   std::vector<Collision*>::iterator it = this->collisionList.begin();
    207   for(; it < this->collisionList.end(); it++) {
    208     if( !(*it)->isDispatched())
    209     {
    210       this->collisionReaction->reactToCollision(*it);
    211       (*it)->flushCollisionEvents();
    212     }
    213   }
    214 
    215   // now set state to dispatched
    216   this->bDispatched = true;
    217   this->bCollided = false;
    218 
    219   this->flushCollisions();
    220 }
    221 
    222 
    223 /**
    224  * filter out the CollisionEvents that are not wanted
    225  *  @param collisionEvent the collision event to filter
    226  */
    227 bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent)
    228 {
    229   std::vector<ClassID>::iterator it = this->targetList.begin();
    230   for(; it < this->targetList.end(); it++)
    231   {
    232 //     if(collisionEvent->getEntityB()->isA(CL_AIMING_SYSTEM) || collisionEvent->getEntityA()->isA(CL_AIMING_SYSTEM))
    233 //     {
    234 //        PRINTF(0)("I am: %s colliding with: %s\n", owner->getClassCName(), collisionEvent->getEntityB()->getClassCName(), *it);
    235 //        if( collisionEvent->getEntityA() == this->owner) {
    236 //          PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    237 //          collisionEvent->getEntityB()->getClassCName(), *it);
    238 //          if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
    239 //            PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    240 //            collisionEvent->getEntityB()->getClassCName(), *it);
    241 //             }
    242 //        }
    243 //        else {
    244 //          PRINTF(0)("I am not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    245 //          collisionEvent->getEntityB()->getClassCName(), *it);
    246 //          if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
    247 //            PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    248 //            collisionEvent->getEntityA()->getClassCName(), *it);
    249 //             }
    250 //        }
    251 //
    252 //     }
    253 
    254     if( collisionEvent->getEntityA() == this->owner) {
    255       if( collisionEvent->getEntityB()->isA((*it))) {
    256         PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    257         collisionEvent->getEntityB()->getClassCName(), (*it).id());
    258         return true; }
    259     }
    260     else {
    261       if( collisionEvent->getEntityA()->isA((*it))) {
    262         PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    263         collisionEvent->getEntityA()->getClassCName(), (*it).id());
    264       return true; }
    265     }
    266   }
    267 
    268   return false;
    269 }
    270 
    271 
    272 /**
    273  * filter Collisions that are not wanted to be reacted to
    274  *  @param collision the collision object to filter
    275  */
    276 bool CollisionHandle::filterCollision(Collision* collision)
    277 {
    278   std::vector<ClassID>::iterator it = this->targetList.begin();
    279   for(; it < this->targetList.end(); it++)
    280   {
    281 
    282 //     if(collision->getEntityB()->isA(CL_AIMING_SYSTEM) || collision->getEntityA()->isA(CL_AIMING_SYSTEM))
    283 //     {
    284 //       PRINTF(0)("Shared!!! I am: %s colliding with: %s\n", owner->getClassCName(), collision->getEntityB()->getClassCName(), *it);
    285 //       if( collision->getEntityA() == this->owner) {
    286 //         PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    287 //         collision->getEntityB()->getClassCName(), *it);
    288 //         if( collision->getEntityB()->isA((ClassID)(*it))) {
    289 //           PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    290 //           collision->getEntityB()->getClassCName(), *it);
    291 //         }
    292 //       }
    293 //       else {
    294 //         PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(),
    295 //         collision->getEntityB()->getClassCName(), *it);
    296 //         if( collision->getEntityA()->isA((ClassID)(*it))) {
    297 //           PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(),
    298 //           collision->getEntityA()->getClassCName(), *it);
    299 //         }
    300 //       }
    301 //     }
    302 
    303     if( collision->getEntityA() == this->owner) {
    304       if( collision->getEntityA()->isA(*it))
    305         return true; }
    306       else {
    307         if( collision->getEntityB()->isA(*it))
    308           return true; }
    309   }
    310 
    311   return false;
    312 }
    313 
    314 
    315 
    316 
    317 
    318 
    319 
     333
  • branches/coll_rect/src/lib/collision_reaction/collision_handle.h

    r9888 r9889  
    1616class Collision;
    1717class WorldEntity;
    18 class CollisionReaction;
     18
     19namespace CoRe
     20{
     21
     22  class CollisionReaction;
    1923
    2024
    2125
    22 //! A class for defining collision reactions and storing events
    23 class CollisionHandle : public BaseObject
    24 {
    25   ObjectListDeclaration(CollisionHandle);
     26  //! A class for defining collision reactions and storing events
     27  class CollisionHandle : public BaseObject
     28  {
     29    ObjectListDeclaration(CollisionHandle);
    2630  public:
    2731    CollisionHandle(WorldEntity* owner, CREngine::CRType type);
     
    6872    CollisionReaction*            collisionReaction;       //!< reference to the collision reaction object
    6973
    70 };
     74  };
    7175
     76}
    7277#endif /* _COLLISION_HANDLE_H */
  • branches/coll_rect/src/lib/collision_reaction/collision_reaction.cc

    r9888 r9889  
    1717#include "collision_reaction.h"
    1818
     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  }
    1932
    2033
    21 ObjectListDefinition(CollisionReaction);
     34  /**
     35   *  standard deconstructor
     36   */
     37  CollisionReaction::~CollisionReaction ()
     38  {}
    2239
    23 /**
    24  *  standard constructor
    25  */
    26 CollisionReaction::CollisionReaction ()
    27   : BaseObject()
    28 {
    29   this->registerObject(this, CollisionReaction::_objectList);
    3040}
    31 
    32 
    33 /**
    34  *  standard deconstructor
    35  */
    36 CollisionReaction::~CollisionReaction ()
    37 {
    38 }
    39 
  • branches/coll_rect/src/lib/collision_reaction/collision_reaction.h

    r9869 r9889  
    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();
     
    3233  private:
    3334    bool                    bContinuousPoll;       //!< if true the collision rection function is also called, if there was no collision
    34 };
     35  };
    3536
     37}
    3638#endif /* _COLLISION_REACTION_H */
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.cc

    r9869 r9889  
    2727#include "debug.h"
    2828
     29namespace CoRe
     30{
     31
     32  ObjectListDefinition(CREngine);
     33  /**
     34   * standard constructor
     35   */
     36  CREngine::CREngine ()
     37      : BaseObject()
     38  {
     39    this->registerObject(this, CREngine::_objectList);
     40    this->setName("CREngine");
     41
     42    this->init();
     43  }
     44
     45  /**
     46   *  the singleton reference to this class
     47   */
     48  CREngine* CREngine::singletonRef = NULL;
     49
     50  /**
     51     @brief standard deconstructor
     52   */
     53  CREngine::~CREngine ()
     54  {
     55    CREngine::singletonRef = NULL;
     56
     57    if( this->collisionsUnused.size() != CR_MAX_COLLISIONS)
     58      PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS);
     59    if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS)
     60      PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);
     61
     62    this->reset();
     63
     64    std::vector<Collision*>::iterator it1 = this->collisionsUnused.begin();
     65    for(; it1 < this->collisionsUnused.end(); it1++)
     66      delete *it1;
     67    std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin();
     68    for(; it2 < this->collisionEventsUnused.end(); it2++)
     69      delete *it2;
     70
     71    this->collisionsUnused.clear();
     72    this->collisionEventsUnused.clear();
     73  }
     74
     75  /**
     76   * inits the CREngine to a working state
     77   */
     78  void CREngine::init()
     79  {
     80    // create a list of Collision events (precaching)
     81    for( int i = 0; i < CR_MAX_COLLISIONS; i++)
     82      this->collisionsUnused.push_back(new Collision());
     83    for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)
     84      this->collisionEventsUnused.push_back(new CollisionEvent());
     85  }
    2986
    3087
    31 ObjectListDefinition(CREngine);
    32 /**
    33  * standard constructor
    34  */
    35 CREngine::CREngine ()
    36   : BaseObject()
    37 {
    38   this->registerObject(this, CREngine::_objectList);
    39    this->setName("CREngine");
     88  /**
     89   * flushes the CollisionHandles and restores the CREngine to the initial state
     90   */
     91  void CREngine::reset()
     92  {
     93    // first clear all CollisionHandles
    4094
    41    this->init();
    42 }
     95    std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();
     96    for(; it < this->collisionHandles.end(); it++)
     97    {
     98      (*it)->reset();
     99      delete *it;
     100    }
    43101
    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 }
     102    this->collisionHandles.clear();
     103  }
    85104
    86105
    87 /**
    88  * flushes the CollisionHandles and restores the CREngine to the initial state
    89  */
    90 void CREngine::reset()
    91 {
    92   // first clear all CollisionHandles
     106  /**
     107   * subscribes a WorldEntity for a CollisionReaction
     108   *  @param owner: the WE to subscribe
     109   *  @param type: the type of collision reaction to perform
     110   *  @return the newly created CollisionHandle
     111   */
     112  CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type)
     113  {
     114    CollisionHandle* ch = new CollisionHandle(owner, type);
     115    this->collisionHandles.push_back(ch);
    93116
    94   std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();
    95   for(; it < this->collisionHandles.end(); it++)
    96   {
    97     (*it)->reset();
    98     delete *it;
     117    return ch;
    99118  }
    100119
    101   this->collisionHandles.clear();
    102 }
     120
     121  /**
     122   * unsubscribe reaction from the reaction list
     123   *  @param collisionHandle the CollisionHandle to remove
     124   *  @param returns true if worked collrectly
     125   */
     126  bool CREngine::unsubscribeReaction(CollisionHandle* collisionHandle)
     127  {
     128    std::vector<CollisionHandle*>::iterator it;
     129    for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
     130    {
     131      if( *it == collisionHandle)
     132      {
     133        this->collisionHandles.erase(it);
     134        delete collisionHandle;
     135        return true;
     136      }
     137    }
     138    return false;
     139  }
    103140
    104141
    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 }
     142  /**
     143   * processes the collisions by calling the EventHandlers
     144   */
     145  void CREngine::handleCollisions()
     146  {
     147    std::vector<CollisionHandle*>::iterator it;
     148    for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
     149    {
     150      if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
     151      {
     152        (*it)->handleCollisions();
     153      }
     154    }
     155    this->flushCollisions();
     156  }
    118157
    119158
    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     }
     159  /**
     160   * flushes all the collision lists and puts them to their initial state
     161   */
     162  void CREngine::flushCollisions()
     163  {
     164    std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin();
     165    for(; it1 < this->collisionsUsed.end(); it1++)
     166      this->collisionsUnused.push_back(*it1);
     167
     168    std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();
     169    for(; it2 < this->collisionEventsUsed.end(); it2++)
     170      this->collisionEventsUnused.push_back(*it2);
     171
     172    this->collisionsUsed.clear();
     173    this->collisionEventsUsed.clear();
    134174  }
    135   return false;
    136 }
    137175
    138176
    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++)
     177  void CREngine::debug()
    146178  {
    147     if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
    148     {
    149       (*it)->handleCollisions();
    150     }
    151179  }
    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 {
    176180
    177181}
    178 
  • branches/coll_rect/src/lib/collision_reaction/cr_engine.h

    r9869 r9889  
    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 CollisionHandle;
     24  class Collision;
     25  class CollisionEvent;
     26
     27  //! A default singleton class.
     28  class CREngine : public BaseObject
     29  {
     30    ObjectListDeclaration(CREngine);
    2831
    2932  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
     33    typedef enum CRType {
     34      CR_PHYSICS_MOMENTUM   = 0,    //!< physical reaction: conservervation of momentum
     35      CR_PHYSICS_STEP_BACK,         //!< physical reaction: just go to the last position without collisions
     36      CR_PHYSICS_GROUND_WALK,       //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
     37      CR_PHYSICS_FULL_WALK,         //!< physical reaction: walking on the ground (inkl. hills etc)
     38      CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
    3639
    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!)
     40      CR_OBJECT_DAMAGE,             //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)
     41      CR_OBJECT_PICKUP,             //!< object rection: calling the objects pickup functions, let them handle the collision (once!)
    3942
    40     CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
     43      CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
    4144
    42     CR_SPECIAL_CALLBACK,          //!< special: call a callback function
     45      CR_SPECIAL_CALLBACK,          //!< special: call a callback function
    4346
    44     CR_NUMBER
     47      CR_NUMBER
     48    };
     49
     50    virtual ~CREngine(void);
     51
     52    /** @returns a Pointer to the only object of this Class */
     53    inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
     54
     55    void reset();
     56
     57
     58    CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
     59
     60    bool unsubscribeReaction(CollisionHandle* collisionHandle);
     61
     62    void handleCollisions();
     63
     64    /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
     65    inline Collision* popCollisionObject()
     66    {
     67      if( !this->collisionsUnused.empty())
     68      {
     69        this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back();
     70      }
     71      else return NULL;
     72    }
     73
     74
     75    /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */
     76    inline CollisionEvent* popCollisionEventObject()
     77    {
     78      if( !this->collisionEventsUnused.empty())
     79      {
     80        this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back();
     81      }
     82      else return NULL;
     83    }
     84
     85    void debug();
     86
     87
     88  private:
     89    CREngine();
     90    void init();
     91
     92    void flushCollisions();
     93
     94
     95  private:
     96    std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
     97
     98    std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
     99    std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
     100
     101    std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
     102    std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
     103
     104    static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
    45105  };
    46106
    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 
     107}
    94108#endif /* _CR_ENGINE_ */
  • branches/coll_rect/src/lib/collision_reaction/cr_object_damage.cc

    r9869 r9889  
    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    collision->flushCollisionEvents();
     77    collision->dispatched();
     78
     79    //   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     80    //   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     81    //   for(; it != collisionEvents->end(); it++)
     82    //   {
     83    //     // go through the collisions and try to estimate the damage
     84    //     mass = (*it)->getEntityA()->getMass();
     85    //   }
     86
    6687  }
    6788
    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 
    8589}
    86 
  • branches/coll_rect/src/lib/collision_reaction/cr_object_damage.h

    r9869 r9889  
    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();
     
    2428  private:
    2529
    26 };
     30  };
     31}
    2732
    2833#endif /* _CR_OBJECT_DAMAGE_H */
  • branches/coll_rect/src/lib/collision_reaction/cr_physics_full_walk.cc

    r9869 r9889  
    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->getEntityB()->getModelAABB();
     64    WorldEntity* entity = collision->getEntityB();
     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    const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     84    std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     85    for(; it != collisionEvents->end(); it++)
     86    {
     87
     88      CollisionEvent* ce = (*it);
     89      Vector normal = ce->getGroundNormal();
     90
     91      // calculate the collision position
     92      Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     93
     94      // test the 3 axis differently
     95      switch( ce->getType())
     96      {
     97          /* collision in the X-AXIS */
     98          case COLLISION_TYPE_AXIS_X:
     99          front = collPos.len() - box->halfLength[0];
     100
     101          // object is beneath the plane (ground)
     102          if( front <= 0.0f )
     103          {
     104            Vector dirX = entity->getAbsDirX();
     105            dirX.y = 0.0f;
     106            dirX.normalize();
     107            Vector backoff = dirX * front;
     108
     109            entity->shiftCoor(backoff);
     110          }
     111          else if( ce->isInWall())
     112          {
     113            // object is already in the wall
     114            entity->setAbsCoor(entity->getLastAbsCoor());
     115          }
     116          break;
     117
     118          case COLLISION_TYPE_AXIS_X_NEG:
     119          back = collPos.len() - box->halfLength[0];
     120
     121          // object is beneath the plane (ground)
     122          if( back <= 0.0f)
     123          {
     124            Vector dirX = entity->getAbsDirX();
     125            dirX.y = 0.0f;
     126            dirX.normalize();
     127            Vector backoff = dirX * back * -1.0f;
     128
     129            entity->shiftCoor(backoff);
     130          }
     131          else if( ce->isInWall())
     132          {
     133            // object is already in the wall
     134            entity->setAbsCoor(entity->getLastAbsCoor());
     135          }
     136          break;
     137
     138
     139          /* collision in the Y-AXIS */
     140          case COLLISION_TYPE_AXIS_Y_NEG:
     141          // calulate the height above ground
     142          height = collPos.len() - box->halfLength[1];
     143
     144
     145          // object is beneath the plane (ground)
     146          //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
     147          if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
     148          {
     149            entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
     150            entity->setOnGround(true);
     151          }
     152          // object is already in the wall
     153          else if( ce->isInWall())
     154          {
     155            entity->setAbsCoor(entity->getLastAbsCoor());
     156            PRINTF(0)("ground collision: reset pos\n");
     157          }
     158          else
     159          {
     160            // entity is not on ground
     161            entity->setOnGround(false);
     162          }
     163          break;
     164
     165
     166          /* collision in the Z-AXIS */
     167          case COLLISION_TYPE_AXIS_Z:
     168
     169          right = collPos.len()  - box->halfLength[2];
     170
     171          // object is beneath the plane (ground)
     172          if( right <= 0.0f )
     173          {
     174            Vector dirZ = entity->getAbsDirZ();
     175            dirZ.y = 0.0f;
     176            dirZ.normalize();
     177            Vector backoff = dirZ * right;
     178            entity->shiftCoor(backoff);
     179          }
     180          else if( ce->isInWall())
     181          {
     182            // object is already in the wall
     183            entity->setAbsCoor(entity->getLastAbsCoor());
     184          }
     185          break;
     186
     187
     188          // collision in the z-axis
     189          case COLLISION_TYPE_AXIS_Z_NEG:
     190
     191          left = collPos.len()  - box->halfLength[2];
     192
     193          // object is beneath the plane (ground)
     194          if( left <= 0.0f )
     195          {
     196            Vector dirZ = entity->getAbsDirZ();
     197            dirZ.y = 0.0f;
     198            dirZ.normalize();
     199            Vector backoff = dirZ * left*-1.0f;
     200            entity->shiftCoor(backoff);
     201          }
     202          // object is already in the wall
     203          else if( ce->isInWall())
     204          {
     205            entity->setAbsCoor(entity->getLastAbsCoor());
     206          }
     207          break;
     208      }
     209    }
     210    //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
     211
     212
     213
     214
     215
     216
     217
     218  }
     219
     220
     221
     222
     223  /**
     224   * use this to do some collision offline calculations, only called for bContinuousPoll == true
     225   */
     226  void CRPhysicsFullWalk::update(WorldEntity* owner)
     227  {}
    45228}
    46 
    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/src/lib/collision_reaction/cr_physics_full_walk.h

    r9869 r9889  
    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();
     
    2729  private:
    2830    float        downspeed;
    29 };
    30 
     31  };
     32}
    3133#endif /* _CR_PHYSICS_FULL_WALK_H */
  • branches/coll_rect/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r9869 r9889  
    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->getEntityB()->getModelAABB();
     67    WorldEntity* entity = collision->getEntityB();
    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    const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     82    std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     83    for(; it != collisionEvents->end(); it++)
     84    {
     85
     86      CollisionEvent* ce = (*it);
     87      Vector normal = ce->getGroundNormal();
     88
     89      // calculate the collision position
     90      Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     91
     92      // test the 3 axis differently
     93      switch( ce->getType())
     94      {
     95          /* collision in the Y-AXIS */
     96          case COLLISION_TYPE_AXIS_Y_NEG:
     97          // calulate the height above ground
     98          height = collPos.len() - box->halfLength[1];
     99
     100
     101          // object is beneath the plane (ground)
     102          //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
     103          if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
     104          {
     105            entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
     106            entity->setOnGround(true);
     107          }
     108          // object is already in the wall
     109          else if( ce->isInWall())
     110          {
     111            entity->setAbsCoor(entity->getLastAbsCoor());
     112          }
     113          else
     114          {
     115            // entity is not on ground
     116            entity->setOnGround(false);
     117          }
     118          break;
     119
     120
     121      }
    117122    }
     123    //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
     124
    118125  }
    119   //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
    120 
    121 }
    122126
    123127
    124128
    125129
    126 /**
    127  * use this to do some collision offline calculations, only called for bContinuousPoll == true
    128  */
    129 void CRPhysicsGroundWalk::update(WorldEntity* owner)
    130 {}
     130  /**
     131   * use this to do some collision offline calculations, only called for bContinuousPoll == true
     132   */
     133  void CRPhysicsGroundWalk::update(WorldEntity* owner)
     134  {}
    131135
    132 
     136}
  • branches/coll_rect/src/lib/collision_reaction/cr_physics_ground_walk.h

    r9869 r9889  
    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();
     
    2729  private:
    2830    float        downspeed;
    29 };
     31  };
    3032
     33}
    3134#endif /* _CR_PHYSICS_GROUND_WALK_H */
  • branches/coll_rect/src/story_entities/game_world.cc

    r9869 r9889  
    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/src/story_entities/game_world_data.cc

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

    r9869 r9889  
    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/src/world_entities/npcs/generic_npc.cc

    r9869 r9889  
    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/src/world_entities/weapons/aiming_system.cc

    r9869 r9889  
    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/src/world_entities/world_entity.cc

    r9869 r9889  
    7878
    7979  // reset all collision handles to NULL == unsubscribed state
    80   for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     80  for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    8181    this->collisionHandles[i] = NULL;
    8282  this->bReactive = false;
     
    8484
    8585  // registering default reactions:
    86   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID());
     86  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID());
    8787
    8888  this->toList(OM_NULL);
     
    302302 *  @param target1 a filter target (classID)
    303303 */
    304 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1)
     304void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1)
    305305{
    306306  this->subscribeReaction(type);
     
    316316 *  @param target1 a filter target (classID)
    317317 */
    318 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2)
     318void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2)
    319319{
    320320  this->subscribeReaction(type);
     
    331331 *  @param target1 a filter target (classID)
    332332 */
    333 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
     333void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
    334334{
    335335  this->subscribeReaction(type);
     
    342342
    343343
    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 
    360344
    361345/**
     
    365349 *  @param ... the targets as classIDs
    366350 */
    367 void WorldEntity::subscribeReaction(CREngine::CRType type)
     351void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type)
    368352{
    369353  if( this->collisionHandles[type] != NULL)
     
    373357  }
    374358
    375   this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
     359  this->collisionHandles[type] = CoRe::CREngine::getInstance()->subscribeReaction(this, type);
    376360
    377361  // now there is at least one collision reaction subscribed
     
    384368 *  @param type the reaction to unsubscribe
    385369 */
    386 void WorldEntity::unsubscribeReaction(CREngine::CRType type)
     370void WorldEntity::unsubscribeReaction(CoRe::CREngine::CRType type)
    387371{
    388372  if( this->collisionHandles[type] == NULL)
    389373    return;
    390374
    391   CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
     375  CoRe::CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
    392376  this->collisionHandles[type] = NULL;
    393377
    394378  // check if there is still any handler registered
    395   for(int i = 0; i < CREngine::CR_NUMBER; ++i)
     379  for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    396380  {
    397381    if( this->collisionHandles[i] != NULL)
     
    410394void WorldEntity::unsubscribeReaction()
    411395{
    412   for( int i = 0; i < CREngine::CR_NUMBER; i++)
    413     this->unsubscribeReaction((CREngine::CRType)i);
     396  for( int i = 0; i < CoRe::CREngine::CR_NUMBER; i++)
     397    this->unsubscribeReaction((CoRe::CREngine::CRType)i);
    414398
    415399  // there are no reactions subscribed from now on
     
    433417
    434418  // get a collision event
    435   CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
     419  CoRe::CollisionEvent* c = CoRe::CREngine::getInstance()->popCollisionEventObject();
    436420  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    437421  c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
    438422
    439   for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     423  for( int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    440424    if( this->collisionHandles[i] != NULL)
    441425      this->collisionHandles[i]->registerCollisionEvent(c);
     
    457441
    458442  // get a collision event
    459   CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
     443  CoRe::CollisionEvent* c = CoRe::CREngine::getInstance()->popCollisionEventObject();
    460444  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
    461445  c->collide(type, entity, groundEntity, normal, position, bInWall);
    462446
    463   for( int i = 0; i < CREngine::CR_NUMBER; ++i)
     447  for( int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i)
    464448    if( this->collisionHandles[i] != NULL)
    465449      this->collisionHandles[i]->registerCollisionEvent(c);
  • branches/coll_rect/src/world_entities/world_entity.h

    r9888 r9889  
    8282
    8383  /* --- 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);
     84  void subscribeReaction(CoRe::CREngine::CRType type);
     85  void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1);
     86  void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2);
     87  void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
     88
     89  void unsubscribeReaction(CoRe::CREngine::CRType type);
    9190  void unsubscribeReaction();
    9291
     
    9695  inline bool isReactive() const { return this->bReactive; }
    9796
    98   CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
     97  CoRe::CollisionHandle* getCollisionHandle(CoRe::CREngine::CRType type) const { return this->collisionHandles[type]; }
    9998
    10099  /** @returns true if this entity is standing on ground (BSP model) */
     
    212211  int                     healthMax_handle;
    213212
    214   CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
     213  CoRe::CollisionHandle*  collisionHandles[CoRe::CREngine::CR_NUMBER];  //!< the list of the collision reactions
    215214  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
     215
    216216
    217217  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
Note: See TracChangeset for help on using the changeset viewer.