[Orxonox-commit 5447] r10110 - in code/branches/hudHS14: data/overlays src/modules/overlays/hud

aejonas at orxonox.net aejonas at orxonox.net
Wed Nov 5 16:04:52 CET 2014


Author: aejonas
Date: 2014-11-05 16:04:51 +0100 (Wed, 05 Nov 2014)
New Revision: 10110

Modified:
   code/branches/hudHS14/data/overlays/HUDTemplates3.oxo
   code/branches/hudHS14/src/modules/overlays/hud/HUDEnemyHealthBar.cc
   code/branches/hudHS14/src/modules/overlays/hud/HUDHealthBar.cc
   code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.cc
   code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.h
Log:
new way to display the healthbar on the screen (in a similar way like the existing ship marker)

Modified: code/branches/hudHS14/data/overlays/HUDTemplates3.oxo
===================================================================
--- code/branches/hudHS14/data/overlays/HUDTemplates3.oxo	2014-11-05 14:59:18 UTC (rev 10109)
+++ code/branches/hudHS14/data/overlays/HUDTemplates3.oxo	2014-11-05 15:04:51 UTC (rev 10110)
@@ -35,7 +35,7 @@
      background        = "Orxonox/HealthBarBackground"
      size              = "0.35, 0.0875"
      position          = "0.0 , 0.9 "
-     pickpoint         = "0, 1"
+     pickpoint         = "0, 1"       
      bartexture        = "healthbar_bar.png"
      textfont          = "VeraMono"
      textusebarcolour  = true
@@ -81,14 +81,14 @@
      name              = "EnemyHealthBar"
      background        = "Orxonox/HealthBarBackground"
      size              = "0.35, 0.0875"
-     position          = "1.0 , 0.1 "
-     pickpoint         = "1, 1"
+     position          = "1 ,0"
+     pickpoint         = "0.6, 0.5"
      bartexture        = "healthbar_bar.png"
      textfont          = "VeraMono"
      textusebarcolour  = true
      textsize          = 0.039
      textoffset        = "0.315, 0.05"
-     textpickpoint     = "0, 0"
+     textpickpoint     = "2, 1"
      textalign         = "right"
      correctaspect     = false
      textcorrectaspect = false

Modified: code/branches/hudHS14/src/modules/overlays/hud/HUDEnemyHealthBar.cc
===================================================================
--- code/branches/hudHS14/src/modules/overlays/hud/HUDEnemyHealthBar.cc	2014-11-05 14:59:18 UTC (rev 10109)
+++ code/branches/hudHS14/src/modules/overlays/hud/HUDEnemyHealthBar.cc	2014-11-05 15:04:51 UTC (rev 10110)
@@ -30,6 +30,7 @@
 
 #include "core/config/ConfigValueIncludes.h"
 #include "worldentities/pawns/Pawn.h"
+#include "graphics/Camera.h"
 
 namespace orxonox
 {
@@ -56,6 +57,55 @@
     {
         this->updateTarget();
 
+
+
+
+/*
+        //--------------------------------------------------------------------------
+        //first try to place a healthbar under the enemy ship
+        //getting all the parameters (direction, position, angle) to place the health bar on the screen
+
+        Camera* camera = this->owner_->getCamera();
+
+        //position and orientation relative to the root space
+        Vector3 cameraPosition = camera->getWorldPosition();
+        Quaternion cameraOrientation = camera->getWorldOrientation();
+
+        Vector3 cameraDirection = camera->FRONT;
+        Vector3 cameraOrthonormal = camera->UP;
+
+        //get target
+        //if there is one get it's position (relative to the root space(
+        WorldEntity* target = this->owner_->getTarget();
+
+        if(target != NULL){
+        Vector3 targetPosition = target->getWorldPosition();
+
+
+        //try 1
+        Vector2 screenCoordinates = get2DViewcoordinates(cameraPosition, cameraOrientation * WorldEntity::FRONT, cameraOrientation * WorldEntity::UP, targetPosition);
+
+        orxout() << screenCoordinates.x << endl;
+
+        //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
+        screenCoordinates.x += 0.5;
+        screenCoordinates.y += 0.5;
+        orxout() << screenCoordinates.x << endl;
+
+        this->setPosition(screenCoordinates);
+
+        this->setTextOffset(screenCoordinates);
+
+
+
+
+
+        }
+
+        //--------------------------------------------------------------------------
+*/
+
+
         SUPER(HUDEnemyHealthBar, tick, dt);
     }
 
@@ -70,10 +120,20 @@
             while (target && !target->isA(Class(Pawn)))
                 target = target->getParent();
             pawn = orxonox_cast<Pawn*>(target);
+
+
+
+            /*Vector3 tempPosition = target->getWorldPosition();
+            Vector2 tempPos2D = Vector2(tempPosition.x, tempPosition.y);
+                     this->pickPoint_(tempPos2D);
+                     this->position_(tempPos2D);*/
+
+
             // Don't show the HealthBar if the pawn is invisible
             if (pawn && !pawn->isVisible())
                 pawn = NULL;
         }
