[Orxonox-commit 6366] r11023 - code/trunk/src/modules/overlays/hud

landauf at orxonox.net landauf at orxonox.net
Sat Jan 2 23:07:27 CET 2016


Author: landauf
Date: 2016-01-02 23:07:26 +0100 (Sat, 02 Jan 2016)
New Revision: 11023

Modified:
   code/trunk/src/modules/overlays/hud/HUDNavigation.cc
Log:
bugfix: use orxonox_cast instead of c-style-cast and check if the object is actually a pawn.
fixes weird behavior of healthbar elements in hud. also this: http://orxonox2.vseth.ethz.ch/phpBB3/viewtopic.php?f=11&t=1129

Modified: code/trunk/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDNavigation.cc	2016-01-02 20:50:26 UTC (rev 11022)
+++ code/trunk/src/modules/overlays/hud/HUDNavigation.cc	2016-01-02 22:07:26 UTC (rev 11023)
@@ -366,49 +366,58 @@
                 {
                     // Object is in view
 
-
-
-
                     //calculate the health of the actual selected radarViewable (relativHealthScale: while (0) is no health left, (1) is the initial health)
-                    Pawn* pawnPtr = (Pawn*) (it->first->getWorldEntity());
-                    float health = pawnPtr->getHealth();
-                    float initHealth = pawnPtr->getMaxHealth();
-                    float relativHealthScale = health/initHealth;
+                    const Pawn* pawnPtr = orxonox_cast<const Pawn*>(it->first->getWorldEntity());
+                    if (pawnPtr)
+                    {
+                        float health = pawnPtr->getHealth();
+                        float initHealth = pawnPtr->getMaxHealth();
+                        float relativHealthScale = health/initHealth;
 
-                    //integer values from 0 to 10 (0 is no health and 10 is full health)
-                    int discreteHealthScale = (int)(10*relativHealthScale);
+                        //integer values from 0 to 10 (0 is no health and 10 is full health)
+                        int discreteHealthScale = (int)(10*relativHealthScale);
 
-                    //calculate the HealthLevel (= OponentLevel or Strength) there are 5 Levels
-                    //Level 1, Level 2,... , Level 5
-                    int HealthLevel = 1;
+                        //calculate the HealthLevel (= OponentLevel or Strength) there are 5 Levels
+                        //Level 1, Level 2,... , Level 5
+                        int HealthLevel = 1;
 
-                    if(initHealth < 200)
-                        HealthLevel = 1;
-                    if(200 <= initHealth && initHealth < 500)
-                        HealthLevel = 2;
-                    if(500 <= initHealth && initHealth < 1000)
-                        HealthLevel = 3;
-                    if(1000 <= initHealth && initHealth < 2500)
-                        HealthLevel = 4;
-                    if(2500 <= initHealth)
-                        HealthLevel = 5;
+                        if(initHealth < 200)
+                            HealthLevel = 1;
+                        if(200 <= initHealth && initHealth < 500)
+                            HealthLevel = 2;
+                        if(500 <= initHealth && initHealth < 1000)
+                            HealthLevel = 3;
+                        if(1000 <= initHealth && initHealth < 2500)
+                            HealthLevel = 4;
+                        if(2500 <= initHealth)
+                            HealthLevel = 5;
 
+                        // Change material only if outOfView changed
+                        if (it->second.wasOutOfView_)
+                        {
+                            //it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2_1.png", it->first->getRadarObjectColour()));
+                            it->second.health_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
+                            it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x , 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
 
+                            // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the
+                            // spaceship is still intact there should be at least one part of the bar left.
+                            if(1<=discreteHealthScale){
+                                it->second.health_->setTiling((float)discreteHealthScale , 1 ,0);
+                                it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1f*discreteHealthScale, 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
+                            }
 
-                    // Change material only if outOfView changed
-                    if (it->second.wasOutOfView_)
-                    {
-                        //it->second.panel_->setMaterialName("Orxonox/NavTDC");
-                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour()));
-                        it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
-                        it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y);
+                            //healthLevel
+                            it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
+                            it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x , 0.75f*this->healthLevelMarkerSize_ * this->getActualSize().y);
+                            it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0);
+                            it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y);
+                        }
 
+                        // sets Position and Dimensions (amount) health
+                        it->second.health_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
+                        it->second.health_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
+                        it->second.health_->setTop((-pos.y + 1.04f - it->second.panel_->getHeight()) * 0.5f);
 
-                        //it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2_1.png", it->first->getRadarObjectColour()));
-                        it->second.health_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
-                        it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x , 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
-                        it->second.wasOutOfView_ = false;
-
                         // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the
                         // spaceship is still intact there should be at least one part of the bar left.
                         if(1<=discreteHealthScale){
@@ -416,42 +425,31 @@
                             it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1f*discreteHealthScale, 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
                         }
 
-
-
-                        //healthLevel
+                        //sets Position and Dimensions (level) of healthLevel
                         it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
-                        it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x , 0.75f*this->healthLevelMarkerSize_ * this->getActualSize().y);
-                        it->second.wasOutOfView_ = false;
+                        it->second.healthLevel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
+                        it->second.healthLevel_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
+                        it->second.healthLevel_->setTop((-pos.y + 1.125f - it->second.panel_->getHeight()) * 0.5f);
+
                         it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0);
                         it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y);
+
+                        // Make sure the overlays are shown
+                        it->second.health_->show();
+                        it->second.healthLevel_->show();
                     }
 
 
-
-                    // sets Position and Dimensions (amount) health
-                    it->second.health_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
-                    it->second.health_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
-                    it->second.health_->setTop((-pos.y + 1.04f - it->second.panel_->getHeight()) * 0.5f);
-
-
-                    // because as soon as relative health drops below 10% (0.1) the descrete value is 0 but as long as the
-                    // spaceship is still intact there should be at least one part of the bar left.
-                    if(1<=discreteHealthScale){
-                    it->second.health_->setTiling((float)discreteHealthScale , 1 ,0);
-                    it->second.health_->setDimensions(this->healthMarkerSize_ * this->getActualSize().x *0.1f*discreteHealthScale, 0.75f*this->healthMarkerSize_ * this->getActualSize().y);
+                    // Change material only if outOfView changed
+                    if (it->second.wasOutOfView_)
+                    {
+                        //it->second.panel_->setMaterialName("Orxonox/NavTDC");
+                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour()));
+                        it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
+                        it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y);
+                        it->second.wasOutOfView_ = false;
                     }
 
-
-                    //sets Position and Dimensions (level) of healthLevel
-                    it->second.healthLevel_->setMaterialName(TextureGenerator::getMaterialName("barSquare.png", it->first->getRadarObjectColour()));
-                    it->second.healthLevel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
-                    it->second.healthLevel_->setLeft((pos.x + 0.975f - it->second.panel_->getWidth()) * 0.5f);
-                    it->second.healthLevel_->setTop((-pos.y + 1.125f - it->second.panel_->getHeight()) * 0.5f);
-
-                    it->second.healthLevel_->setTiling((float)HealthLevel , 1 ,0);
-                    it->second.healthLevel_->setDimensions(this->healthLevelMarkerSize_ * this->getActualSize().x *0.1f*HealthLevel, 0.25f*this->healthLevelMarkerSize_ * this->getActualSize().y);
-
-
                     // Position marker
                     it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
                     it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f);
@@ -461,12 +459,7 @@
                     it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f);
                     it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
 
-
-
-
                     // Make sure the overlays are shown
-                    it->second.health_->show();
-                    it->second.healthLevel_->show();
                     it->second.panel_->show();
                     it->second.text_->show();
 




More information about the Orxonox-commit mailing list