Index: code/trunk/src/orxonox/hud/HUD.cc
===================================================================
--- code/trunk/src/orxonox/hud/HUD.cc	(revision 1407)
+++ code/trunk/src/orxonox/hud/HUD.cc	(revision 1502)
@@ -1,52 +1,65 @@
 /*
-*   ORXONOX - the hottest 3D action shooter ever to exist
-*
-*
-*   License notice:
-*
-*   This program is free software; you can redistribute it and/or
-*   modify it under the terms of the GNU General Public License
-*   as published by the Free Software Foundation; either version 2
-*   of the License, or (at your option) any later version.
-*
-*   This program is distributed in the hope that it will be useful,
-*   but WITHOUT ANY WARRANTY; without even the implied warranty of
-*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*   GNU General Public License for more details.
-*
-*   You should have received a copy of the GNU General Public License
-*   along with this program; if not, write to the Free Software
-*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*
-*   Author:
-*      Yuning Chai
-*   Co-authors:
-*      Felix Schulthess
-*
-*/
-
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Yuning Chai
+ *   Co-authors:
+ *      Felix Schulthess
+ *
+ */
 
 #include "OrxonoxStableHeaders.h"
+#include "HUD.h"
+
+#include <string>
+#include <set>
 #include <OgreOverlay.h>
 #include <OgreOverlayContainer.h>
 #include <OgreOverlayManager.h>
-#include <OgreSceneNode.h>
-#include <OgreEntity.h>
 #include <OgreStringConverter.h>
+
 #include "core/Debug.h"
+#include "core/ConsoleCommand.h"
 #include "objects/SpaceShip.h"
-#include "HUD.h"
+#include "GraphicsEngine.h"
 #include "BarOverlayElement.h"
+#include "RadarObject.h"
 #include "RadarOverlayElement.h"
+#include "Navigation.h"
 #include "OverlayElementFactories.h"
 
 namespace orxonox
 {
+    SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User);
+    SetConsoleCommandShortcut(HUD, toggleFPS).setAccessLevel(AccessLevel::User);
+    SetConsoleCommandShortcut(HUD, toggleRenderTime).setAccessLevel(AccessLevel::User);
+
     using namespace Ogre;
 
