Changeset 6377 for code/branches
- Timestamp:
- Dec 18, 2009, 12:29:54 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc
r6376 r6377 34 34 #include <OgreCamera.h> 35 35 #include <OgreSceneManager.h> 36 #include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> 36 37 37 38 #include "core/CoreIncludes.h" … … 43 44 #include "graphics/Camera.h" 44 45 #include "sound/SoundManager.h" 46 #include "tools/BulletConversions.h" 45 47 #include "Scene.h" 46 #include "tools/BulletConversions.h"47 #include "bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"48 48 49 49 namespace orxonox 50 50 { 51 SetConsoleCommand(NewHumanController, changeMode, 52 SetConsoleCommand(NewHumanController, accelerate, 53 SetConsoleCommand(NewHumanController, decelerate, 54 SetConsoleCommand(NewHumanController, unfire, 51 SetConsoleCommand(NewHumanController, changeMode, false).keybindMode(KeybindMode::OnPress); 52 SetConsoleCommand(NewHumanController, accelerate, false).keybindMode(KeybindMode::OnPress); 53 SetConsoleCommand(NewHumanController, decelerate, false).keybindMode(KeybindMode::OnPress); 54 SetConsoleCommand(NewHumanController, unfire, true).keybindMode(KeybindMode::OnRelease); 55 55 56 56 CreateUnloadableFactory(NewHumanController); … … 102 102 centerOverlay_->setBackgroundMaterial("Orxonox/CenterOverlay"); 103 103 centerOverlay_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); 104 centerOverlay_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); \104 centerOverlay_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); 105 105 centerOverlay_->hide(); 106 106 107 if ( showDamageOverlay_)107 if (showDamageOverlay_) 108 108 { 109 109 damageOverlayTop_ = new OrxonoxOverlay(this); 110 110 damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop"); 111 111 damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); 112 damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); \112 damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); 113 113 damageOverlayTop_->hide(); 114 114 … … 116 116 damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight"); 117 117 damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); 118 damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); \118 damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); 119 119 damageOverlayRight_->hide(); 120 120 … … 122 122 damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom"); 123 123 damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); 124 damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); \124 damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); 125 125 damageOverlayBottom_->hide(); 126 126 … … 128 128 damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft"); 129 129 damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); 130 damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); \130 damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0)); 131 131 damageOverlayLeft_->hide(); 132 132 } 133 133 134 if ( showArrows_)134 if (showArrows_) 135 135 { 136 136 arrowsOverlay1_ = new OrxonoxOverlay(this); … … 173 173 controlPaused_ = false; 174 174 175 //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true);175 //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true); 176 176 } 177 177 … … 204 204 { 205 205 206 if ( this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())206 if (this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) 207 207 { 208 208 this->updateTarget(); 209 209 210 if ( !controlPaused_ ) { 211 if (this->getControllableEntity() && (this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket")) 210 if (!controlPaused_ ) 211 { 212 if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket")))) 212 213 this->showOverlays(); 213 214 214 215 this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2)); 215 216 216 if ( this->controlMode_ == 0 || ( this->controlMode_ == 1 && this->firemode_ == 1 ))217 if (this->controlMode_ == 0 || (this->controlMode_ == 1 && this->firemode_ == 1)) 217 218 { 218 if ( 219 if (this->showOverlays_ && this->showArrows_) 219 220 alignArrows(); 220 221 } … … 222 223 hideArrows(); 223 224 224 if ( this->showDamageOverlay_ && ( this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0 ) ) { 225 if (this->showDamageOverlay_ && (this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0)) 226 { 225 227 this->damageOverlayTT_ -= dt; 226 228 this->damageOverlayTR_ -= dt; 227 229 this->damageOverlayTB_ -= dt; 228 230 this->damageOverlayTL_ -= dt; 229 if ( this->damageOverlayTT_ <= 0)231 if (this->damageOverlayTT_ <= 0) 230 232 this->damageOverlayTop_->hide(); 231 if ( this->damageOverlayTR_ <= 0)233 if (this->damageOverlayTR_ <= 0) 232 234 this->damageOverlayRight_->hide(); 233 if ( this->damageOverlayTB_ <= 0)235 if (this->damageOverlayTB_ <= 0) 234 236 this->damageOverlayBottom_->hide(); 235 if ( this->damageOverlayTL_ <= 0)237 if (this->damageOverlayTL_ <= 0) 236 238 this->damageOverlayLeft_->hide(); 237 239 } … … 241 243 this->hideOverlays(); 242 244 243 if ( this->acceleration_ > 0 ) 244 { 245 /* 246 if (this->controllableEntity_ && this->controllableEntity_->getEngine()) { 247 std::cout << this->controllableEntity_->getEngine()->getAccelerationFront() << endl; 248 } 249 */ 250 if ( this->accelerating_ ) 245 if (this->acceleration_ > 0) 246 { 247 if (this->accelerating_) 251 248 HumanController::moveFrontBack(Vector2(1, 0)); 252 249 else … … 265 262 } 266 263 267 /*void NewHumanController::tick(float dt)268 {269 if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_)270 {271 // Update sound listener272 Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera();273 if (camera)274 {275 SoundManager::getInstance().setListenerPosition(camera->getWorldPosition());276 SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation());277 }278 else279 COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl;280 }281 }*/282 283 264 void NewHumanController::doFire(unsigned int firemode) 284 265 { 285 if ( !this->controllableEntity_)266 if (!this->controllableEntity_) 286 267 return; 287 //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) {288 289 /*290 // Get results, create a node/entity on the position291 for ( itr = result.begin(); itr != result.end(); itr++ )292 {293 if (itr->movable && itr->movable->getName() == "Head")294 {295 soundMgr->StopSound( &jaguarSoundChannel );296 soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );297 break;298 } // if299 }300 */301 268 302 269 this->firemode_ = firemode; … … 313 280 } 314 281 315 void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) { 316 if ( this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook() ) { 282 void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) 283 { 284 if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) 285 { 317 286 Vector3 posA; 318 if ( originator)287 if (originator) 319 288 posA = originator->getWorldPosition(); 320 289 else … … 329 298 //y is down positive 330 299 relativeHit.normalise(); 331 // COUT(0) << relativeHit << endl;332 300 333 301 float threshold = 0.3; 334 // && abs(relativeHit.y) < 0.5 335 if ( relativeHit.x > threshold) // Left 302 if (relativeHit.x > threshold) // Left 336 303 { 337 304 this->damageOverlayLeft_->show(); … … 339 306 //this->damageOverlayLeft_->setBackgroundAlpha(0.3); 340 307 } 341 if ( 308 if (relativeHit.x < -threshold) //Right 342 309 { 343 310 this->damageOverlayRight_->show(); … … 345 312 //this->damageOverlayRight_->setBackgroundAlpha(0.3); 346 313 } 347 if ( 314 if (relativeHit.y > threshold) //Top 348 315 { 349 316 this->damageOverlayBottom_->show(); … … 351 318 //this->damageOverlayTop_->setBackgroundAlpha(0.3); 352 319 } 353 if ( 320 if (relativeHit.y < -threshold) //Bottom 354 321 { 355 322 this->damageOverlayTop_->show(); … … 357 324 //this->damageOverlayBottom_->setBackgroundAlpha(0.3); 358 325 } 359 360 326 } 361 327 } … … 403 369 if (wePtr) 404 370 { 405 // go through all parents of object and look whet er they are Sightable or not371 // go through all parents of object and look whether they are sightable or not 406 372 bool isSightable = false; 407 373 WorldEntity* parent = wePtr->getParent(); 408 while ( parent)374 while (parent) 409 375 { 410 376 if (this->targetMask_.isExcluded(parent->getIdentifier())) … … 419 385 } 420 386 } 421 if ( !isSightable)387 if (!isSightable) 422 388 continue; 423 389 } 424 390 425 if ( this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr ) 426 { 391 if (this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr) 427 392 this->getControllableEntity()->setTarget(wePtr); 428 } 429 430 if( pawn ) 431 { 393 394 if (pawn) 432 395 pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance ); 433 }434 396 435 397 //itr->movable->getParentSceneNode()->showBoundingBox(true); 436 //std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;437 398 //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition() 438 399 return; 439 400 } 440 441 } 442 if ( pawn ) 443 { 401 } 402 403 if (pawn) 444 404 pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 ); 445 }446 405 447 406 if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0 ) 448 407 this->getControllableEntity()->setTarget( 0 ); 449 450 408 451 409 //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000); … … 458 416 459 417 //if (this->acceleration_ == 0) 460 418 HumanController::frontback(value); 461 419 } 462 420 463 421 void NewHumanController::yaw(const Vector2& value) 464 422 { 465 //SUPER(NewHumanController, yaw, value);466 if (this->controlMode_ == 0 || ( this->controllableEntity_ && this->controllableEntity_->isInMouseLook() ))423 //SUPER(NewHumanController, yaw, value); 424 if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook())) 467 425 HumanController::yaw(value); 468 426 … … 472 430 void NewHumanController::pitch(const Vector2& value) 473 431 { 474 //SUPER(NewHumanController, pitch, value);475 if (this->controlMode_ == 0 || ( this->controllableEntity_ && this->controllableEntity_->isInMouseLook() ))432 //SUPER(NewHumanController, pitch, value); 433 if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook())) 476 434 HumanController::pitch(value); 477 435 … … 495 453 void NewHumanController::changedControllableEntity() 496 454 { 497 /*498 if( this->getControllableEntity() )499 CCOUT(0) << "changed controllable entity to: " << this->getControllableEntity()->getIdentifier()->getName() << endl;500 else501 CCOUT(0) << "changed controllable entity to: " << this->getControllableEntity() << endl;502 */503 455 this->controlMode_ = 0; 504 456 this->currentYaw_ = 0; 505 457 this->currentPitch_ = 0; 506 if (this->getControllableEntity() && ( this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket"))458 if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket")))) 507 459 { 508 460 this->showOverlays_ = true; 509 if ( !this->controlPaused_)461 if (!this->controlPaused_) 510 462 { 511 463 this->showOverlays(); … … 522 474 void NewHumanController::accelerate() 523 475 { 524 if ( NewHumanController::localController_s ) 525 { 476 if (NewHumanController::localController_s) 526 477 NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f); 527 }528 478 } 529 479 530 480 void NewHumanController::decelerate() 531 481 { 532 if ( NewHumanController::localController_s ) 533 { 482 if (NewHumanController::localController_s) 534 483 NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f); 535 536 } 537 538 void NewHumanController::doResumeControl(){484 } 485 486 void NewHumanController::doResumeControl() 487 { 539 488 this->controlPaused_ = false; 540 if ( this->showOverlays_ ) {489 if (this->showOverlays_) 541 490 this->showOverlays(); 542 543 } 544 545 void NewHumanController::doPauseControl(){491 } 492 493 void NewHumanController::doPauseControl() 494 { 546 495 this->controlPaused_ = true; 547 // COUT(0) << "pause control" << endl;548 496 this->hideOverlays(); 549 497 } 550 498 551 void NewHumanController::alignArrows() { 552 if (showArrows_) { 499 void NewHumanController::alignArrows() 500 { 501 if (showArrows_) 502 { 553 503 hideArrows(); 554 504 555 505 float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2)); 556 506 557 if ( distance > 0.04 && distance <= 0.59 * arrowsSize_ / 2.0 ) { 507 if (distance > 0.04 && distance <= 0.59 * arrowsSize_ / 2.0 ) 508 { 558 509 this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); 559 560 510 this->arrowsOverlay1_->show(); 561 511 } 562 else if ( distance > 0.59 * arrowsSize_ / 2.0 && distance <= 0.77 * arrowsSize_ / 2.0 ) { 512 else if (distance > 0.59 * arrowsSize_ / 2.0 && distance <= 0.77 * arrowsSize_ / 2.0 ) 513 { 563 514 this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); 564 565 515 this->arrowsOverlay2_->show(); 566 516 } 567 else if ( distance > 0.77 * arrowsSize_ / 2.0 && distance <= arrowsSize_ / 2.0 ) { 517 else if (distance > 0.77 * arrowsSize_ / 2.0 && distance <= arrowsSize_ / 2.0) 518 { 568 519 this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); 569 570 520 this->arrowsOverlay3_->show(); 571 521 } 572 else if ( distance > arrowsSize_ / 2.0 ) { 522 else if (distance > arrowsSize_ / 2.0) 523 { 573 524 this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); 574 575 525 this->arrowsOverlay4_->show(); 576 526 } … … 578 528 } 579 529 580 void NewHumanController::showOverlays() { 581 if( !GameMode::showsGraphics() ) 530 void NewHumanController::showOverlays() 531 { 532 if (!GameMode::showsGraphics()) 582 533 return; 583 534 this->crossHairOverlay_->show(); 584 535 this->centerOverlay_->show(); 585 536 586 if (showArrows_) { 537 if (showArrows_) 538 { 587 539 this->arrowsOverlay1_->show(); 588 540 this->arrowsOverlay2_->show(); … … 592 544 } 593 545 594 void NewHumanController::hideOverlays() { 595 if( !GameMode::showsGraphics() ) 546 void NewHumanController::hideOverlays() 547 { 548 if (!GameMode::showsGraphics()) 596 549 return; 597 550 this->crossHairOverlay_->hide(); 598 551 this->centerOverlay_->hide(); 599 552 600 if ( showDamageOverlay_ ) { 553 if (showDamageOverlay_) 554 { 601 555 this->damageOverlayTop_->hide(); 602 556 this->damageOverlayRight_->hide(); … … 608 562 } 609 563 610 void NewHumanController::hideArrows() { 611 if( !GameMode::showsGraphics() ) 564 void NewHumanController::hideArrows() 565 { 566 if(!GameMode::showsGraphics()) 612 567 return; 613 if (showArrows_) { 568 if (showArrows_) 569 { 614 570 this->arrowsOverlay1_->hide(); 615 571 this->arrowsOverlay2_->hide(); -
code/branches/presentation2/src/orxonox/controllers/NewHumanController.h
r6310 r6377 76 76 unsigned int controlMode_; 77 77 static NewHumanController* localController_s; 78 78 79 private: 79 80 float currentYaw_;
Note: See TracChangeset
for help on using the changeset viewer.