Changeset 9517
- Timestamp:
- Dec 15, 2012, 2:41:57 PM (12 years ago)
- Location:
- code/branches/Racingbot/src/modules/gametypes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
r9513 r9517 42 42 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 43 43 44 44 45 namespace orxonox 45 46 { … … 57 58 ; std::vector<RaceCheckPoint*> checkpoints; 58 59 59 virtualCheckPointIndex =-2;60 for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)60 virtualCheckPointIndex = -2; 61 for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it) 61 62 { 62 63 checkpoints = it->getAllCheckpoints(); 63 nextRaceCheckpoint_ =it->findCheckpoint(0);64 nextRaceCheckpoint_ = it->findCheckpoint(0); 64 65 } 65 66 66 67 OrxAssert(!checkpoints.empty(), "No Checkpoints in Level"); 67 checkpoints_ =checkpoints;68 checkpoints_ = checkpoints; 68 69 /*orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl; 69 70 for(std::vector<RaceCheckPoint*>::iterator it=checkpoints_.begin(); it!=checkpoints_.end(); it++) … … 86 87 }//ausgabe*/ 87 88 88 for ( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it)89 for (std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it != checkpoints.end(); ++it) 89 90 { 90 91 std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints()); … … 124 125 125 126 int i; 126 for (i =-2; findCheckpoint(i)!= NULL; i--)127 for (i = -2; findCheckpoint(i) != NULL; i--) 127 128 { 128 129 continue; … … 140 141 XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f); 141 142 XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 142 143 143 } 144 144 … … 149 149 std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints) 150 150 { 151 std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoi t was reached (for simulation)151 std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoint was reached (for simulation) 152 152 for (unsigned int i = 0; i < allCheckpoints.size(); i++) 153 153 { … … 158 158 std::vector<RaceCheckPoint*> returnVec; 159 159 returnVec.clear(); 160 for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler->begin(); iter != zaehler->end(); iter++)160 for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler->begin(); iter != zaehler->end(); iter++) 161 161 { 162 162 if (iter->second == maxWays) … … 188 188 for (std::set<int>::iterator it = currentCheckpoint->getVirtualNextCheckpoints().begin(); it!= currentCheckpoint->getVirtualNextCheckpoints().end(); ++it) 189 189 { 190 if(currentCheckpoint ==findCheckpoint(*it))190 if(currentCheckpoint == findCheckpoint(*it)) 191 191 { 192 192 //orxout() << currentCheckpoint->getCheckpointIndex()<<endl; 193 193 continue; 194 194 } 195 if(findCheckpoint(*it)==NULL){orxout()<<"Problematic Point: "<<(*it)<<endl;} 195 if(findCheckpoint(*it) == NULL) 196 {orxout()<<"Problematic Point: "<<(*it)<<endl;} 196 197 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler); 197 198 } … … 219 220 RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint) 220 221 { 221 int distances[] = 222 { -1, -1, -1}; 222 int distances[] = {-1, -1, -1}; 223 223 int temp_i = 0; 224 224 for (std::set<int>::iterator it =raceCheckpoint->getVirtualNextCheckpoints().begin(); it!= raceCheckpoint->getVirtualNextCheckpoints().end(); ++it) … … 266 266 { 267 267 int minimum = std::numeric_limits<int>::max(); 268 for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it != currentCheckPoint->getVirtualNextCheckpoints().end(); ++it)268 for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it != currentCheckPoint->getVirtualNextCheckpoints().end(); ++it) 269 269 { 270 270 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length()); 271 271 272 minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(*it), currentCheckPoint->getPosition()));272 minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(*it), currentCheckPoint->getPosition())); 273 273 // minimum of distanz from 'currentPosition' to the next static Checkpoint 274 274 } … … 374 374 {//Checkpoint erreicht 375 375 376 currentRaceCheckpoint_ =nextRaceCheckpoint_;376 currentRaceCheckpoint_ = nextRaceCheckpoint_; 377 377 OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined"); 378 378 nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_); 379 lastPositionSpaceship =this->getControllableEntity()->getPosition();379 lastPositionSpaceship = this->getControllableEntity()->getPosition(); 380 380 //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl; 381 381 } … … 383 383 { 384 384 nextRaceCheckpoint_ = adjustNextPoint(); 385 lastPositionSpaceship =this->getControllableEntity()->getPosition();385 lastPositionSpaceship = this->getControllableEntity()->getPosition(); 386 386 } 387 387 388 388 // Abmessung fuer MINDISTANCE gut; 389 389 390 else if((lastPositionSpaceship -this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE )391 { 392 this->moveToPosition(Vector3(rnd()*100, rnd()*100,rnd()*100));390 else if((lastPositionSpaceship - this->getControllableEntity()->getPosition()).length()/dt < MINDISTANCE ) 391 { 392 this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100)); 393 393 this->spin(); 394 394 //orxout(user_status) << "Mindistance reached" << std::endl; … … 396 396 } 397 397 //orxout(user_status) << "dt= " << dt << "; distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl; 398 lastPositionSpaceship =this->getControllableEntity()->getPosition();398 lastPositionSpaceship = this->getControllableEntity()->getPosition(); 399 399 this->moveToPosition(nextRaceCheckpoint_->getPosition()); 400 400 } … … 403 403 bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse) 404 404 { 405 if(abs(pointToPoint.x) <groesse.x)406 return true;407 if(abs(pointToPoint.y) <groesse.y)408 return true;409 if(abs(pointToPoint.z) <groesse.z)410 return true;405 if(abs(pointToPoint.x) < groesse.x) 406 return true; 407 if(abs(pointToPoint.y) < groesse.y) 408 return true; 409 if(abs(pointToPoint.z) < groesse.z) 410 return true; 411 411 412 412 } … … 415 415 { 416 416 417 Vector3 cP1ToCP2 =(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector418 Vector3 centerCP1 =racepoint1->getPosition();417 Vector3 cP1ToCP2 = (racepoint2->getPosition() - racepoint1->getPosition()) / (racepoint2->getPosition() - racepoint1->getPosition()).length(); //unit Vector 418 Vector3 centerCP1 = racepoint1->getPosition(); 419 419 btVector3 positionObject; 420 420 btScalar radiusObject; 421 421 422 for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it !=allObjects.end(); ++it)423 { 424 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) !=0; everyShape++)422 for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it) 423 { 424 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++) 425 425 { 426 426 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape(); … … 441 441 } 442 442 443 void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, std::vector<StaticEntity*> allObjects)443 void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, std::vector<StaticEntity*> allObjects) 444 444 { 445 445 Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector … … 448 448 btScalar radiusObject; 449 449 450 for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it !=allObjects.end(); ++it)451 { 452 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) !=0; everyShape++)450 for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it) 451 { 452 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++) 453 453 { 454 454 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape(); … … 458 458 currentShape->getBoundingSphere(positionObject,radiusObject); 459 459 Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z()); 460 if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0) 461 { 462 Vector3 zufall; 463 Vector3 objectmiddle=positionObjectNonBT; 464 do 465 { 460 Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT); 461 462 if(norm_r_CP.length == 0){ 463 Vector3 zufall; 464 do{ 466 465 zufall=Vector3(rnd(),rnd(),rnd());//random 467 }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0); 468 469 Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition()); 470 // a'/b'=a/b => a' =b'*a/b 471 float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radiusObject*radiusObject)*radiusObject; 472 RaceCheckPoint* newVirtualCheckpoint=addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec); 473 //placeVirtualCheckpoints(newVirtualCheckpoint, racepoint2); 474 return; 475 } 476 466 }while((zufall.crossProduct(cP1ToCP2)).length() == 0); 467 norm_r_CP=zufall.crossProduct(cP1ToCP2); 468 } 469 Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2); 470 float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2)); 471 float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2)); 472 //TODO float distanz=max(distanzToCP1,distanzToCP2); 473 float distanz = 0.0f; //TEMPORARY 474 Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length(); 475 Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length(); 476 if((newCheckpointPositionPos-centerCP1).length+(newCheckpointPositionPos-(centerCP1+cP1ToCP2)).length < (newCheckpointPositionNeg-centerCP1).length+(newCheckpointPositionNeg-(centerCP1+cP1ToCP2)).length){ 477 RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos); 478 }else{ 479 RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg); 480 } 481 return; 477 482 } 478 483 } … … 489 494 { 490 495 491 if (dynamic_cast<RaceCheckPoint*>(*it) !=NULL)496 if (dynamic_cast<RaceCheckPoint*>(*it) != NULL) 492 497 { continue;} // does not work jet 493 498 -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
r9507 r9517 32 32 #include "gametypes/Gametype.h" 33 33 #include "gametypes/RaceCheckPoint.h" 34 #include "util/Math.h" 34 35 35 36 namespace orxonox
Note: See TracChangeset
for help on using the changeset viewer.