-    HUD::HUD(int zoom){
+    HUD::HUD(){
         om = &Ogre::OverlayManager::getSingleton();
-
-		// create Factories
+        sm = GraphicsEngine::getSingleton().getSceneManager();
+        showFPS = true;
+        showRenderTime = true;
+
+        // create Factories
         BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
         om->addOverlayElementFactory(barOverlayElementFactory);
@@ -56,12 +69,24 @@
         orxonoxHUD = om->create("Orxonox/HUD");
         container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
-        // test
-        test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123"));
-        test->show();
-        test->setMetricsMode(Ogre::GMM_RELATIVE);
-        test->setDimensions(0.8, 0.8);
-        test->setPosition(0.02, 0.02);
-        test->setFontName("Console");
-        test->setCaption("init");
+
+        // creating text to display fps
+        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
+        fpsText->show();
+        fpsText->setMetricsMode(Ogre::GMM_PIXELS);
+        fpsText->setDimensions(0.001, 0.001);
+        fpsText->setPosition(10, 10);
+        fpsText->setFontName("Console");
+        fpsText->setCharHeight(20);
+        fpsText->setCaption("init");
+
+        // creating text to display render time ratio
+        rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText"));
+        rTRText->show();
+        rTRText->setMetricsMode(Ogre::GMM_PIXELS);
+        rTRText->setDimensions(0.001, 0.001);
+        rTRText->setPosition(10, 30);
+        rTRText->setFontName("Console");
+        rTRText->setCharHeight(20);
+        rTRText->setCaption("init");
 
         // create energy bar
@@ -75,5 +100,8 @@
         radar->show();
 
-		// set up screen-wide container
+        // create Navigation
+        nav = new Navigation(container);
+
+        // set up screen-wide container
         container->show();
 
@@ -85,25 +113,36 @@
         container->setHeight(1.0);
         container->setMetricsMode(Ogre::GMM_RELATIVE);
-        container->addChild(test);
+        container->addChild(fpsText);
+        container->addChild(rTRText);
+
         energyBar->init(0.01, 0.94, 0.4, container);
         energyBar->setValue(1);
+
         speedoBar->init(0.01, 0.90, 0.4, container);
+
         radar->init(0.5, 0.9, 0.2, container);
-        radar->addObject(Vector3(1500.0, 0.0, 100.0));
-        radar->addObject(Vector3(0.0, 4000.0, 0.0));
-        radar->addObject(Vector3(0.0, 0.0, 6800.0));
-        RadarOverlayElement::cycleFocus();
+        SceneNode* node;
+        node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0));
+        addRadarObject(node);
+        node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0));
+        addRadarObject(node);
+        node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0));
+        addRadarObject(node);
+	node = sm->getRootSceneNode()->createChildSceneNode("station", Vector3(10000.0,16000.0,0.0));
+        addRadarObject(node, 3);
+    }
+
+    HUD::~HUD(){
+        //todo: clean up objects
     }
 
     void HUD::tick(float dt)
     {
-        int d = radar->getDist2Focus()/10;
-        if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
-        else test->setCaption("");
-
         energyBar->resize();
 
-        float v = SpaceShip::instance_s->getVelocity().length();
-        float vmax = SpaceShip::instance_s->getMaxSpeed();
+        if(!SpaceShip::getLocalShip())
+          return;
+        float v = SpaceShip::getLocalShip()->getVelocity().length();
+        float vmax = SpaceShip::getLocalShip()->getMaxSpeed();
         speedoBar->setValue(v/vmax);
         speedoBar->resize();
@@ -111,7 +150,75 @@
         radar->resize();
         radar->update();
-    }
-
-    HUD::~HUD(void){
+
+        nav->update();
+
+        setFPS();
+    }
+
+    void HUD::setRenderTimeRatio(float ratio)
+    {
+        if(showRenderTime){
+            rTRText->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio));
+        }
+        else{
+            rTRText->setCaption("");
+            return;
+        }
+    }
+
+    void HUD::setFPS(){
+        if(showFPS){
+            float fps = GraphicsEngine::getSingleton().getAverageFPS();
+            fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
+        }
+        else{
+            fpsText->setCaption("");
+            return;
+        }
+    }
+
+    void HUD::addRadarObject(SceneNode* node, int colour){
+        RadarObject* obj = new RadarObject(container, node, colour);
+        roSet.insert(obj);
+//        // check if this is the first RadarObject to create
+//        if(firstRadarObject == NULL){
+//            firstRadarObject = new RadarObject(container, node, colour);
+//            lastRadarObject = firstRadarObject;
+//        }
+//        else{ // if not, append to list
+//            lastRadarObject->next = new RadarObject(container, node, colour);
+//            lastRadarObject = lastRadarObject->next;
+//        }
+    }
+
+    void HUD::removeRadarObject(Ogre::SceneNode* node){
+      COUT(3) << "blabla" << std::endl;
+        for(std::set<RadarObject*>::iterator it=roSet.begin(); it!=roSet.end(); it++){
+            if((*it)->getNode() == node) {
+                delete (*it);
+                roSet.erase(it);
+            }
+        }
+    }
+
+    /*static*/ HUD& HUD::getSingleton(){
+        static HUD theInstance;
+        return theInstance;
+    }
+
+    /*static*/ void HUD::setEnergy(float value){
+        HUD::getSingleton().energyBar->setValue(value);
+    }
+
+    /*static*/ void HUD::cycleNavigationFocus(){
+        HUD::getSingleton().nav->cycleFocus();
+    }
+
+    /*static*/ void HUD::toggleFPS(){
+        HUD::getSingleton().showFPS = !HUD::getSingleton().showFPS;
+    }
+
+    /*static*/ void HUD::toggleRenderTime(){
+        HUD::getSingleton().showRenderTime = !HUD::getSingleton().showRenderTime;
     }
 }
