Changeset 8908
- Timestamp:
- Oct 26, 2011, 8:34:40 PM (13 years ago)
- Location:
- code/branches/formation/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/formation/src/orxonox/controllers/ArtificialController.cc
r8858 r8908 80 80 this->bShooting_ = false; 81 81 this->bHasTargetPosition_ = false; 82 this->bHasTargetOrientation_=false; 82 83 this->speedCounter_ = 0.2f; 83 84 this->targetPosition_ = Vector3::ZERO; … … 372 373 if (distance < 300) 373 374 { 375 if (bHasTargetOrientation_) 376 { 377 copyTargetOrientation(); 378 } 374 379 if (distance < 40) 375 380 { 376 381 this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER); 382 377 383 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 378 384 … … 385 391 { 386 392 this->positionReached(); 393 bHasTargetOrientation_=false; 387 394 } 388 395 } … … 391 398 { 392 399 this->moveToPosition(this->targetPosition_); 400 } 401 402 void ArtificialController::copyOrientation(const Quaternion& orient) 403 { 404 //roll angle in radian, difference between master and slave 405 float diff=orient.getRoll().valueRadians()-(this->getControllableEntity()->getOrientation().getRoll().valueRadians()); 406 if ((diff<math::twoPi && diff>math::pi) || diff>(math::pi)*3) 407 { 408 diff=diff-math::twoPi; 409 } 410 this->getControllableEntity()->rotateRoll(1.0f*ROTATEFACTOR_MASTER*diff); 411 } 412 413 void ArtificialController::copyTargetOrientation() 414 { 415 if (bHasTargetOrientation_) 416 { 417 copyOrientation(targetOrientation_); 418 } 393 419 } 394 420 … … 476 502 } 477 503 } 478 479 /** 504 /** 480 505 @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master. 481 506 */ 482 void ArtificialController::commandSlaves() 507 508 void ArtificialController::commandSlaves() 483 509 { 484 510 if(this->state_ != MASTER) return; … … 494 520 } 495 521 else 522 // formation: 496 523 { 497 524 dest += 1.0f*orient*WorldEntity::BACK; 498 525 Vector3 pos = Vector3::ZERO; 526 bool left=true; 499 527 int i = 1; 500 528 501 529 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 502 530 { 503 531 pos = Vector3::ZERO; 504 if (i <= 1) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::LEFT); 505 if (i == 2) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::RIGHT); 506 if (i == 3) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::UP); 507 if (i >= 4) 508 { 509 pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::DOWN); 510 i = 1; 511 dest += (float)FORMATION_LENGTH*(orient*WorldEntity::BACK); 512 (*it)->setTargetPosition(pos); 513 continue; 514 } 515 i++; 532 if (left) 533 { 534 pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::LEFT); 535 } else 536 { 537 pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::RIGHT); 538 i++; 539 dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK); 540 } 541 (*it)->setTargetOrientation(orient); 516 542 (*it)->setTargetPosition(pos); 543 left=!left; 517 544 } 518 545 } … … 819 846 this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000)); 820 847 this->bHasTargetPosition_ = true; 848 } 849 850 void ArtificialController::setTargetOrientation(const Quaternion& orient) 851 { 852 this->targetOrientation_=orient; 853 this->bHasTargetOrientation_=true; 854 } 855 856 void ArtificialController::setTargetOrientation(Pawn* target) 857 { 858 if (target) 859 setTargetOrientation(target->getOrientation()); 821 860 } 822 861 -
code/branches/formation/src/orxonox/controllers/ArtificialController.h
r8706 r8908 96 96 void moveToPosition(const Vector3& target); 97 97 void moveToTargetPosition(); 98 void copyOrientation(const Quaternion& orient); 99 void copyTargetOrientation(); 98 100 99 101 virtual void positionReached() {} … … 124 126 void searchRandomTargetPosition(); 125 127 128 void setTargetOrientation(const Quaternion& orient); 129 void setTargetOrientation(Pawn* target); 130 126 131 void setTarget(Pawn* target); 127 132 void searchNewTarget(); … … 138 143 bool bHasTargetPosition_; 139 144 Vector3 targetPosition_; 145 146 bool bHasTargetOrientation_; 147 Quaternion targetOrientation_; 148 140 149 WeakPtr<Pawn> target_; 141 150 bool bShooting_;
Note: See TracChangeset
for help on using the changeset viewer.