Exemplo n.º 1
0
Point3F BtPlayer::move( const VectorF &disp, CollisionList &outCol )
{
   AssertFatal( mGhostObject, "BtPlayer::move - The controller is null!" );

   // First recover from any penetrations from the previous tick.
   U32 numPenetrationLoops = 0;
   bool touchingContact = false;
   while ( _recoverFromPenetration() )
   {
      numPenetrationLoops++;
      touchingContact = true;
      if ( numPenetrationLoops > 4 )
         break;
   }

   btTransform newTrans = mGhostObject->getWorldTransform();
   btVector3 newPos = newTrans.getOrigin();

   // The move consists of 3 steps... the up step, the forward 
   // step, and the down step.

   btVector3 forwardSweep( disp.x, disp.y, 0.0f );
   const bool hasForwardSweep = forwardSweep.length2() > 0.0f;
   F32 upSweep = 0.0f;
   F32 downSweep = 0.0f;
	if ( disp[2] < 0.0f )
      downSweep = disp[2];
	else								
      upSweep = disp[2];

	// Only do auto stepping if the character is moving forward.
   F32 stepOffset = mStepHeight;
	if ( hasForwardSweep )
		upSweep += stepOffset;

   // First we do the up step which includes the passed in
   // upward displacement as well as the auto stepping.
   if (  upSweep > 0.0f &&
         _sweep( &newPos, btVector3( 0.0f, 0.0f, upSweep ), NULL ) )
   {
      // Keep track of how far we actually swept to make sure
      // we do not remove too much in the down sweep.
		F32 delta = newPos[2] - newTrans.getOrigin()[2];
		if ( delta < stepOffset )
			stepOffset = delta;
   }

   // Now do the forward step.
   _stepForward( &newPos, forwardSweep, &outCol );

   // Now remove what remains of our auto step 
   // from the down sweep.
	if ( hasForwardSweep )
		downSweep -= stepOffset;

   // Do the downward sweep.
   if ( downSweep < 0.0f )
      _sweep( &newPos, btVector3( 0.0f, 0.0f, downSweep ), &outCol );

   // Finally update the ghost with its new position.
	newTrans.setOrigin( newPos );
	mGhostObject->setWorldTransform( newTrans );

   // Return the current position of the ghost.
   newPos[2] -= mOriginOffset;
   return btCast<Point3F>( newPos );
}
Exemplo n.º 2
0
Route* routeCalculate(int sid1, int sid2, List* stations, List* links)
{
    Station** stationsArray = (Station**)stations->data;
    double* map = (double*)calloc(stations->count, sizeof(double));

    for (int i = 0; i < stations->count; i++) 
    {
        map[i] = -1;
    }

    int found = false;
    int step = false;
    List* currentStations = listNew();
    List* nextStations = listNew();
    listAdd(currentStations, stationsArray[sid2]);
    map[sid2] = 0;


    while (true)
    {
        listClear(nextStations);
        step = false;
        for (int j = 0; j < currentStations->count; j++)
        {
            Station* current = (Station*)currentStations->data[j];

            for (int l = 0; l < current->srtLids->count; l++)
            {
                Link* link = (Link*)current->srtLids->data[l];
                _stepBack(current, link, link->sid2, sid1, map, stationsArray, nextStations, &step, &found);
            }

            for (int l = 0; l < current->endLids->count; l++)
            {
                Link* link = (Link*)current->endLids->data[l];
                _stepBack(current, link, link->sid1, sid1, map, stationsArray, nextStations, &step, &found);
            }
        }
        if (!found && !step) break;

        if (found && nextStations->count == 0) break;
        listClear(currentStations);
        for (int l = 0; l < nextStations->count; l++)
        {
            listAdd(currentStations, nextStations->data[l]);
        }
    }

    listFree(currentStations);
    listFree(nextStations);

    Route* result = NULL;

    if (found)
    {
        found = false;
        Link* nextLink = NULL;
        Station* nextStation = stationsArray[sid1];
        double minval = map[sid1];

        while (!found)
        {
            Station* cursid = nextStation;
            step = false;

            for (int l = 0; l < cursid->srtLids->count; l++)
            {
                Link* link = (Link*)cursid->srtLids->data[l];
                _stepForward(cursid, link, link->sid2, sid2, map, stationsArray, &nextStation, &nextLink, &minval, &step, &found);
            }

            for (int l = 0; l < cursid->endLids->count; l++)
            {
                Link* link = (Link*)cursid->endLids->data[l];
                _stepForward(cursid, link, link->sid1, sid2, map, stationsArray, &nextStation, &nextLink, &minval, &step, &found);
            }

            if (!found && !step) return NULL;

            if (result == NULL)
            { 
                result = _routeNew(stationsArray[sid1]);
            }
            
            result->length += nextLink->len;
            listAdd(result->stations, nextStation);
            listAdd(result->links, nextLink);

            if (found) return result;
        }
    
    }

    routeFree(&result);
    free(map);

    return NULL;
}