Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 2, 2006, 1:36:13 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

File:
1 edited

Legend:

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

    r8894 r9003  
    2323#include "world_entity.h"
    2424#include "cr_physics_ground_walk.h"
     25#include "collision_reaction.h"
    2526
    2627#include <vector>
     
    5859void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
    5960{
    60   CollisionEvent* ce = collision->getCollisionEvents().front();
    61   Vector normal = ce->getGroundNormal();
    62   // normal.normalize();
    63 
    64   // put it back
    65   //   PRINTF(0)("putting it back to lastPos: \n");
    66   //   this->lastPositions[0].debug();
    67   //   PRINTF(0)("current pos:\n");
    68   //   collision->getEntityB()->getAbsCoor().debug();
    69 
    70   float height;
     61
    7162  AABB* box = collision->getEntityB()->getModelAABB();
    7263  WorldEntity* entity = collision->getEntityB();
    73 
    74   // collision position maths
    75   Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
    76 
    77   float CR_MAX_WALK_HEIGHT = 2.0f;
    78   float CR_THRESHOLD = 0.2f;
    7964
    8065  if( box == NULL)
     
    8570
    8671
    87   switch( ce->getType())
     72  float CR_MAX_WALK_HEIGHT = 2.0f;
     73  float CR_THRESHOLD = 0.2f;
     74
     75  float height = 0;
     76  float front = 0;
     77  float side = 0;
     78
     79  //PRINTF(0)("collision raction======================================\n");
     80
     81  const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
     82  std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
     83  for(; it != collisionEvents->end(); it++)
    8884  {
    89     case COLLISION_TYPE_AXIS_Y:
    90 
    91       height = collPos.y - box->halfLength[1];
    92      // PRINTF(0)("height: %f          , model height: %f\n", height, box->halfLength[1]);
    93      // PRINTF(0)(" ground normal: %f, %f, %f\n", normal.x, normal.y, normal.z);
    94 
    95       // object is beneath the plane (ground)
    96       if( height <= 0.0f )
    97       {
    98         entity->shiftCoor(Vector(0, -height, 0));
    99       }
    100       // object is already in the wall
    101       else if( ce->isInWall())
    102       {
    103         entity->setAbsCoor(entity->getLastAbsCoor());
    104       }
    105       break;
    106 
    107 
    108     case COLLISION_TYPE_AXIS_X:
    109     case COLLISION_TYPE_AXIS_Z:
    110       break;
    111 
    112     }
    113 
    114 
     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 x-axis
     96      case COLLISION_TYPE_AXIS_X:
     97        front = collPos.x - box->halfLength[0]; // should be [0]
     98
     99        // object is beneath the plane (ground)
     100        if( front <= 0.0f )
     101        {
     102          Vector backoff = entity->getAbsDirX() * front;
     103//           entity->shiftCoor(backoff);
     104        }
     105        // object is already in the wall
     106        else if( ce->isInWall())
     107        {
     108//           entity->setAbsCoor(entity->getLastAbsCoor());
     109        }
     110        break;
     111
     112
     113        // collision in the y-axis
     114      case COLLISION_TYPE_AXIS_Y:
     115        // calulate the height above ground
     116        height = collPos.y - box->halfLength[1];
     117
     118
     119        // object is beneath the plane (ground)
     120        if( height <= 0.0f )
     121        {
     122          entity->shiftCoor(Vector(0.0f, -height, 0.0f));
     123          entity->setOnGround(true);
     124        }
     125        // object is already in the wall
     126        else if( ce->isInWall())
     127        {
     128          entity->setAbsCoor(entity->getLastAbsCoor());
     129        }
     130        else
     131        {
     132          // entity is not on ground
     133          entity->setOnGround(false);
     134        }
     135        break;
     136
     137
     138        // collision in the z-axis
     139      case COLLISION_TYPE_AXIS_Z:
     140
     141        side = collPos.z - box->halfLength[2]; // should be [2]
     142
     143        // object is beneath the plane (ground)
     144        if( side <= 0.0f )
     145        {
     146          Vector backoff = entity->getAbsDirX() * side;
     147//           entity->shiftCoor(backoff);
     148        }
     149        // object is already in the wall
     150        else if( ce->isInWall())
     151        {
     152//           entity->setAbsCoor(entity->getLastAbsCoor());
     153        }
     154        break;
     155    }
     156  }
     157  //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
    115158
    116159
     
    126169
    127170
    128   if( box != NULL) {
    129 
    130 
    131     if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
     171  if( box != NULL)
     172  {
     173
     174
     175    if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
     176    {
    132177      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    133178      return;
    134179    }
    135     if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
     180    if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f)
     181    {
    136182      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    137183      return;
    138184    }
    139185
    140     if(ce->getGroundNormal().len() <= 0.1f) {
     186    if(ce->getGroundNormal().len() <= 0.1f)
     187    {
    141188      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    142189      return;
     
    144191
    145192
    146     if(ce->getGroundNormal().len() >= 1.4f) {
     193    if(ce->getGroundNormal().len() >= 1.4f)
     194    {
    147195      downspeed++;
    148196      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
     
    164212
    165213    }
    166     else {
     214    else
     215    {
    167216      if(height.y <  box->halfLength[1] + 0.0f   /* && height.y  >  - 55.0f*/) // below ground
    168217      {
     
    194243 */
    195244void CRPhysicsGroundWalk::update(WorldEntity* owner)
    196 {
    197 
    198 }
    199 
    200 
     245{}
     246
     247
Note: See TracChangeset for help on using the changeset viewer.