Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.