Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8490 in orxonox.OLD for trunk/src/lib/collision_reaction


Ignore:
Timestamp:
Jun 15, 2006, 9:34:48 PM (19 years ago)
Author:
patrick
Message:

merged the bsp branche back to trunk

Location:
trunk/src/lib/collision_reaction
Files:
8 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_reaction/Makefile.am

    r8190 r8490  
    99                     collision_handle.cc \
    1010                     collision_reaction.cc \
    11                      cr_object_damage.cc
     11                     cr_object_damage.cc \
     12                     cr_physics_ground_walk.cc
    1213
    1314
     
    1920                     cr_defs.h \
    2021                     collision_reaction.h \
    21                      cr_object_damage.h
     22                     cr_object_damage.h \
     23                     cr_physics_ground_walk.h
    2224
  • trunk/src/lib/collision_reaction/collision.h

    r8190 r8490  
    2727
    2828    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    29     inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; }
     29    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; }
    3030
    3131
     
    4242    /** sets the flag if it reacts @param flag true if it should react on entityB*/
    4343    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
     44
    4445
    4546    /** @returns true if this Collision has already been dispatched */
  • trunk/src/lib/collision_reaction/collision_event.h

    r8190 r8490  
    2525  { this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
    2626  /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
    27   inline void collide(WorldEntity* entity, Plane* ground, Vector position)
    28   { this->entityA = entity; this->ground = ground; this->position = position; }
     27  inline void collide(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position)
     28  { this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; }
    2929
    3030
     
    3838  inline BoundingVolume* getBVB() const { return this->bvB; }
    3939
     40  /** @return ground plane if collided with bsp model */
     41  inline Vector getGroundNormal() { return this->groundNormal; }
    4042
    41   inline void operator()(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) { this->collide(entityA, entityB, bvA, bvB); }
    42   inline void operator()(WorldEntity* entity, Plane* ground, Vector position) { this->collide(entity, ground, position); }
    43 
     43  /** @return position of the position, only accurate if this is a collision with the ground!!! */
     44  inline Vector getCollisionPosition() { return this->position; }
    4445
    4546 private:
     
    5051  BoundingVolume*   bvB;                           //!< reference to the bounding volume B
    5152
    52   Plane*            ground;                        //!< the ground plane with which it collides (only for bsp-model collisions
     53  Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
    5354  Vector            position;                      //!< position of the collision on the ground plane
    5455};
  • trunk/src/lib/collision_reaction/collision_handle.cc

    r8362 r8490  
    2424
    2525#include "cr_object_damage.h"
     26#include "cr_physics_ground_walk.h"
    2627
    2728#include "debug.h"
     
    4243
    4344  this->bCollided = false;
    44   this->bDispatched = false;
    45 
    46   if( this->type == CREngine::CR_PHYSICS_STEP_BACK)
    47     this->bContinuousPoll = false;
    48   else
    49     this->bContinuousPoll = true;
    50 
    51   if( this->type == CREngine::CR_OBJECT_DAMAGE)
    52     this->bStopOnFirstCollision = true;
    53   else
    54    this->bStopOnFirstCollision = false;
     45  this->bDispatched = true;
     46
     47  this->collisionReaction = NULL;
     48  this->bContinuousPoll = false;
     49  this->bStopOnFirstCollision = false;
     50
    5551
    5652  switch( type)
    5753  {
     54    case CREngine::CR_PHYSICS_STEP_BACK:
     55//       this->collisionReaction = new CRPhysicsGroundWalk();
     56      this->bContinuousPoll = true;
     57      break;
     58    case CREngine::CR_PHYSICS_GROUND_WALK:
     59      this->collisionReaction = new CRPhysicsGroundWalk();
     60      this->bContinuousPoll = true;
     61      break;
    5862    case CREngine::CR_OBJECT_DAMAGE:
    5963      this->collisionReaction = new CRObjectDamage();
     64      this->bStopOnFirstCollision = true;
    6065      break;
    6166    default:
     
    7176{
    7277  // delete what has to be deleted here
     78  if( this->collisionReaction != NULL)
     79    delete this->collisionReaction;
    7380}
    7481
     
    169176
    170177 c->registerCollisionEvent(collisionEvent);
     178 PRINTF(0)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassName(), collisionEvent->getEntityB()->getClassName());
    171179}
    172180
     
    186194void CollisionHandle::handleCollisions()
    187195{
     196  // if continuous poll poll the reaction
     197  if( this->bContinuousPoll && !this->bCollided)
     198  {
     199    this->collisionReaction->update(this->owner);
     200    return;
     201  }
     202
    188203  // collision reaction calculations (for every collision there will be a reaction)
    189204  vector<Collision*>::iterator it = this->collisionList.begin();
     
    214229  {
    215230    if( collisionEvent->getEntityA() == this->owner) {
    216       if( collisionEvent->getEntityA()->isA((ClassID)(*it)))
     231      if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
     232        PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
     233                  collisionEvent->getEntityB()->getClassName(), *it);
    217234        return true; }
     235    }
    218236    else {
    219       if( collisionEvent->getEntityB()->isA((ClassID)(*it)))
    220         return true; }
     237      if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
     238        PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
     239                  collisionEvent->getEntityA()->getClassName(), *it);
     240      return true; }
     241    }
    221242  }
    222243
  • trunk/src/lib/collision_reaction/collision_handle.h

    r8190 r8490  
    4141    /** @returns true if this handle should be pulled also if there are no collisions */
    4242    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
     43    /** @returns the type */
     44    inline CREngine::CRType getType() const { return this->type; }
    4345
    4446    void handleCollisions();
  • trunk/src/lib/collision_reaction/collision_reaction.h

    r8190 r8490  
    1212
    1313class Collision;
     14class WorldEntity;
     15
    1416
    1517//! A class representing a simple collision
     
    2325    virtual void reactToCollision(Collision* collision) = 0;
    2426
     27    virtual void update(WorldEntity* owner) {}
     28
     29    /** use this to do some collision offline calculations, only called for bContinuousPoll == true */
    2530    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
    2631
  • trunk/src/lib/collision_reaction/cr_engine.cc

    r8362 r8490  
    126126{
    127127  std::vector<CollisionHandle*>::iterator it;
    128   for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
    129   {
    130     if( *it == collisionHandle)
    131     {
     128  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)  {
     129    if( *it == collisionHandle) {
    132130      this->collisionHandles.erase(it);
    133131      delete collisionHandle;
     
    147145  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
    148146  {
    149     if( (*it)->isCollided() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
     147    if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
    150148    {
    151149      (*it)->handleCollisions();
  • trunk/src/lib/collision_reaction/cr_object_damage.cc

    r8362 r8490  
    5454void CRObjectDamage::reactToCollision(Collision* collision)
    5555{
    56   float damage;
     56  float damage = 0.0f;
    5757
    58   PRINTF(0)("Dealing damage - Handling collision: %s vs %s\n",
     58  PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n",
    5959            collision->getEntityA()->getClassName(),
    6060            collision->getEntityB()->getClassName());
     
    6565    collision->getEntityA()->decreaseHealth(damage);
    6666  }
    67   PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
     67  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
    6868
    6969  if( collision->isEntityBCollide()) {
     
    7171    collision->getEntityB()->decreaseHealth(damage);
    7272  }
    73   PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
     73  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
    7474
    7575  collision->flushCollisionEvents();
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8489 r8490  
    2323#include "world_entity.h"
    2424#include "cr_physics_ground_walk.h"
     25
     26#include "debug.h"
    2527
    2628#include <vector>
Note: See TracChangeset for help on using the changeset viewer.