Index: code/trunk/src/orxonox/hud/BarOverlayElement.cc
===================================================================
--- code/trunk/src/orxonox/hud/BarOverlayElement.cc	(revision 1407)
+++ code/trunk/src/orxonox/hud/BarOverlayElement.cc	(revision 1502)
@@ -1,40 +1,40 @@
 /*
-*   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 "BarOverlayElement.h"
 #include <OgreOverlayManager.h>
-#include <OgreOverlayElement.h>
-#include <OgrePanelOverlayElement.h>
 #include "GraphicsEngine.h"
-#include "BarOverlayElement.h"
 
 namespace orxonox
 {
-  using namespace Ogre;
+    using namespace Ogre;
 
-    BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
+    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
         name_ = name;
     }
@@ -42,8 +42,8 @@
     BarOverlayElement::~BarOverlayElement(){}
 
-    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
+    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
         // init some values...
         container_ = container;
-        om = &Ogre::OverlayManager::getSingleton();
+        om = &OverlayManager::getSingleton();
         value_ = 0;
         color_ = 2;
@@ -53,10 +53,10 @@
         topRel_ = topRel;
         dimRel_ = dimRel;
-        
+
         // create background...
         background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
         background_->show();
         container_->addChild(background_);
-        background_->setMetricsMode(Ogre::GMM_PIXELS);
+        background_->setMetricsMode(GMM_PIXELS);
         background_->setMaterialName("Orxonox/BarBackground");
 
@@ -65,5 +65,5 @@
 
         show();
-        setMetricsMode(Ogre::GMM_PIXELS);
+        setMetricsMode(GMM_PIXELS);
         setMaterialName("Orxonox/Green");
         background_->addChild(this);
@@ -126,4 +126,2 @@
     }
 }
-
-
Index: code/trunk/src/orxonox/hud/BarOverlayElement.h
===================================================================
--- code/trunk/src/orxonox/hud/BarOverlayElement.h	(revision 1407)
+++ code/trunk/src/orxonox/hud/BarOverlayElement.h	(revision 1502)
@@ -1,41 +1,37 @@
 /*
-*   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
+ *
+ */
 
+#ifndef _BarOverlayElement_H__
+#define _BarOverlayElement_H__
 
-#ifndef _BAR_H__
-#define _BAR_H__
-
-#include <OgreOverlayManager.h>
-#include <OgreOverlayElement.h>
-#include <OgrePanelOverlayElement.h>
+#include "OrxonoxPrereqs.h"
 
 #include <OgrePrerequisites.h>
-#include "../OrxonoxPrereqs.h"
-
-
+#include <OgrePanelOverlayElement.h>
 
 namespace orxonox
@@ -44,37 +40,35 @@
   {
     private:
-        bool autoColor_;                    // whether bar changes color automatically
-        float value_;                       // progress of bar
-        int color_;
-        int left_;
-        int top_;
-        int width_;
-        int height_;
-        int windowW_, windowH_;
-        Ogre::Real leftRel_;
-        Ogre::Real topRel_;
-        Ogre::Real dimRel_;
-        Ogre::OverlayManager* om;           // our overlay manager
-        Ogre::OverlayContainer* container_; // our parent container to attach to
-        Ogre::OverlayContainer* background_;
-        Ogre::String name_;
+      bool autoColor_;                    // whether bar changes color automatically
+      float value_;                       // progress of bar
+      int color_;
+      int left_;
+      int top_;
+      int width_;
+      int height_;
+      int windowW_, windowH_;
+      Ogre::Real leftRel_;
+      Ogre::Real topRel_;
+      Ogre::Real dimRel_;
+      Ogre::OverlayManager* om;           // our overlay manager
+      Ogre::OverlayContainer* container_; // our parent container to attach to
+      Ogre::OverlayContainer* background_;
+      Ogre::String name_;
 
     public:
-        bool left2Right;
-        static const int RED = 0;           // predefined colors
-        static const int YELLOW = 1;
-        static const int GREEN = 2;
+      bool left2Right;
+      static const int RED = 0;           // predefined colors
+      static const int YELLOW = 1;
+      static const int GREEN = 2;
 
-        BarOverlayElement(const Ogre::String& name);
-        virtual ~BarOverlayElement();
-        void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
-        void resize();
-        void setValue(float value);
-        void setColor(int color);
-        float getValue();
-        int getBarColor();
+      BarOverlayElement(const Ogre::String& name);
+      virtual ~BarOverlayElement();
+      void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
+      void resize();
+      void setValue(float value);
+      void setColor(int color);
+      float getValue();
+      int getBarColor();
     };
 }
