Changeset 11023 for code/trunk/src/modules
- Timestamp:
- Jan 2, 2016, 11:07:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/overlays/hud/HUDNavigation.cc
r10624 r11023 367 367 // Object is in view 368 368 369 370 371 372 369 //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 = (int)(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 399 if (it->second.wasOutOfView_) 400 { 401 //it->second.panel_->setMaterialName("Orxonox/NavTDC"); 402 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour())); 403 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 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.75f*this->healthMarkerSize_ * this->getActualSize().y); 410 it->second.wasOutOfView_ = false; 370 const Pawn* pawnPtr = orxonox_cast<const Pawn*>(it->first->getWorldEntity()); 371 if (pawnPtr) 372 { 373 float health = pawnPtr->getHealth(); 374 float initHealth = pawnPtr->getMaxHealth(); 375 float relativHealthScale = health/initHealth; 376 377 //integer values from 0 to 10 (0 is no health and 10 is full health) 378 int discreteHealthScale = (int)(10*relativHealthScale); 379 380 //calculate the HealthLevel (= OponentLevel or Strength) there are 5 Levels 381 //Level 1, Level 2,... , Level 5 382 int HealthLevel = 1; 383 384 if(initHealth < 200) 385 HealthLevel = 1; 386 if(200 <= initHealth && initHealth < 500) 387 HealthLevel = 2; 388 if(500 <= initHealth && initHealth < 1000) 389 HealthLevel = 3; 390 if(1000 <= initHealth && initHealth < 2500) 391 HealthLevel = 4; 392 if(2500 <= initHealth) 393 HealthLevel = 5; 394 395 // Change material only if outOfView changed 396 if (it->second.wasOutOfView_) 397 { 398 //it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2_1.png", it->first->getRadarObjectColour())); 399 it->second.health_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour())); 400 it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x , 0.75f*this->healthMarkerSize_ * this->getActualSize().y); 401 402 // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the 403 // spaceship is still intact there should be at least one part of the bar left. 404 if(1<=discreteHealthScale){ 405 it->second.health_->setTiling((float)discreteHealthScale , 1 ,0); 406 it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1f*discreteHealthScale, 0.75f*this->healthMarkerSize_ * this->getActualSize().y); 407 } 408 409 //healthLevel 410 it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour())); 411 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x , 0.75f*this->healthLevelMarkerSize_ * this->getActualSize().y); 412 it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0); 413 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y); 414 } 415 416 // sets Position and Dimensions (amount) health 417 it->second.health_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 418 it->second.health_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f); 419 it->second.health_->setTop((-pos.y + 1.04f - it->second.panel_->getHeight()) * 0.5f); 411 420 412 421 // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the … … 417 426 } 418 427 419 420 421 //healthLevel 428 //sets Position and Dimensions (level) of healthLevel 422 429 it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour())); 423 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x , 0.75f*this->healthLevelMarkerSize_ * this->getActualSize().y); 424 it->second.wasOutOfView_ = false; 430 it->second.healthLevel_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 431 it->second.healthLevel_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f); 432 it->second.healthLevel_->setTop((-pos.y + 1.125f - it->second.panel_->getHeight()) * 0.5f); 433 425 434 it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0); 426 435 it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*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.1f*discreteHealthScale, 0.75f*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.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y); 453 436 437 // Make sure the overlays are shown 438 it->second.health_->show(); 439 it->second.healthLevel_->show(); 440 } 441 442 443 // Change material only if outOfView changed 444 if (it->second.wasOutOfView_) 445 { 446 //it->second.panel_->setMaterialName("Orxonox/NavTDC"); 447 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour())); 448 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 449 it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y); 450 it->second.wasOutOfView_ = false; 451 } 454 452 455 453 // Position marker … … 462 460 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 463 461 464 465 466 467 462 // Make sure the overlays are shown 468 it->second.health_->show();469 it->second.healthLevel_->show();470 463 it->second.panel_->show(); 471 464 it->second.text_->show();
Note: See TracChangeset
for help on using the changeset viewer.