Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8923 in orxonox.OLD


Ignore:
Timestamp:
Jun 29, 2006, 10:09:28 PM (18 years ago)
Author:
patrick
Message:

ground collision detection advanc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/single_player_map/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8922 r8923  
    5959void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
    6060{
    61   CollisionEvent* ce = collision->getCollisionEvents().front();
    62   Vector normal = ce->getGroundNormal();
    63   // normal.normalize();
    64 
    65 
    66   float height;
     61
    6762  AABB* box = collision->getEntityB()->getModelAABB();
    6863  WorldEntity* entity = collision->getEntityB();
     
    7570
    7671
    77   // collision position maths
    78   Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
    79 
    8072  float CR_MAX_WALK_HEIGHT = 2.0f;
    8173  float CR_THRESHOLD = 0.2f;
    8274
    83   //height = collPos.y - box->halfLength[1];
    84   //PRINTF(0)("height: %f          , model height: %f\n", height, box->halfLength[1]);
    85   // PRINTF(0)(" ground normal: %f, %f, %f\n", normal.x, normal.y, normal.z);
    86   //
    87 
    88   switch( ce->getType())
    89   {
    90 
    91     case COLLISION_TYPE_AXIS_X:
    92 
    93       break;
    94 
    95     case COLLISION_TYPE_AXIS_Y:
    96 
    97       height = collPos.y - box->halfLength[1];
    98 
    99       PRINTF(0)("height: %f\n", height);
    100       PRINTF(0)("in wall %i\n", ce->isInWall());
    101 
    102       // object is beneath the plane (ground)
    103       if( height <= 0.0f )
    104       {
    105         entity->shiftCoor(Vector(0, -height, 0));
    106       }
    107       // object is already in the wall
    108       else if( ce->isInWall())
    109       {
    110         entity->setAbsCoor(entity->getLastAbsCoor());
    111       }
    112       break;
    113       break;
    114 
    115 
    116     case COLLISION_TYPE_AXIS_Z:
    117 
    118       break;
    119 
    120   }
    121 
     75  float height;
     76
     77
     78   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     79   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     80   for(; it != collisionEvents->end(); it++)
     81   {
     82
     83     CollisionEvent* ce = (*it);
     84     Vector normal = ce->getGroundNormal();
     85
     86     // collision position maths
     87     Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     88
     89
     90     // test the 3 axis differently
     91     switch( ce->getType())
     92     {
     93       // collision in the x-axis
     94       case COLLISION_TYPE_AXIS_X:
     95         PRINTF(0)("AXIS X\n");
     96         break;
     97
     98
     99       // collision in the y-axis
     100       case COLLISION_TYPE_AXIS_Y:
     101         // calulate the height above ground
     102         height = collPos.y - box->halfLength[1];
     103
     104         PRINTF(0)("height: %f\n", height);
     105         PRINTF(0)("in wall %i\n", ce->isInWall());
     106
     107         // object is beneath the plane (ground)
     108         if( height <= 0.0f )
     109         {
     110           entity->shiftCoor(Vector(0, -height, 0));
     111         }
     112         // object is already in the wall
     113         else if( ce->isInWall())
     114         {
     115           entity->setAbsCoor(entity->getLastAbsCoor());
     116         }
     117         break;
     118
     119
     120       // collision in the z-axis
     121       case COLLISION_TYPE_AXIS_Z:
     122         PRINTF(0)("AXIS Y\n");
     123         break;
     124     }
     125   }
    122126
    123127
Note: See TracChangeset for help on using the changeset viewer.