-#endif
-
-
+#endif /* _BarOverlayElement_H__ */
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;
     }
 }
Index: code/trunk/src/orxonox/hud/HUD.h
===================================================================
--- code/trunk/src/orxonox/hud/HUD.h	(revision 1407)
+++ code/trunk/src/orxonox/hud/HUD.h	(revision 1502)
@@ -1,28 +1,29 @@
 /*
-*   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
+ *
+ */
 
 
@@ -30,14 +31,11 @@
 #define _HUD_H__
 
-#include <string.h>
-#include <OgreOverlayElement.h>
+#include "OrxonoxPrereqs.h"
+
+#include <OgrePrerequisites.h>
 #include <OgreTextAreaOverlayElement.h>
-#include <OgrePrerequisites.h>
-
-#include "OrxonoxPrereqs.h"
+#include <OgreSceneNode.h>
 #include "core/Tickable.h"
-#include "BarOverlayElement.h"
-#include "RadarOverlayElement.h"
-
+#include "util/Math.h"
 
 namespace orxonox
@@ -45,20 +43,39 @@
     class _OrxonoxExport HUD : public Tickable
     {
-        private:
-            Ogre::OverlayManager* om;
-            Ogre::Overlay* orxonoxHUD;
-            Ogre::OverlayContainer* container;
-            Ogre::TextAreaOverlayElement* test;
-            BarOverlayElement* energyBar;
-            BarOverlayElement* speedoBar;
-            RadarOverlayElement* radar;
+      private:
+        HUD();
+        HUD(HUD& instance);
+        ~HUD();
+        Ogre::OverlayManager* om;
+        Ogre::SceneManager* sm;
+        Ogre::Overlay* orxonoxHUD;
+        Ogre::OverlayContainer* container;
+        Ogre::TextAreaOverlayElement* fpsText;
+        Ogre::TextAreaOverlayElement* rTRText;
+        BarOverlayElement* energyBar;
+        BarOverlayElement* speedoBar;
+        RadarOverlayElement* radar;
+        Navigation* nav;
 
-        public:
-            HUD(int zoom);
-            ~HUD();
-            virtual void tick(float);
+        bool showFPS;
+        bool showRenderTime;
 
+      public:
+        virtual void tick(float);
+        void addRadarObject(Ogre::SceneNode* node, int colour = 0);
+        void removeRadarObject(Ogre::SceneNode* node);
+        void setRenderTimeRatio(float ratio);
+        void setFPS();
+
+        std::set<RadarObject*> roSet;
+
+        static HUD* instance_s;
+        static HUD& getSingleton();
+        static void setEnergy(float value);
+        static void cycleNavigationFocus();
+        static void toggleFPS();
+        static void toggleRenderTime();
     };
 }
 
