Changeset 11965 for code/branches/RacingBots_FS18/src
- Timestamp:
- May 17, 2018, 2:29:38 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRaceController.cc
r11913 r11965 30 30 #include "collisionshapes/CollisionShape.h" 31 31 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 32 #include "SpaceRace.h" 32 33 33 34 … … 38 39 const int ADJUSTDISTANCE = 500; 39 40 const int MINDISTANCE = 5; 41 40 42 /* 41 43 * Idea: Find static Point (checkpoints the spaceship has to reach) … … 45 47 { 46 48 RegisterObject(SpaceRaceController); 49 //this->parentRace = nullptr; 50 47 51 std::vector<RaceCheckPoint*> checkpoints; 48 52 … … 122 126 for (int checkpointIndex : currentCheckpoint->getNextCheckpoints()) 123 127 { 128 if (findCheckpoint(checkpointIndex) == nullptr){ 129 orxout(internal_warning) << "Problematic Point: " << checkpointIndex << endl; 130 } 124 131 if (currentCheckpoint == findCheckpoint(checkpointIndex)) 125 132 { … … 127 134 continue; 128 135 } 129 if (findCheckpoint(checkpointIndex) == nullptr){ 130 orxout(internal_warning) << "Problematic Point: " << checkpointIndex << endl; 131 } 136 132 137 else 133 138 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(checkpointIndex), zaehler); … … 170 175 minDistance = distance; 171 176 minNextRaceCheckPoint = nextRaceCheckPoint; 172 } 173 174 } 175 if(minNextRaceCheckPoint==nullptr){orxout()<<"minNextRaceCheckPoint=nullpointer line 175 SpaceRaceController index: "<<endl;} 177 178 } 179 180 } 181 if(minNextRaceCheckPoint == nullptr) orxout()<<"nullptr found @181 SpaceRaceController" << endl; 176 182 return minNextRaceCheckPoint; 177 183 } … … 210 216 211 217 { 218 if(nextRaceCheckpoint_ == nullptr) orxout()<<"nullptr found @218 SpaceRaceController" << endl; 219 212 220 return nextRaceCheckpoint_; 213 221 } … … 215 223 216 224 { 225 if(nextRaceCheckpoint_ == nullptr) orxout()<<"nullptr found @223 SpaceRaceController" << endl; 226 217 227 return nextRaceCheckpoint_; 218 228 } … … 226 236 { 227 237 for (RaceCheckPoint* checkpoint : this->checkpoints_){ 228 if (checkpoint->getCheckpointIndex() == index) 238 //conclusion: index=20 is not 239 if (checkpoint->getCheckpointIndex() == index){ 240 if(checkpoint == nullptr) orxout()<<"returned nullptr @line 234 SpaceRaceController"<<endl; 229 241 return checkpoint; 230 231 } 232 233 orxout()<<"returned nullptr @line 231 SpaceRaceController"<<endl; 242 } 243 } 244 234 245 return nullptr; 235 246 } 247 248 /*RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , const Vector3& virtualCheckPointPosition ) 249 { 250 orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl; 251 RaceCheckPoint* newTempRaceCheckPoint; 252 ObjectList<SpaceRaceManager> list; 253 for (ObjectList<SpaceRaceManager>::iterator it = list.begin(); it!= list.end(); ++it) 254 { 255 newTempRaceCheckPoint = new RaceCheckPoint((*it)); 256 } 257 newTempRaceCheckPoint->setVisible(false); 258 newTempRaceCheckPoint->setPosition(virtualCheckPointPosition); 259 newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex); 260 newTempRaceCheckPoint->setLast(false); 261 newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1)); 262 263 Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3(); 264 //orxout()<<"temp bei 0: ="<< temp.x<< temp.y<< temp.z<<endl; 265 checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint); 266 int positionInNextCheckPoint; 267 for (int i = 0; i <3; i++) 268 { 269 if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint) 270 positionInNextCheckPoint=i; 271 } 272 switch(positionInNextCheckPoint) 273 { 274 case 0: temp.x=virtualCheckPointIndex; break; 275 case 1: temp.y=virtualCheckPointIndex; break; 276 case 2: temp.z=virtualCheckPointIndex; break; 277 } 278 previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint 279 virtualCheckPointIndex--; 280 //orxout()<<"temp bei 1: ="<< temp.x<< temp.y<< temp.z<<endl; 281 //orxout()<<"temp nach ausgabe: "<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().x<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().y<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().z<<endl; 282 //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp"); 283 orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" : "<<temp.x<<", "<<temp.y<<", "<<temp.z<<"; "; 284 temp=previousCheckpoint->getNextCheckpointsAsVector3(); 285 orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<": "<<temp.x<<", "<<temp.y<<", "<<temp.z<<"; "; 286 orxout()<<endl; 287 return newTempRaceCheckPoint; 288 }*/ 236 289 237 290 SpaceRaceController::~SpaceRaceController() … … 276 329 { 277 330 nextRaceCheckpoint_ = adjustNextPoint(); 331 if(nextRaceCheckpoint_ == nullptr) orxout()<<"nullptr found @327 SpaceRaceController" << endl; 332 278 333 lastPositionSpaceship = this->getControllableEntity()->getPosition(); 279 334 } … … 285 340 this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100)); 286 341 this->spin(); 287 orxout(user_status) << "Mindistance reached" << std::endl;342 //orxout(user_status) << "Mindistance reached" << std::endl; 288 343 return; 289 344 } 290 345 //orxout(user_status) << "dt= " << dt << "; distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl; 291 lastPositionSpaceship = this->getControllableEntity()->getPosition(); 292 346 /*lastPositionSpaceship = this->getControllableEntity()->getPosition(); 347 348 SpaceRace obj=new SpaceRace(); 349 obj.setParentRace(parentRace); 350 this->parentRace=obj.parentRace;*/ 351 293 352 this->boostControl(); 294 if (nextRaceCheckpoint_ == nullptr) orxout() << "nextRaceCheckpoint_ equals to nullpointer look @line 334 SpaceRaceController.cc" << endl; 353 354 /*if(nextRaceCheckpoint_ == nullptr){ 355 this->parentRace->bLost=true; 356 this->parentRace->end(); 357 }*/ 358 // if(nextRaceCheckpoint_ == nullptr ){ 359 // // if( nextRaceCheckpoint_->getCheckpointIndex()==19) 360 // orxout()<<"nullptr @351 Line"<<endl; 361 // } 362 295 363 this->moveToPosition(nextRaceCheckpoint_->getPosition()); 364 296 365 this->boostControl(); 297 366 } 298 367 368 369 /*void SpaceRaceController::setParentRace(parentRace){ 370 this->parentRace=parentRace; 371 }*/ 299 372 // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse' 300 373 bool SpaceRaceController::vergleicheQuader(const Vector3& pointToPoint, const Vector3& groesse) … … 338 411 339 412 } 413 414 /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects) 415 { 416 Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector 417 Vector3 centerCP1=racepoint1->getPosition(); 418 btVector3 positionObject; 419 btScalar radiusObject; 420 421 for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it) 422 { 423 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != nullptr; everyShape++) 424 { 425 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape(); 426 if(currentShape == nullptr) 427 continue; 428 429 currentShape->getBoundingSphere(positionObject,radiusObject); 430 Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z()); 431 Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT); 432 433 if(norm_r_CP.length() == 0){ 434 Vector3 zufall; 435 do{ 436 zufall=Vector3(rnd(),rnd(),rnd());//random 437 }while((zufall.crossProduct(cP1ToCP2)).length() == 0); 438 norm_r_CP=zufall.crossProduct(cP1ToCP2); 439 } 440 Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2); 441 float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2)); 442 float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2)); 443 float distanz = std::max(distanzToCP1,distanzToCP2); 444 //float distanz = 0.0f; //TEMPORARY 445 Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length(); 446 Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length(); 447 if((newCheckpointPositionPos - centerCP1).length() + (newCheckpointPositionPos - (centerCP1+cP1ToCP2)).length() < (newCheckpointPositionNeg - centerCP1).length() + (newCheckpointPositionNeg - (centerCP1+cP1ToCP2)).length() ) 448 { 449 RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos); 450 } 451 else 452 { 453 RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg); 454 } 455 return; 456 } 457 } 458 459 }*/ 460 461 /*void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2) 462 { 463 Vector3 point1 = racepoint1->getPosition(); 464 Vector3 point2 = racepoint2->getPosition(); 465 std::vector<StaticEntity*> problematicObjects; 466 467 ObjectList<StaticEntity> list; 468 for (ObjectList<StaticEntity>::iterator it = list.begin(); it!= list.end(); ++it) 469 { 470 471 if (dynamic_cast<RaceCheckPoint*>(*it) != nullptr) 472 { 473 continue; 474 } // does not work jet 475 476 problematicObjects.insert(problematicObjects.end(), *it); 477 //it->getScale3D();// vector fuer halbe wuerfellaenge 478 } 479 480 if(!directLinePossible(racepoint1, racepoint2, problematicObjects)) 481 { 482 //orxout()<<"From "<<racepoint1->getCheckpointIndex()<<" to "<<racepoint2->getCheckpointIndex()<<"produces: "<< virtualCheckPointIndex<<endl; 483 computeVirtualCheckpoint(racepoint1, racepoint2, problematicObjects); 484 } 485 486 // 487 // do{ 488 // zufall=Vector3(rnd(),rnd(),rnd());//random 489 // }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0); 490 // 491 // Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition()); 492 // // a'/b'=a/b => a' =b'*a/b 493 // float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radius*radius)*radius; 494 // addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec); 495 496 // Vector3 richtungen [6]; 497 // richtungen[0]= Vector3(1,0,0); 498 // richtungen[1]= Vector3(-1,0,0); 499 // richtungen[2]= Vector3(0,1,0); 500 // richtungen[3]= Vector3(0,-1,0); 501 // richtungen[4]= Vector3(0,0,1); 502 // richtungen[5]= Vector3(0,0,-1); 503 // 504 // for (int i = 0; i< 6; i++) 505 // { 506 // const int STEPS=100; 507 // const float PHI=1.1; 508 // bool collision=false; 509 // 510 // for (int j =0; j<STEPS; j++) 511 // { 512 // Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*(float)j/STEPS); 513 // for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it) 514 // { 515 // btVector3 positionObject; 516 // btScalar radiusObject; 517 // if((*it)==nullptr) 518 // { orxout()<<"Problempoint 1.1"<<endl; continue;} 519 // //TODO: Probably it points on a wrong object 520 // for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++) 521 // { 522 // if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr) 523 // { continue;} 524 // 525 // orxout()<<"Problempoint 2.1"<<endl; 526 // (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject); 527 // Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z()); 528 // if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))) 529 // { 530 // collision=true; break; 531 // } 532 // } 533 // if(collision) break; 534 // } 535 // if(collision)break; 536 // } 537 // if(collision) continue; 538 // // no collision => possible Way 539 // for (float j =0; j<STEPS; j++) 540 // { 541 // Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS); 542 // collision=false; 543 // for(int ij=0; ij<STEPS; j++) 544 // { 545 // Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*(float)ij/STEPS); 546 // for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it) 547 // { 548 // btVector3 positionObject; 549 // btScalar radiusObject; 550 // if((*it)==nullptr) 551 // { orxout()<<"Problempoint 1"<<endl; continue;} 552 // for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++) 553 // { 554 // if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr) 555 // { orxout()<<"Problempoint 2.2"<<endl; continue;} 556 // (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject); 557 // Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z()); 558 // if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))) 559 // { 560 // collision=true; break; 561 // } 562 // } 563 // if(collision) break; 564 // } 565 // if(collision)break; 566 // //addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition); 567 // return; 568 // } 569 // 570 // } 571 // } 572 573 }*/ 340 574 }
Note: See TracChangeset
for help on using the changeset viewer.