+
         // Set the pawn as owner of the HealthBar
         this->setHealthBarOwner(pawn);
         this->setVisible(pawn != NULL);

Modified: code/branches/hudHS14/src/modules/overlays/hud/HUDHealthBar.cc
===================================================================
--- code/branches/hudHS14/src/modules/overlays/hud/HUDHealthBar.cc	2014-11-05 14:59:18 UTC (rev 10109)
+++ code/branches/hudHS14/src/modules/overlays/hud/HUDHealthBar.cc	2014-11-05 15:04:51 UTC (rev 10110)
@@ -82,6 +82,10 @@
     {
         SUPER(HUDHealthBar, tick, dt);
 
+
+
+
+
         if (this->owner_)
         {
             this->setValue(this->owner_->getHealth() / this->owner_->getInitialHealth());

Modified: code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.cc	2014-11-05 14:59:18 UTC (rev 10109)
+++ code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.cc	2014-11-05 15:04:51 UTC (rev 10110)
@@ -297,7 +297,8 @@
                     // Change material only if outOfView changed
                     if (!it->second.wasOutOfView_)
                     {
-                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
+                    	it->second.health_->hide();
+                    	it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
                         it->second.wasOutOfView_ = true;
                         it->second.target_->hide();
                     }
@@ -363,9 +364,18 @@
                         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);
+
+                        //manipulation bzw versuch !!! Jonas
+                        it->second.health_->setMaterialName(TextureGenerator::getMaterialName("bar2b.png", it->first->getRadarObjectColour()));
+
                         it->second.wasOutOfView_ = false;
                     }
 
+                    // Position health (versuch !!!!)
+                    it->second.health_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f);
+                    it->second.health_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f);
+
+
                     // 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);
@@ -376,6 +386,8 @@
                     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.panel_->show();
                     it->second.text_->show();
 
@@ -418,6 +430,7 @@
             else // do not display on HUD
 
             {
+            	it->second.health_->hide()
                 it->second.panel_->hide();
                 it->second.text_->hide();
                 it->second.target_->hide();
@@ -441,6 +454,8 @@
 
         for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it)
         {
+        	if (it->second.health_ != NULL)
+        	    it->second.health_->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale);
             if (it->second.panel_ != NULL)
                 it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
             if (it->second.text_ != NULL)
@@ -467,7 +482,15 @@
         float yScale = this->getActualSize().y;
 
         // Create everything needed to display the object on the radar and add it to the map
+        // Create health
+                Ogre::PanelOverlayElement* health = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton()
+                        .createOverlayElement("Panel", "HUDNavigation_healthMarker_" + getUniqueNumberString()));
+                //panel->setMaterialName("Orxonox/NavTDC");
+                health->setMaterialName(TextureGenerator::getMaterialName("bar2b.png", object->getRadarObjectColour()));
+                health->setDimensions(this->healthMarkerSize_ * xScale, this->healthMarkerSize_ * yScale);
+                //panel->setColour(object->getRadarObjectColour());
 
+
         // Create arrow/marker
         Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton()
                 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
@@ -489,14 +512,16 @@
         text->setCharHeight(text->getCharHeight() * yScale);
         text->setColour(object->getRadarObjectColour());
 
+        health->hide();
         panel->hide();
         target->hide();
         text->hide();
 
         ObjectInfo tempStruct =
-        {   panel, target, text, false, false, false};
+        {   health, panel, target, text, false, false, false, false};
         this->activeObjectList_[object] = tempStruct;
 
+        this->background_->addChild(health);
         this->background_->addChild(panel);
         this->background_->addChild(target);
         this->background_->addChild(text);
@@ -511,10 +536,12 @@
         if (this->activeObjectList_.find(viewable) != this->activeObjectList_.end())
         {
             // Detach overlays
+        	this->background_->removeChild(it->second.health_->getName());
             this->background_->removeChild(it->second.panel_->getName());
             this->background_->removeChild(it->second.target_->getName());
             this->background_->removeChild(it->second.text_->getName());
             // Properly destroy the overlay elements (do not use delete!)
+            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.health_);
             Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);
             Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_);
             Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);

Modified: code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.h
===================================================================
--- code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.h	2014-11-05 14:59:18 UTC (rev 10109)
+++ code/branches/hudHS14/src/modules/overlays/hud/HUDNavigation.h	2014-11-05 15:04:51 UTC (rev 10110)
@@ -76,7 +76,11 @@
         private:
             struct ObjectInfo
             {
-                Ogre::PanelOverlayElement* panel_;
+
+            	//manipulation bzw versuch !!! Jonas
+            	Ogre::PanelOverlayElement* health_;
+
+            	Ogre::PanelOverlayElement* panel_;
                 Ogre::PanelOverlayElement* target_;
                 Ogre::TextAreaOverlayElement* text_;
                 bool outOfView_;




More information about the Orxonox-commit mailing list