-#endif
+#endif /* _HUD_H__ */
Index: code/trunk/src/orxonox/hud/Navigation.cc
===================================================================
--- code/trunk/src/orxonox/hud/Navigation.cc	(revision 1502)
+++ code/trunk/src/orxonox/hud/Navigation.cc	(revision 1502)
@@ -0,0 +1,234 @@
+/*
+ *   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:
+ *      Felix Schulthess
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "Navigation.h"
+
+#include <OgreOverlayManager.h>
+#include <OgreStringConverter.h>
+
+#include "GraphicsEngine.h"
+// TODO: remove the SpaceShip and CameraHandler dependencies
+#include "objects/SpaceShip.h"
+#include "objects/CameraHandler.h"
+#include "RadarObject.h"
+#include "RadarOverlayElement.h"
+#include "HUD.h"
+#include "core/Debug.h"
+
+namespace orxonox
+{
+    using namespace Ogre;
+
+    Navigation::Navigation(OverlayContainer* container){
+        container_ = container;
+        focus_ = NULL;
+        init();
+    }
+
+    Navigation::Navigation(OverlayContainer* container, RadarObject* focus){
+        container_ = container;
+        focus_ = focus;
+        init();
+    }
+
+    void Navigation::init(){
+        om = &OverlayManager::getSingleton();
+        navCam_ = NULL;
+        // create nav text
+        navText_ = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "navText"));
+        navText_->show();
+        navText_->setMetricsMode(Ogre::GMM_PIXELS);
+        navText_->setDimensions(0.001, 0.001);
+        navText_->setPosition(0.02, 0.02);
+        navText_->setFontName("Console");
+        navText_->setCharHeight(20);
+        navText_->setCaption("");
+        container_->addChild(navText_);
+
+
+        // create nav marker ...
+        navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
+        navMarker_->setMetricsMode(GMM_PIXELS);
+        navMarker_->hide();
+        navText_->hide();
+        container_->addChild(navMarker_);
+    }
+
+    void Navigation::update(){
+        if(focus_ == NULL) return;
+        navCamPos_ = SpaceShip::getLocalShip()->getPosition();
+        currentDir_ = SpaceShip::getLocalShip()->getDir();
+        currentOrth_ = SpaceShip::getLocalShip()->getOrth();
+
+        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
+        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
+        updateMarker();
+    }
+
+    void Navigation::updateMarker(){
+        // set text
+        int dist = (int) getDist2Focus()/100;
+        navText_->setCaption(Ogre::StringConverter::toString(dist));
+
+        if(navCam_ == NULL) navCam_ = SpaceShip::getLocalShip()->getCamera()->cam_;
+        Vector3 pos = focus_->getPosition();
+        // transform to screen coordinates
+        pos = navCam_->getProjectionMatrix()*navCam_->getViewMatrix()*pos;
+        float xPosRel = 0.5*pos.x+0.5;
+        float yPosRel = 1-(0.5*pos.y+0.5);
+        int xPos = (int) (xPosRel*windowW_);
+        int yPos = (int) (yPosRel*windowH_);
+        int xFromCenter = xPos-windowW_/2;
+        int yFromCenter = yPos-windowH_/2;
+        // is object in view?
+        float radius = RadarOverlayElement::calcRadius(navCamPos_, currentDir_, currentOrth_, focus_);
+        bool isRight = (currentDir_.crossProduct(currentOrth_)).dotProduct(focus_->getPosition() - navCamPos_)>0;
+        bool isAbove = currentOrth_.dotProduct(focus_->getPosition() - navCamPos_)>0;
+        bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1);
+        // if object is behind us, it is out of view anyway:
+        if(!outOfView && radius>3.14/2) outOfView = true;
+
+        if(outOfView){
+            // object is not in view
+            navMarker_->setMaterialName("Orxonox/NavArrows");
+            navMarker_->setDimensions(16,16);
+            float phiUpperCorner = atan((float)(windowW_)/(float)(windowH_));
+            // from the angle we find out on which edge to draw the marker
+            // and which of the four arrows to take
+            float phiNav = atan((float) xFromCenter / (float) yFromCenter);
+
+            if(isAbove && isRight){
+                // top right quadrant
+                if(-phiNav<phiUpperCorner){
+                    //COUT(3) << "arrow up\n";
+                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
+                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
+                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getHeight());
+                }
+                else {
+                    //COUT(3) << "arrow right\n";
+                    navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
+                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
+                    navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
+                }
+            }
+            if(!isAbove && isRight){
+                // bottom right quadrant
+                if(phiNav<phiUpperCorner) {
+                    //COUT(3) << "arrow down\n";
+                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
+                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
+                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
+                }
+                else {
+                    //COUT(3) << "arrow right\n";
+                    navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
+                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
+                    navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
+                }
+            }
+            if(isAbove && !isRight){
+                // top left quadrant
+                if(phiNav<phiUpperCorner){
+                    //COUT(3) << "arrow up\n";
+                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
+                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
+                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getHeight());
+                }
+                else {
+                    //COUT(3) << "arrow left\n";
+                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
+                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
+                    navText_->setLeft(navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
+                }
+            }
+            if(!isAbove && !isRight){
+                // bottom left quadrant
+                if(phiNav>-phiUpperCorner) {
+                    //COUT(3) << "arrow down\n";
+                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
+                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
+                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
+                }
+                else {
+                    //COUT(3) << "arrow left\n";
+                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
+                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
+                    navText_->setLeft(navMarker_->getWidth());
+                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
+                }
+            }
+        }
+        else{
+            // object is in view
+            navMarker_->setMaterialName("Orxonox/NavTDC");
+            navMarker_->setDimensions(24,24);
+            navMarker_->setUV(0.0, 0.0, 1.0, 1.0);
+            navMarker_->setPosition(xPos-navMarker_->getWidth()/2, yPos-navMarker_->getHeight()/2);
+            navText_->setPosition(xPos+navMarker_->getWidth()/2, yPos+navMarker_->getHeight()/2);
+        }
+    }
+
+    void Navigation::cycleFocus(){
+        if(focus_ == NULL){
+            it_ = HUD::getSingleton().roSet.begin();
+            focus_ = *it_;
+            ++it_;
+        }
+        else{
+            focus_->resetColour();
+            if(it_ != HUD::getSingleton().roSet.end()){
+                focus_ = *it_;
+                ++it_;
+            }
+            else focus_ = NULL;
+        }
+        if(focus_ == NULL){
+            navMarker_->hide();
+            navText_->hide();
+        }
+        else{
+            navMarker_->show();
+            navText_->show();
+            focus_->setColour(RadarObject::WHITE);
+        }
+    }
+
+    float Navigation::getDist2Focus(){
+        if(focus_ == NULL) return(0.0);
+        return((focus_->getPosition()-SpaceShip::getLocalShip()->getPosition()).length());
+    }
+}
Index: code/trunk/src/orxonox/hud/Navigation.h
===================================================================
--- code/trunk/src/orxonox/hud/Navigation.h	(revision 1502)
+++ code/trunk/src/orxonox/hud/Navigation.h	(revision 1502)
@@ -0,0 +1,70 @@
+/*
+ *   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:
+ *      Felix Schulthess
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Navigation_H__
+#define _Navigation_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <OgrePrerequisites.h>
+#include <OgreTextAreaOverlayElement.h>
+#include <OgrePanelOverlayElement.h>
+#include "util/Math.h"
+
+namespace orxonox
+{
+
+    class _OrxonoxExport Navigation
+    {
+      private:
+        Ogre::OverlayManager* om;				            // our one and only overlay manager
+        Ogre::OverlayContainer* container_;
+        Ogre::PanelOverlayElement* navMarker_;      // the panel used to show the arrow
+        Ogre::TextAreaOverlayElement* navText_;     // displaying distance
+        Ogre::Camera* navCam_;
+        Vector3 navCamPos_;                         // position of ship
+        Vector3 currentDir_;
+        Vector3 currentOrth_;
+        std::set<RadarObject*>::iterator it_;
+        int windowW_, windowH_;
+        void init();
+        void updateMarker();
+
+      public:
+        Navigation(Ogre::OverlayContainer* container);
+        Navigation(Ogre::OverlayContainer* container, RadarObject* focus);
+        ~Navigation();
+        RadarObject* focus_;                        // next pointer of linked list
+
+        void update();
+        void cycleFocus();
+        float getDist2Focus();
+  };
+}
+
+#endif /* _Navigation_H__ */
Index: code/trunk/src/orxonox/hud/OverlayElementFactories.h
===================================================================
--- code/trunk/src/orxonox/hud/OverlayElementFactories.h	(revision 1407)
+++ code/trunk/src/orxonox/hud/OverlayElementFactories.h	(revision 1502)
@@ -1,41 +1,45 @@
 /*
-*   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
+ *
+ */
 
