Changeset 9487 for code/branches/Racingbot/src/modules/gametypes
- Timestamp:
- Dec 3, 2012, 4:46:40 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
r9470 r9487 40 40 #include "core/XMLPort.h" 41 41 #include "gametypes/SpaceRaceManager.h" 42 #include "collisionshapes/CollisionShape.h" 43 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 42 44 43 45 namespace orxonox … … 53 55 ArtificialController(creator) 54 56 { 55 RegisterObject(SpaceRaceController) 56 ;std::vector<RaceCheckPoint*> checkpoints;57 RegisterObject(SpaceRaceController); 58 std::vector<RaceCheckPoint*> checkpoints; 57 59 for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it) 58 60 { … … 63 65 OrxAssert(!checkpoints.empty(), "No Checkpoints in Level"); 64 66 checkpoints_=checkpoints; 67 for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it){ 68 for (std::set<int>::iterator numb = ((*it)->getNextCheckpoints()).begin(); numb!=((*it)->getNextCheckpoints()).end(); ++numb) 69 placeVirtualCheckpoints((*it), findCheckpoint((*numb))); 70 } 65 71 staticRacePoints_ = findStaticCheckpoints(checkpoints); 66 72 // initialisation of currentRaceCheckpoint_ … … 247 253 } 248 254 249 bool SpaceRaceController::addVirtualCheckPoint(int positionInNextCheckPoint,RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition ){255 RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition ){ 250 256 251 257 RaceCheckPoint* newTempRaceCheckPoint = new RaceCheckPoint(this); … … 257 263 Vector3 temp = previousCheckpoint->getNextCheckpointsAsVector3(); 258 264 checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint); 265 int positionInNextCheckPoint; 266 for (int i = 0; i <3 ; i++){ 267 if(previousCheckpoint->getNextCheckpointsAsVector3()[i]==indexFollowingCheckPoint) 268 positionInNextCheckPoint=i; 269 } 259 270 switch(positionInNextCheckPoint){ 260 271 case 0: temp.x=virtualCheckPointIndex; break; … … 262 273 case 2: temp.z=virtualCheckPointIndex; break; 263 274 } 275 previousCheckpoint->setNextCheckpointsAsVector3(temp); 264 276 virtualCheckPointIndex--; 277 return newTempRaceCheckPoint; 265 278 } 266 279 … … 309 322 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 310 323 this->moveToPosition(nextRaceCheckpoint_->getPosition()); 311 312 313 ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); 314 /*if ( it->isA(RaceCheckPoint)){ 315 orxout(user_status) << "works" << std::endl; 316 } 317 /* 318 for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it) 319 { 320 if ((*it).isA(RaceCheckPoint)) 321 btVector3 temppos; 322 it-> 323 btScalar temppos; 324 btCollisionShape* temp= it->getCollisionShape(temppos, temppos); 325 it->get 326 327 } 328 */ 329 } 330 331 int SpaceRaceController::pointToPointDistance(Vector3 point1, Vector3 point2){ 324 } 325 326 // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse' 327 bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse){ 328 if(abs(pointToPoint.x)<groesse.x) 329 return true; 330 if(abs(pointToPoint.y)<groesse.y) 331 return true; 332 if(abs(pointToPoint.z)<groesse.z) 333 return true; 334 335 } 336 337 void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2){ 338 Vector3 point1 = racepoint1->getPosition(); 339 Vector3 point2 = racepoint2->getPosition(); 340 std::vector<StaticEntity*> problematicObjects; 341 332 342 for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it) 333 343 { 334 if ((*it).isA(RaceCheckPoint)){break;} // does not work jet 335 336 for (int i=0; it->getAttachedCollisionShape(i)!=0; i++){ 337 btVector3 temppos; 338 btScalar tempradius; 339 it->getAttachedCollisionShape(i)->getCollisionShape()->getCollisionShape(temppos,tempradius); 340 //http://bulletphysics.com/Bullet/BulletFull/btCollisionShape_8cpp_source.html#l00032 341 //ueber shape moegliche Hindernisse bestimmen 344 345 if (dynamic_cast<RaceCheckPoint*>(*it)!=NULL){continue;} // does not work jet 346 347 problematicObjects.insert(problematicObjects.end(), (*it)); 348 //it->getScale3D();// vector fuer halbe wuerfellaenge 349 } 350 Vector3 richtungen [6]; 351 richtungen[0]= Vector3(1,0,0); 352 richtungen[1]= Vector3(-1,0,0); 353 richtungen[2]= Vector3(0,1,0); 354 richtungen[3]= Vector3(0,-1,0); 355 richtungen[4]= Vector3(0,0,1); 356 richtungen[5]= Vector3(0,0,-1); 357 358 for (int i = 0; i< 6; i++){ 359 const int STEPS=100; 360 const float PHI=1.1; 361 bool collision=false; 362 363 for (float j =0; j<STEPS; j++){ 364 Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS); 365 for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it){ 366 btVector3 positionObject; 367 btScalar radiusObject; 368 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){ 369 (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject); 370 Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z()); 371 if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))){ 372 collision=true; break; 373 } 374 } 375 if(collision) break; 376 } 377 if(collision)break; 378 } 379 if(collision) continue; 380 // no collision => possible Way 381 for (float j =0; j<STEPS; j++){ 382 Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS); 383 collision=false; 384 for(float ij=0; ij<STEPS; j++){ 385 Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*ij/STEPS); 386 for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it){ 387 btVector3 positionObject; 388 btScalar radiusObject; 389 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){ 390 (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject); 391 Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z()); 392 if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))){ 393 collision=true; break; 394 } 395 } 396 if(collision) break; 342 397 } 343 it->getAttachedCollisionShape(i); 344 345 346 } 347 const int DeltaStrecke = 5; 348 for( int i=0; i*DeltaStrecke-5 < (point1-point2).length(); i++){ 349 return 0; 350 } 398 if(collision)break; 399 addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition); 400 return; 401 } 402 403 } 404 } 405 406 351 407 } 352 408 } -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
r9470 r9487 33 33 #include "gametypes/RaceCheckPoint.h" 34 34 35 36 35 namespace orxonox 37 36 { 38 class _GametypesExport SpaceRaceController : public ArtificialController, public Tickable 37 class _GametypesExport SpaceRaceController: public ArtificialController, 38 public Tickable 39 39 { 40 40 private: 41 41 std::vector<RaceCheckPoint*> staticRacePoints_; 42 RaceCheckPoint* nextRaceCheckpoint_; 42 RaceCheckPoint* nextRaceCheckpoint_; // checkpoint that should be reached 43 43 RaceCheckPoint* currentRaceCheckpoint_; // last checkPoint (already reached) 44 44 std::vector<RaceCheckPoint*> checkpoints_; … … 52 52 std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<RaceCheckPoint*>); 53 53 std::vector<RaceCheckPoint*> staticCheckpoints(); 54 int rekSimulationCheckpointsReached(RaceCheckPoint* , std::map<RaceCheckPoint*, int>*);54 int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>*); 55 55 // same as SpaceRaceManager, but needed to add virtuell Checkpoints ( Checkpoints which don't exist but needed to avoid collisions with big Objects) 56 56 RaceCheckPoint* findCheckpoint(int index) const; 57 bool addVirtualCheckPoint(int , RaceCheckPoint* , int , Vector3 ); 58 int pointToPointDistance(Vector3, Vector3); 57 RaceCheckPoint* addVirtualCheckPoint(RaceCheckPoint*, int , Vector3); 58 void placeVirtualCheckpoints(RaceCheckPoint*,RaceCheckPoint*); 59 bool vergleicheQuader(Vector3, Vector3); 59 60 60 61 public: 61 SpaceRaceController(BaseObject* creator);62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);63 virtual ~SpaceRaceController();64 virtual void tick(float dt);62 SpaceRaceController(BaseObject* creator); 63 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 64 virtual ~SpaceRaceController(); 65 virtual void tick(float dt); 65 66 }; 66 67 67 68 } 68 69 69 70 70 #endif /* SPACERACECONTROLLER_H_ */
Note: See TracChangeset
for help on using the changeset viewer.