Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 15, 2006, 2:57:44 PM (18 years ago)
Author:
bottac
Message:

Ground Collision fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc

    r8456 r8468  
    5050BspManager::BspManager(WorldEntity* parent)
    5151{
    52   this->outputStartsOut = true;
    53   this->outputAllSolid = false;
    54   this->outputFraction = 1.0f;
     52 
    5553  this->parent = parent;
    5654  /*// open a BSP file
     
    595593  float startFraction = -1.0f;
    596594  float endFraction = 1.0f;
    597   bool startsOut = false;
    598   bool endsOut = false;
    599 
    600   Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
    601   Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
     595  bool  startsOut = false;
     596  bool  endsOut = false;
     597
     598 // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
     599 // Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
     600
     601  for (int i = 0; i < curBrush->n_brushsides; i++) {
     602    brushside& curBrushSide =   this->bspFile->brushSides[curBrush->brushside + i]   ;
     603    plane& curPlane  =   this->bspFile->planes[curBrushSide.plane] ;
     604
     605    startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d;
     606    endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d;
     607
     608    if (startDistance > 0)
     609      startsOut = true;
     610    if (endDistance > 0)
     611      endsOut = true;
     612
     613    // make sure the trace isn't completely on one side of the brush
     614    if (startDistance > 0 && endDistance > 0) {   // both are in front of the plane, its outside of this brush
     615      return;
     616    }
     617    if (startDistance <= 0 && endDistance <= 0) {   // both are behind this plane, it will get clipped by another one
     618      continue;
     619    }
     620
     621    // MMM... BEEFY
     622    if (startDistance > endDistance) {   // line is entering into the brush
     623      float fraction = (startDistance - EPSILON) / (startDistance - endDistance);  // *
     624      if (fraction > startFraction)
     625        startFraction = fraction;
     626      // store plane
     627      this->collPlane = &curPlane;
     628
     629    } else {   // line is leaving the brush
     630      float fraction = (startDistance + EPSILON) / (startDistance - endDistance);  // *
     631      if (fraction < endFraction)
     632        endFraction = fraction;
     633      // store plane
     634      this->collPlane = & curPlane;
     635
     636    }
     637
     638  }
     639  if (startsOut == false) {
     640    this->outputStartsOut = false;
     641    if (endsOut == false)
     642      this->outputAllSolid = true;
     643    return;
     644  }
     645
     646  if (startFraction < endFraction) {
     647    if (startFraction > -1.0f && startFraction < outputFraction) {
     648      if (startFraction < 0)
     649        startFraction = 0;
     650      this->outputFraction = startFraction;
     651    }
     652  }
     653
     654}
     655
     656void BspManager::checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd)
     657{
     658  float EPSILON = 0.000001;
     659  float startDistance;
     660  float endDistance;
     661
     662  float startFraction = -1.0f;
     663  float endFraction = 1.0f;
     664  bool  startsOut = false;
     665  bool  endsOut = false;
     666
     667  //Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();
     668  //Vector inputEnd   = State::getCameraTargetNode()->getAbsCoor();
    602669
    603670  for (int i = 0; i < curBrush->n_brushsides; i++) {
     
    870937void BspManager::checkCollision(WorldEntity* worldEntity)
    871938{
    872   Vector position = worldEntity->getLastAbsCoor();
     939 
     940  this->outputStartsOut = true;
     941  this->outputAllSolid = false;
     942  this->outputFraction = 1.0f;
     943 
     944  Vector position = worldEntity->getAbsCoor();
    873945
    874946
     
    877949
    878950  Vector upDir = worldEntity->getAbsDirY();
    879   Vector dest = position;
     951  upDir.x = 0.0;
     952  upDir.y = 1.0;
     953  upDir.z = 0.0;
     954  Vector dest;
    880955  /*
    881956  dest.x  += forwardDir.x;
     
    884959  */
    885960
    886   dest = worldEntity->getAbsCoor();
     961  dest = worldEntity->getAbsCoor() - upDir*40.0;
    887962  Vector out = dest;
    888963
     
    901976
    902977  float height = 40;
    903   this->outputAllSolid = false;
    904 
     978 
     979  this->inputStart =  position;
     980  this->inputEnd =   dest;
    905981  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
    906982
    907983  PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
     984  PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
     985  PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z); 
    908986//   position1.debug();
    909987
Note: See TracChangeset for help on using the changeset viewer.