-#ifndef _FACTORIES_H__
-#define _FACTORIES_H__
+#ifndef _OverlayElementFactories_H__
+#define _OverlayElementFactories_H__
 
+#include "OrxonoxPrereqs.h"
+
+#include <OgrePrerequisites.h>
 #include <OgreOverlayElement.h>
-#include <OgrePrerequisites.h>
 #include <OgreOverlayElementFactory.h>
 
 #include "BarOverlayElement.h"
+#include "RadarOverlayElement.h"
 
 namespace orxonox{
     class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{
-        public:
+      public:
         Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){
             return new BarOverlayElement(instanceName);
@@ -48,5 +52,5 @@
 
     class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{
-        public:
+      public:
         Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){
             return new RadarOverlayElement(instanceName);
@@ -59,3 +63,3 @@
 }
 
-#endif
+#endif /* _OverlayElementFactories_H__ */
Index: code/trunk/src/orxonox/hud/RadarObject.cc
===================================================================
--- code/trunk/src/orxonox/hud/RadarObject.cc	(revision 1407)
+++ code/trunk/src/orxonox/hud/RadarObject.cc	(revision 1502)
@@ -1,30 +1,36 @@
 /*
-*   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:
-*      Felix Schulthess
-*   Co-authors:
-*      ...
-*
-*/
+ *   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:
+ *      Felix Schulthess
+ *   Co-authors:
+ *      ...
+ *
+ */
 
+#include "OrxonoxStableHeaders.h"
 #include "RadarObject.h"
+
+#include <OgreOverlayManager.h>
+#include <OgreStringConverter.h>
+#include "GraphicsEngine.h"
 
 namespace orxonox
@@ -32,27 +38,15 @@
     using namespace Ogre;
 
-	int RadarObject::count = 0;		// initialize static variable
+    int RadarObject::count = 0;		// initialize static variable
 
-	RadarObject::RadarObject(Ogre::OverlayContainer* container){
-		container_ = container;
-		pos_ = Vector3(0.0, 0.0, 0.0);
-		init();
-	}
-
-	RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){
-		container_ = container;
-		pos_ = pos;
-		init();
-	}
-
-	RadarObject::~RadarObject(){}
-
-	void RadarObject::init(){
-	    next = NULL;
-		om = &Ogre::OverlayManager::getSingleton();
-		panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
-			"Object"+Ogre::StringConverter::toString(count)));
-		panel_->setMaterialName("Orxonox/RedDot");
-		panel_->setDimensions(3,3);
+    RadarObject::RadarObject(OverlayContainer* container, SceneNode* node, int colour){
+        container_ = container;
+        node_ = node;
+        colour_ = colour;
+        om = &OverlayManager::getSingleton();
+        panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
+            "Object"+StringConverter::toString(count)));
+        setColour(colour_);
+        panel_->setDimensions(3,3);
         panel_->setMetricsMode(Ogre::GMM_PIXELS);
         panel_->show();
