Changeset 9188
- Timestamp:
- May 18, 2012, 1:54:37 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/newlevel2012/src/orxonox/controllers/FormationController.cc
r9016 r9188 272 272 } 273 273 274 Vector2 coord = get2DView direction(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);274 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 275 275 float distance = (target - this->getControllableEntity()->getPosition()).length(); 276 276 if(coord.x < 0.0001 && coord.y < 0.0001) 277 { 278 // if the ship reaches a direction very close to the direct one, set it to the direct one 279 Vector3 v_temp = this->getControllableEntity()->getPosition(); 280 Quaternion quat = v_temp.getRotationTo(target); 281 this->getControllableEntity()->rotate(quat); 282 } 277 283 278 284 if(this->state_ == FREE) … … 281 287 { 282 288 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 283 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);284 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);285 } 286 287 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())289 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * coord.x * 2); 290 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * coord.y * 2); 291 } 292 293 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 288 294 { 289 295 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance … … 297 303 if (this->target_ || distance > 10) 298 304 { 299 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);300 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);305 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * coord.x * 2); 306 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * coord.y * 2); 301 307 } 302 308 … … 310 316 311 317 if(this->state_ == SLAVE) 312 313 314 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);315 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);316 317 318 319 320 321 copyTargetOrientation();322 323 324 {//linear speed reduction325 326 327 328 329 330 331 332 318 { 319 320 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * coord.x * 2); 321 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * coord.y * 2); 322 323 if (distance < 300) 324 { 325 if (bHasTargetOrientation_) 326 { 327 copyTargetOrientation(); 328 } 329 if (distance < 100) 330 { //linear speed reduction 331 this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER); 332 333 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 334 335 } else { 336 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 337 } 338 } 333 339 334 340 if (distance < 10) … … 383 389 void FormationController::searchNewMaster() 384 390 { 385 if (this->state_==SLAVE) 391 if (this->state_==SLAVE) 386 392 return; 387 393 if (!this->getControllableEntity()) … … 394 400 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 395 401 { 396 402 397 403 //same team? 398 404 Gametype* gt=this->getGametype(); … … 479 485 bool left=true; 480 486 int i = 1; 481 487 482 488 for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 483 489 { … … 490 496 i++; 491 497 dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK); 492 } 498 } 493 499 (*it)->setTargetOrientation(orient); 494 500 (*it)->setTargetPosition(pos); … … 599 605 600 606 if (this->state_==SLAVE) //become master of this formation 601 { 607 { 602 608 this->slaves_=this->myMaster_->slaves_; 603 609 this->myMaster_->slaves_.clear(); 604 610 this->myMaster_->state_=SLAVE; 605 611 this->myMaster_->myMaster_=this; 606 612 607 613 //delete myself in slavelist 608 614 std::vector<FormationController*>::iterator it2 = std::find(this->slaves_.begin(), this->slaves_.end(), this); … … 647 653 if (i>=slaves_.size()/2) break; //half the formation should attack. 648 654 } 649 } 655 } 650 656 651 657 … … 860 866 void FormationController::setTargetOrientation(const Quaternion& orient) 861 867 { 862 this->targetOrientation_=orient; 868 this->targetOrientation_=orient; 863 869 this->bHasTargetOrientation_=true; 864 870 }
Note: See TracChangeset
for help on using the changeset viewer.