Changeset 10171 for code/branches/presentationHS14/src/modules/overlays
- Timestamp:
- Dec 11, 2014, 1:01:28 PM (10 years ago)
- Location:
- code/branches/presentationHS14
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationHS14
- Property svn:mergeinfo changed
/code/branches/hudHS14 (added) merged: 10083,10110,10122,10143,10149,10163
- Property svn:mergeinfo changed
-
code/branches/presentationHS14/src/modules/overlays/hud/HUDEnemyHealthBar.cc
r9667 r10171 31 31 #include "core/config/ConfigValueIncludes.h" 32 32 #include "worldentities/pawns/Pawn.h" 33 #include "graphics/Camera.h" 33 34 34 35 namespace orxonox … … 57 58 this->updateTarget(); 58 59 60 61 62 /* 63 //-------------------------------------------------------------------------- 64 //first try to place a healthbar under the enemy ship 65 //getting all the parameters (direction, position, angle) to place the health bar on the screen 66 67 Camera* camera = this->owner_->getCamera(); 68 69 //position and orientation relative to the root space 70 Vector3 cameraPosition = camera->getWorldPosition(); 71 Quaternion cameraOrientation = camera->getWorldOrientation(); 72 73 Vector3 cameraDirection = camera->FRONT; 74 Vector3 cameraOrthonormal = camera->UP; 75 76 //get target 77 //if there is one get it's position (relative to the root space( 78 WorldEntity* target = this->owner_->getTarget(); 79 80 if(target != NULL){ 81 Vector3 targetPosition = target->getWorldPosition(); 82 83 84 //try 1 85 Vector2 screenCoordinates = get2DViewcoordinates(cameraPosition, cameraOrientation * WorldEntity::FRONT, cameraOrientation * WorldEntity::UP, targetPosition); 86 87 orxout() << screenCoordinates.x << endl; 88 89 //shift coordinates because the screen has it's root in the upper left corner (0,0) but get2Dviewcoordiantes return values between -0.5 and 0.5 90 screenCoordinates.x += 0.5; 91 screenCoordinates.y += 0.5; 92 orxout() << screenCoordinates.x << endl; 93 94 this->setPosition(screenCoordinates); 95 96 this->setTextOffset(screenCoordinates); 97 } 98 //-------------------------------------------------------------------------- 99 */ 100 101 102 59 103 SUPER(HUDEnemyHealthBar, tick, dt); 60 104 } … … 71 115 target = target->getParent(); 72 116 pawn = orxonox_cast<Pawn*>(target); 117 118 73 119 // Don't show the HealthBar if the pawn is invisible 74 120 if (pawn && !pawn->isVisible()) 75 121 pawn = NULL; 76 122 } 123 77 124 // Set the pawn as owner of the HealthBar 78 125 this->setHealthBarOwner(pawn); -
code/branches/presentationHS14/src/modules/overlays/hud/HUDHealthBar.cc
r9667 r10171 83 83 SUPER(HUDHealthBar, tick, dt); 84 84 85 86 87 88 85 89 if (this->owner_) 86 90 { -
code/branches/presentationHS14/src/modules/overlays/hud/HUDNavigation.cc
r9939 r10171 82 82 this->setNavMarkerSize(0.03f); 83 83 this->setAimMarkerSize(0.02f); 84 this->setHealthMarkerSize(0.06f); 85 this->setHealthLevelMarkerSize(0.06f); 84 86 85 87 this->setDetectionLimit(10000.0f); … … 116 118 XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode); 117 119 XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlelement, mode); 120 XMLPortParam(HUDNavigation, "healthMarkerSize", setHealthMarkerSize, getHealthMarkerSize, xmlelement, mode); 121 XMLPortParam(HUDNavigation, "healthLevelMarkerSize", setHealthLevelMarkerSize, getHealthLevelMarkerSize, xmlelement, mode); 122 118 123 } 119 124 … … 206 211 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt) 207 212 { 213 208 214 std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first); 209 215 closeEnough = listIt->second < this->detectionLimit_; … … 275 281 276 282 283 284 277 285 // Transform to screen coordinates 278 286 Vector3 pos = camTransform * it->first->getRVWorldPosition(); … … 298 306 if (!it->second.wasOutOfView_) 299 307 { 300 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour())); 308 it->second.health_->hide(); 309 it->second.healthLevel_->hide(); 310 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour())); 301 311 it->second.wasOutOfView_ = true; 302 312 it->second.target_->hide(); … … 357 367 // Object is in view 358 368 359 // Change material only if outOfView changed 369 370 371 372 //calculate the health of the actual selected radarViewable (relativHealthScale: while (0) is no health left, (1) is the initial health) 373 Pawn* pawnPtr = (Pawn*) (it->first->getWorldEntity()); 374 float health = pawnPtr->getHealth(); 375 float initHealth = pawnPtr->getMaxHealth(); 376 float relativHealthScale = health/initHealth; 377 378 //integer values from 0 to 10 (0 is no health and 10 is full health) 379 int discreteHealthScale = 10*relativHealthScale; 380 381 //calculate the HealthLevel (= OponentLevel or Strength) there are 5 Levels 382 //Level 1, Level 2,... , Level 5 383 int HealthLevel = 1; 384 385 if(initHealth < 200) 386 HealthLevel = 1; 387 if(200 <= initHealth && initHealth < 500) 388 HealthLevel = 2; 389 if(500 <= initHealth && initHealth < 1000) 390 HealthLevel = 3; 391 if(1000 <= initHealth && initHealth < 2500) 392 HealthLevel = 4; 393 if(2500 <= initHealth) 394 HealthLevel = 5; 395 396 397 398 // Change material only if outOfView changed 360 399 if (it->second.wasOutOfView_) 361 400 { … … 364 403 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 365 404 it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y); 405 406 407 //it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2_1.png", it->first->getRadarObjectColour())); 408 it->second.health_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour())); 409 it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x , 0.75*this->healthMarkerSize_ * this->getActualSize().y); 366 410 it->second.wasOutOfView_ = false; 367 } 411 412 // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the 413 // spaceship is still intact there should be at least one part of the bar left. 414 if(1<=discreteHealthScale){ 415 it->second.health_->setTiling((float)discreteHealthScale , 1 ,0); 416 it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1*discreteHealthScale, 0.75*this->healthMarkerSize_ * this->getActualSize().y); 417 } 418 419 420 421 //healthLevel 422 it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour())); 423 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x , 0.75*this->healthLevelMarkerSize_ * this->getActualSize().y); 424 it->second.wasOutOfView_ = false; 425 it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0); 426 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1*HealthLevel, 0.25*this->healthLevelMarkerSize_ * this->getActualSize().y); 427 } 428 429 430 431 // sets Position and Dimensions (amount) health 432 it->second.health_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 433 it->second.health_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f); 434 it->second.health_->setTop((-pos.y + 1.04f - it->second.panel_->getHeight()) * 0.5f); 435 436 437 // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the 438 // spaceship is still intact there should be at least one part of the bar left. 439 if(1<=discreteHealthScale){ 440 it->second.health_->setTiling((float)discreteHealthScale , 1 ,0); 441 it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1*discreteHealthScale, 0.75*this->healthMarkerSize_ * this->getActualSize().y); 442 } 443 444 445 //sets Position and Dimensions (level) of healthLevel 446 it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour())); 447 it->second.healthLevel_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 448 it->second.healthLevel_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f); 449 it->second.healthLevel_->setTop((-pos.y + 1.125f - it->second.panel_->getHeight()) * 0.5f); 450 451 it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0); 452 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1*HealthLevel, 0.25*this->healthLevelMarkerSize_ * this->getActualSize().y); 453 368 454 369 455 // Position marker … … 376 462 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 377 463 464 465 466 378 467 // Make sure the overlays are shown 468 it->second.health_->show(); 469 it->second.healthLevel_->show(); 379 470 it->second.panel_->show(); 380 471 it->second.text_->show(); … … 419 510 420 511 { 421 it->second.panel_->hide(); 512 it->second.health_->hide(); 513 it->second.healthLevel_->hide(); 514 it->second.panel_->hide(); 422 515 it->second.text_->hide(); 423 516 it->second.target_->hide(); … … 442 535 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it) 443 536 { 537 if (it->second.health_ != NULL) 538 it->second.health_->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale); 539 if (it->second.healthLevel_ != NULL) 540 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * xScale, this->healthLevelMarkerSize_ * yScale); 444 541 if (it->second.panel_ != NULL) 445 542 it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale); … … 468 565 469 566 // Create everything needed to display the object on the radar and add it to the map 567 568 // Create health 569 Ogre::PanelOverlayElement* health = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDNavigation_healthMarker_" + getUniqueNumberString())); 570 //panel->setMaterialName("Orxonox/NavTDC"); 571 health->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", object->getRadarObjectColour())); 572 health->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale); 573 //panel->setColour(object->getRadarObjectColour()); 574 575 // Create healthLevel 576 Ogre::PanelOverlayElement* healthLevel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDNavigation_healthLevelMarker_" + getUniqueNumberString())); 577 //panel->setMaterialName("Orxonox/NavTDC"); 578 health->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", object->getRadarObjectColour())); 579 health->setDimensions(this->healthLevelMarkerSize_ * xScale, this->healthLevelMarkerSize_ * yScale); 580 470 581 471 582 // Create arrow/marker … … 490 601 text->setColour(object->getRadarObjectColour()); 491 602 603 health->hide(); 604 healthLevel->hide(); 492 605 panel->hide(); 493 606 target->hide(); … … 495 608 496 609 ObjectInfo tempStruct = 497 { panel, target, text, false, false, false};610 { health, healthLevel, panel, target, text, false, false, false}; 498 611 this->activeObjectList_[object] = tempStruct; 499 612 613 this->background_->addChild(health); 614 this->background_->addChild(healthLevel); 500 615 this->background_->addChild(panel); 501 616 this->background_->addChild(target); … … 512 627 { 513 628 // Detach overlays 629 this->background_->removeChild(it->second.health_->getName()); 630 this->background_->removeChild(it->second.healthLevel_->getName()); 514 631 this->background_->removeChild(it->second.panel_->getName()); 515 632 this->background_->removeChild(it->second.target_->getName()); 516 633 this->background_->removeChild(it->second.text_->getName()); 517 634 // Properly destroy the overlay elements (do not use delete!) 635 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.health_); 636 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.healthLevel_); 518 637 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_); 519 638 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_); -
code/branches/presentationHS14/src/modules/overlays/hud/HUDNavigation.h
r9667 r10171 77 77 struct ObjectInfo 78 78 { 79 Ogre::PanelOverlayElement* panel_; 79 80 81 82 Ogre::PanelOverlayElement* health_; 83 Ogre::PanelOverlayElement* healthLevel_; 84 Ogre::PanelOverlayElement* panel_; 80 85 Ogre::PanelOverlayElement* target_; 81 86 Ogre::TextAreaOverlayElement* text_; … … 88 93 89 94 // XMLPort accessors 95 inline void setHealthMarkerSize(float size) 96 { 97 this->healthMarkerSize_ = size; 98 this->sizeChanged(); 99 } 100 inline float getHealthMarkerSize() const 101 { return healthMarkerSize_; } 102 103 inline void setHealthLevelMarkerSize(float size) 104 { 105 this->healthLevelMarkerSize_ = size; 106 this->sizeChanged(); 107 } 108 inline float getHealthLevelMarkerSize() const 109 { return healthLevelMarkerSize_; } 110 90 111 inline void setNavMarkerSize(float size) 91 112 { … … 100 121 this->sizeChanged(); 101 122 } 123 102 124 inline float getAimMarkerSize() const 103 125 { return aimMarkerSize_; } … … 121 143 std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_; 122 144 145 float healthMarkerSize_; 146 float healthLevelMarkerSize_; 123 147 float navMarkerSize_; 124 148 float aimMarkerSize_;
Note: See TracChangeset
for help on using the changeset viewer.