@@ -60,10 +54,32 @@
         count++;
         container_->addChild(panel_);
-	}
+    }
+
+    RadarObject::~RadarObject(){
+        delete panel_;
+    }
+
+    void RadarObject::setColour(int colour){
+        switch(colour){
+        case RED: panel_->setMaterialName("Orxonox/RedDot"); break;
+        case YELLOW: panel_->setMaterialName("Orxonox/YellowDot"); break;
+        case GREEN: panel_->setMaterialName("Orxonox/GreenDot"); break;
+        case BLUE: panel_->setMaterialName("Orxonox/BlueDot"); break;
+        case WHITE: panel_->setMaterialName("Orxonox/WhiteDot"); break;
+        default: panel_->setMaterialName("Orxonox/RedDot"); break;
+        }
+    }
+
+    void RadarObject::resetColour(){
+        setColour(colour_);
+    }
+
+    Vector3 RadarObject::getPosition(){
+        return node_->getPosition();
+    }
+
+    SceneNode* RadarObject::getNode(){
+        return node_;
+    }
 }
 
-/* my local clipboard...
-COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
-COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
-COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
-*/
Index: code/trunk/src/orxonox/hud/RadarObject.h
===================================================================
--- code/trunk/src/orxonox/hud/RadarObject.h	(revision 1407)
+++ code/trunk/src/orxonox/hud/RadarObject.h	(revision 1502)
@@ -1,41 +1,38 @@
 /*
-*   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:
-*      ...
-*
-*/
+ *   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:
+ *      Felix Schulthess
+ *   Co-authors:
+ *      ...
+ *
+ */
 
-#ifndef _RADAR2_H__
-#define _RADAR2_H__
+#ifndef _RadarObject_H__
+#define _RadarObject_H__
 
-#include <string.h>
 #include <OgrePrerequisites.h>
-#include <OgreOverlayManager.h>
-#include <OgreOverlayElement.h>
+#include <OgreSceneNode.h>
 #include <OgrePanelOverlayElement.h>
-#include <OgreStringConverter.h>
-
-#include <util/Math.h>
-#include "../OrxonoxPrereqs.h"
+#include "OrxonoxPrereqs.h"
+#include "util/Math.h"
 
 namespace orxonox
