Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 4, 2006, 11:18:41 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the Presentation back

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r9061 r9110  
    7070
    7171
    72   float CR_MAX_WALK_HEIGHT = 2.0f;
     72  float CR_MAX_WALK_HEIGHT = 15.0f;
    7373  float CR_THRESHOLD = 0.2f;
    7474
    75   float height = 0;
    76   float front = 0;
    77   float side = 0;
    78 
    79   //PRINTF(0)("collision raction======================================\n");
     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
    8081
    8182  const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     
    9394    switch( ce->getType())
    9495    {
    95         // collision in the x-axis
     96        /* collision in the X-AXIS */
    9697      case COLLISION_TYPE_AXIS_X:
    97         front = collPos.len() - box->halfLength[0]; // should be [0]
     98        front = collPos.len() - box->halfLength[0];
    9899
    99100        // object is beneath the plane (ground)
    100101        if( front <= 0.0f )
    101102        {
    102           Vector dirX = entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
     103          Vector dirX = entity->getAbsDirX();
     104          dirX.y = 0.0f;
     105          dirX.normalize();
    103106          Vector backoff = dirX * front;
    104          
    105           entity->setAbsCoor(entity->getLastAbsCoor());
    106          // entity->shiftCoor(backoff);
    107         }
    108         // object is already in the wall
    109         else if( ce->isInWall())
    110         {
    111               entity->setAbsCoor(entity->getLastAbsCoor());
    112         }
    113         break;
    114        
     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
    115117      case COLLISION_TYPE_AXIS_X_NEG:
    116         front = collPos.len() - box->halfLength[0]; // should be [0]
    117 
    118         // object is beneath the plane (ground)
    119         if( front <= 0.0f )
    120         {
    121           Vector dirX = entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
    122           Vector backoff = dirX * front * -1.0f;
    123          
    124           entity->setAbsCoor(entity->getLastAbsCoor());
    125          // entity->shiftCoor(backoff);
    126         }
    127         // object is already in the wall
    128         else if( ce->isInWall())
    129         {
    130           entity->setAbsCoor(entity->getLastAbsCoor());
    131         }
    132         break;
    133 
    134 
    135         // collision in the y-axis
     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 */
    136139      case COLLISION_TYPE_AXIS_Y_NEG:
    137140        // calulate the height above ground
    138         height = collPos.y - box->halfLength[1];
    139 
    140 
    141         // object is beneath the plane (ground)
    142         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
    143         else if( height < 0.0f )
     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)
    144147        {
    145148          entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
     
    160163
    161164
     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
    162187        // collision in the z-axis
    163       case COLLISION_TYPE_AXIS_Z:
    164 
    165         side = collPos.len()  - box->halfLength[2]; // should be [2]
    166 
    167         // object is beneath the plane (ground)
    168         if( side <= 0.0f )
    169         {
    170           entity->setAbsCoor(entity->getAbsCoor());
    171           Vector dirZ = entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();
    172           Vector backoff = dirZ * side;
    173           entity->shiftCoor(backoff);
    174         }
    175         // object is already in the wall
    176         else if( ce->isInWall())
    177         {
    178           entity->setAbsCoor(entity->getLastAbsCoor());
    179         }
    180         break;
    181        
    182        
    183          // collision in the z-axis
    184188      case COLLISION_TYPE_AXIS_Z_NEG:
    185189
    186         side = collPos.len()  - box->halfLength[2]; // should be [2]
    187 
    188         // object is beneath the plane (ground)
    189         if( side <= 0.0f )
    190         {
    191          
    192           Vector dirZ = entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();
    193           Vector backoff = dirZ * side*-1.0f;
     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;
    194199          entity->shiftCoor(backoff);
    195200        }
     
    209214
    210215
    211 #if 0
    212   if( box != NULL)
    213     height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ;
    214   else
    215     height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ;
    216 
    217 
    218   if( box != NULL)
    219   {
    220 
    221 
    222     if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
    223     {
    224       collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    225       return;
    226     }
    227     if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
    228     {
    229       collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    230       return;
    231     }
    232 
    233     if(ce->getGroundNormal().len() <= 0.1f)
    234     {
    235       collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    236       return;
    237     }
    238 
    239 
    240     if(ce->getGroundNormal().len() >= 1.4f)
    241     {
    242       downspeed++;
    243       collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
    244       return;
    245     }
    246 
    247 
    248     if(height.y > box->halfLength[1] + 0.0f ) // Above ground
    249     {
    250       if(height.y < box->halfLength[1] + 2.3f) // Snap in
    251       {
    252         downspeed = 0;
    253         collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() - Vector(0.0,height.y  - box->halfLength[1] - 0.0f,0.0));
    254       } else
    255       {
    256         downspeed++;
    257         collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
    258       }
    259 
    260     }
    261     else
    262     {
    263       if(height.y <  box->halfLength[1] + 0.0f   /* && height.y  >  - 55.0f*/) // below ground
    264       {
    265         //if(downspeed <= 0) downspeed =1;
    266         collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.y  +  box->halfLength[1] + 2.0f,0.0));
    267         //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
    268         downspeed = 0;
    269       }
    270 
    271     }
    272 
    273   }// if(box!= NULL)
    274 #endif
    275   /*
    276   PRINTF(0)("Collision with Ground: \n");
    277   collision->getEntityB()->getAbsCoor().debug();
    278   collision->getEntityB()->setVelocity(Vector());
    279   collision->getEntityB()->setAbsCoor(this->lastPositions[1]);
    280 
    281   */
    282216
    283217}
Note: See TracChangeset for help on using the changeset viewer.