@@ -43,24 +40,30 @@
     class _OrxonoxExport RadarObject
     {
-    	private:
-    		Ogre::OverlayManager* om;				// our one and only overlay manager
-    		void init();
+      private:
+        Ogre::OverlayManager* om;				// our one and only overlay manager
+        Ogre::SceneNode* node_;					// node of object
+        int colour_;
 
-    	public:
-    		RadarObject(Ogre::OverlayContainer* container);
-    		RadarObject(Ogre::OverlayContainer* container, Vector3 pos);
-    		~RadarObject();
+      public:
+        RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, int colour = 0);
+        ~RadarObject();
+        void setColour(int colour);
+        void resetColour();
+        Vector3 getPosition();
+        Ogre::SceneNode* getNode();
 
-            bool right_;
-            int index_;                             // index number of object
-    		Vector3 pos_;							// position in space
-			Ogre::Real radius_, phi_;				// position on radar
-			Ogre::OverlayContainer* container_;
-			Ogre::PanelOverlayElement* panel_;		// the panel used to show the dot
-			RadarObject* next;                      // next pointer of linked list
+        bool right_;
+        int index_;                             // index number of object
+        Ogre::OverlayContainer* container_;
+        Ogre::PanelOverlayElement* panel_;		// the panel used to show the dot
 
-    		static int count;
-	};
+        static int count;
+        static const int RED = 0;
+        static const int YELLOW = 1;
+        static const int GREEN = 2;
+        static const int BLUE = 3;
+        static const int WHITE = 99;            // used if object got nav focus
+  };
 }
 
-#endif
+#endif /* _RadarObject_H__ */
Index: code/trunk/src/orxonox/hud/RadarOverlayElement.cc
===================================================================
--- code/trunk/src/orxonox/hud/RadarOverlayElement.cc	(revision 1407)
+++ code/trunk/src/orxonox/hud/RadarOverlayElement.cc	(revision 1502)
@@ -1,41 +1,49 @@
 /*
-*   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:
-*      ...
-*
-*/
+ *   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 "RadarOverlayElement.h"
+
+#include <string>
+#include <OgreOverlayManager.h>
+#include <OgreStringConverter.h>
+
+#include "GraphicsEngine.h"
+#include "core/Tickable.h"
+#include "core/ConsoleCommand.h"
+#include "objects/SpaceShip.h"
+#include "RadarObject.h"
+#include "HUD.h"
 
 namespace orxonox
 {
-    ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);
-
     using namespace Ogre;
 
-    RadarOverlayElement* RadarOverlayElement::instance_s = NULL;
-
-    RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
-        RadarOverlayElement::instance_s = this;
+    RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){
     }
 
@@ -43,33 +51,13 @@
     }
 
-    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
+    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
         // some initial data
-		om = &Ogre::OverlayManager::getSingleton();
+        om = &OverlayManager::getSingleton();
         dimRel_ = dimRel;
         leftRel_ = leftRel;
         topRel_ = topRel;
         container_ = container;
-        firstRadarObject_ = NULL;
-        lastRadarObject_ = NULL;
-        focus_ = NULL;
 
-        // create nav marker ...
-        navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
-        navMarker_->setMetricsMode(Ogre::GMM_PIXELS);
-        navMarker_->setMaterialName("Orxonox/NavMarker");
-        navMarker_->setDimensions(16,16);
-        navMarker_->setPosition(0,386);
-        navMarker_->hide();
-        container_->addChild(navMarker_);
-
-        // these have to fit the data in the level
-        shipPos_ = Vector3(0.0, 0.0, 0.0);
-        initialDir_ = Vector3(1.0, 0.0, 0.0);
-        currentDir_ = initialDir_;
-        initialOrth_ = Vector3(0.0, 0.0, 1.0);
-        currentOrth_ = initialOrth_;
-        plane = Plane(currentDir_, shipPos_);
-
-        setMetricsMode(Ogre::GMM_PIXELS);
+        setMetricsMode(GMM_PIXELS);
         setMaterialName("Orxonox/Radar");
         resize();
@@ -90,143 +78,57 @@
 
     void RadarOverlayElement::update() {
-        shipPos_ = SpaceShip::instance_s->getPosition();
-        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; 		// according to beni....
-		currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
-        plane = Plane(currentDir_, shipPos_);
-
-        RadarObject* ro = firstRadarObject_;
+        shipPos_ = SpaceShip::getLocalShip()->getPosition();
+        currentDir_ = SpaceShip::getLocalShip()->getDir();
+        currentOrth_ = SpaceShip::getLocalShip()->getOrth();
         // iterate through all RadarObjects
-		while(ro != NULL){
-		    // calc position on radar...
-            ro->radius_ = calcRadius(ro);
-            ro->phi_ = calcPhi(ro);
-            ro->right_ = calcRight(ro);
+        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
+        // calc position on radar...
+            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it));
+            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it));
+            bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it));
 
             // set size to fit distance...
-            float d = (ro->pos_-shipPos_).length();
-            if(d<4000) ro->panel_->setDimensions(4,4);
-            else if(d<8000) ro->panel_->setDimensions(3,3);
-            else if(d<16000) ro->panel_->setDimensions(2,2);
-            else ro->panel_->setDimensions(1,1);
+            float d = ((*it)->getPosition()-shipPos_).length();
+            if(d<10000) (*it)->panel_->setDimensions(4,4);
+            else if(d<20000) (*it)->panel_->setDimensions(3,3);
+            else (*it)->panel_->setDimensions(2,2);
 
-            if (ro->right_){
-                ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
-                    3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
+            if (right){
+                (*it)->panel_->setPosition(sin(phi)*radius/
+                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
             }
             else {
-                ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
-                    3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
-            }
-            ro = ro->next;
-		}
-		updateNavMarker();
-    }
-
-    void RadarOverlayElement::updateNavMarker(){
-        if(focus_ == NULL) return;
-        // from the angle we find out where to draw the marker
-        // and which of the four arrows to take
-        float r1 = atan((float)(windowW_)/(float)(windowH_));
-        float phi = focus_->phi_;
-        if(focus_->right_){
-            if(phi<r1){
-                navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
-                navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
-            }
-            else if(phi>3.14-r1){
-                navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
-                navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
-            }
-            else {
-                navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
-                navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
-            }
-        }
-        else{
-            if(phi<r1) {
-                navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
-                navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
-            }
-            else if(phi>3.14-r1) {
-                navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
-                navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
-            }
-            else {
-                navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
-                navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
+                (*it)->panel_->setPosition(-sin(phi)*radius/
+                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
             }
         }
     }
 
-    void RadarOverlayElement::addObject(Vector3 pos){
-        if(firstRadarObject_ == NULL){
-            firstRadarObject_ = new RadarObject(container_, pos);
-            lastRadarObject_ = firstRadarObject_;
+    void RadarOverlayElement::listObjects(){
+        int i = 0;
+        COUT(3) << "List of RadarObjects:\n";
+        // iterate through all Radar Objects
+        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
+            COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl;
         }
-        else{
-            lastRadarObject_->next = new RadarObject(container_, pos);
-            lastRadarObject_ = lastRadarObject_->next;
-        }
-	}
+    }
 
-	void RadarOverlayElement::listObjects(){
-	    int i = 0;
-	    RadarObject* ro = firstRadarObject_;
-	    COUT(3) << "List of RadarObjects:\n";
-	    // iterate through all Radar Objects
-	    while(ro != NULL) {
-	        COUT(3) << i++ << ": " << ro->pos_ << std::endl;
-	        ro = ro->next;
-	    }
-	}
+    float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
+        return(acos((dir.dotProduct(obj->getPosition() - pos))/
+        ((obj->getPosition() - pos).length()*dir.length())));
+    }
 
-	float RadarOverlayElement::getDist2Focus(){
-	    if(focus_ == NULL) return(0.0);
-	    return((focus_->pos_-shipPos_).length());
-	}
+    float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
+        // project difference vector on our plane...
+        Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos);
+        // ...and find out the angle
+        return(acos((orth.dotProduct(proj))/
+              (orth.length()*proj.length())));
+    }
 
-	float RadarOverlayElement::calcRadius(RadarObject* obj){
-	    return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
-			((obj->pos_ - shipPos_).length()*currentDir_.length())));
-	}
-
-	float RadarOverlayElement::calcPhi(RadarObject* obj){
-	    // project difference vector on our plane...
-	    Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);
-	    // ...and find out the angle
-	    return(acos((currentOrth_.dotProduct(proj))/
-            (currentOrth_.length()*proj.length())));
-	}
-
-	bool RadarOverlayElement::calcRight(RadarObject* obj){
-	    if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
-        	return true;
+    bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
+        if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0)
+            return true;
         else return false;
-	}
-
-	/*static*/void RadarOverlayElement::cycleFocus(){
-	    if(RadarOverlayElement::instance_s == NULL) return;
-
-	    if(RadarOverlayElement::instance_s->focus_ == NULL){
-            RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_;
-	    }
-        else{
-            RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot");
-            RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next;
-        }
-
-        if(RadarOverlayElement::instance_s->focus_ == NULL){
-            RadarOverlayElement::instance_s->navMarker_->hide();
-        }
-        else{
-            RadarOverlayElement::instance_s->navMarker_->show();
-            RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot");
-        }
-	}
+    }
 }
-
-/* my local clipboard...
-COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
-COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
-COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
-*/
Index: code/trunk/src/orxonox/hud/RadarOverlayElement.h
===================================================================
--- code/trunk/src/orxonox/hud/RadarOverlayElement.h	(revision 1407)
+++ code/trunk/src/orxonox/hud/RadarOverlayElement.h	(revision 1502)
@@ -1,47 +1,38 @@
 /*
-*   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:
-*      ...
-*
-*/
+ *   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
+ *
+ */
 
-#ifndef _RADAR_H__
-#define _RADAR_H__
+#ifndef _RadarOverlayElement_H__
+#define _RadarOverlayElement_H__
 
-#include <string.h>
-#include <OgreOverlayManager.h>
-#include <OgreStringConverter.h>
-#include <OgreOverlayElement.h>
+#include "OrxonoxPrereqs.h"
+
+#include <OgrePrerequisites.h>
 #include <OgrePanelOverlayElement.h>
-#include <OgrePrerequisites.h>
-
-#include <util/Math.h>
-#include <string.h>
-#include "core/Tickable.h"
-#include "core/ConsoleCommand.h"
-#include "objects/SpaceShip.h"
-#include "../OrxonoxPrereqs.h"
-#include "RadarObject.h"
-#include "GraphicsEngine.h"
+#include "util/Math.h"
 
 namespace orxonox
@@ -49,41 +40,28 @@
     class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement
     {
-        private:
-            Ogre::OverlayManager* om;               // our one and only overlay manager
-            Ogre::OverlayContainer* container_;     // pointer to the container we're in
-            Vector3 initialDir_;	                // direction of nose
-            Vector3 currentDir_;
-            Vector3 initialOrth_;                   // direction of normal
-            Vector3 currentOrth_;
-            Vector3 shipPos_;                       // position of ship
-            Ogre::Plane plane;                      // plane perpendicular to dir
+      private:
+        Ogre::OverlayManager* om;               // our one and only overlay manager
+        Ogre::OverlayContainer* container_;     // pointer to the container we're in
+        Vector3 currentDir_;
+        Vector3 currentOrth_;
+        Vector3 shipPos_;                       // position of ship
 
-            Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
-            int left_, top_, dim_;                  // absolute position/dimension
-            int windowW_, windowH_;             	// absolute window dimensions
+        Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
+        int left_, top_, dim_;                  // absolute position/dimension
+        int windowW_, windowH_;             	  // absolute window dimensions
 
-        public:
-            RadarOverlayElement(const Ogre::String& name);
-            ~RadarOverlayElement();
-            void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
-			void resize();
-            void update();
-            void updateNavMarker();
-            void addObject(Vector3 pos);
-            void listObjects();
-            float getDist2Focus();
-            float calcRadius(RadarObject* obj);
-            float calcPhi(RadarObject* obj);
-            bool calcRight(RadarObject* obj);
+      public:
+        RadarOverlayElement(const Ogre::String& name);
+        ~RadarOverlayElement();
+        void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
+        void resize();
+        void update();
+        void listObjects();
 
-            Ogre::PanelOverlayElement* navMarker_;  // marker to help navigating
-			RadarObject* firstRadarObject_;         // start of linked list
-			RadarObject* lastRadarObject_;          // end of linked list
-			RadarObject* focus_;                    // object that is focussed
-
-            static RadarOverlayElement* instance_s;
-            static void cycleFocus();
-	};
+        static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
+        static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
+        static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
+  };
 }
 
-#endif
+#endif /* _RadarOverlayElement_H__ */
