Index: code/trunk/src/orxonox/hud/Navigation.cc
===================================================================
--- code/trunk/src/orxonox/hud/Navigation.cc	(revision 1568)
+++ code/trunk/src/orxonox/hud/Navigation.cc	(revision 1580)
@@ -48,5 +48,6 @@
     using namespace Ogre;
 
-    Navigation::Navigation(OverlayContainer* container){
+    Navigation::Navigation(OverlayContainer* container)
+    {
         container_ = container;
         focus_ = NULL;
@@ -54,10 +55,4 @@
     }
 
-    Navigation::Navigation(OverlayContainer* container, RadarObject* focus){
-        container_ = container;
-        focus_ = focus;
-        init();
-    }
-
     Navigation::~Navigation()
     {
@@ -67,5 +62,6 @@
     }
 
-    void Navigation::init(){
+    void Navigation::init()
+    {
         // create nav text
         navText_ = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("TextArea", "navText"));
@@ -95,5 +91,6 @@
     }
 
-    void Navigation::update(){
+    void Navigation::update()
+    {
         if (!focus_)
             return;
@@ -102,5 +99,6 @@
     }
 
-    void Navigation::updateMarker(){
+    void Navigation::updateMarker()
+    {
         int windowW = GraphicsEngine::getSingleton().getWindowWidth();
         int windowH = GraphicsEngine::getSingleton().getWindowHeight();
@@ -134,8 +132,11 @@
         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 > Ogre::Math::PI / 2) outOfView = true;
-
-        if(outOfView){
+        if (!outOfView && radius > Ogre::Math::PI / 2)
+            outOfView = true;
+
+        if (outOfView)
+        {
             // object is not in view
             navMarker_->setMaterialName("Orxonox/NavArrows");
@@ -147,7 +148,9 @@
             float phiNav = atan((float) xFromCenter / (float) yFromCenter);
 
-            if(isAbove && isRight){
+            if (isAbove && isRight)
+            {
                 // top right quadrant
-                if(-phiNav<phiUpperCorner){
+                if (-phiNav < phiUpperCorner)
+                {
                     //COUT(3) << "arrow up\n";
                     navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0);
@@ -156,5 +159,6 @@
                     navText_->setTop(navMarker_->getHeight());
                 }
-                else {
+                else
+                {
                     //COUT(3) << "arrow right\n";
                     navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2);
@@ -164,7 +168,9 @@
                 }
             }
-            if(!isAbove && isRight){
+            if (!isAbove && isRight)
+            {
                 // bottom right quadrant
-                if(phiNav<phiUpperCorner) {
+                if (phiNav < phiUpperCorner)
+                {
                     //COUT(3) << "arrow down\n";
                     navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16);
@@ -173,5 +179,6 @@
                     navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
                 }
-                else {
+                else
+                {
                     //COUT(3) << "arrow right\n";
                     navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2);
@@ -181,7 +188,9 @@
                 }
             }
-            if(isAbove && !isRight){
+            if (isAbove && !isRight)
+            {
                 // top left quadrant
-                if(phiNav<phiUpperCorner){
+                if (phiNav<phiUpperCorner)
+                {
                     //COUT(3) << "arrow up\n";
                     navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0);
@@ -190,5 +199,6 @@
                     navText_->setTop(navMarker_->getHeight());
                 }
-                else {
+                else
+                {
                     //COUT(3) << "arrow left\n";
                     navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2);
@@ -198,7 +208,9 @@
                 }
             }
-            if(!isAbove && !isRight){
+            if (!isAbove && !isRight)
+            {
                 // bottom left quadrant
-                if(phiNav>-phiUpperCorner) {
+                if (phiNav>-phiUpperCorner)
+                {
                     //COUT(3) << "arrow down\n";
                     navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16);
@@ -207,5 +219,6 @@
                     navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
                 }
-                else {
+                else
+                {
                     //COUT(3) << "arrow left\n";
                     navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2);
@@ -216,5 +229,6 @@
             }
         }
-        else{
+        else
+        {
             // object is in view
             navMarker_->setMaterialName("Orxonox/NavTDC");
@@ -230,6 +244,8 @@
     }
 
-    void Navigation::cycleFocus(){
-        if(focus_ == NULL){
+    void Navigation::cycleFocus()
+    {
+        if (!focus_)
+        {
             // Get closest object
             float distance = (unsigned int) -1;
@@ -255,29 +271,36 @@
                 HUD::getSingleton().getRadarObjects().insert(HUD::getSingleton().getRadarObjects().begin(), focus_);
                 it_ = HUD::getSingleton().getRadarObjects().begin();
-                ++it_;
-            }
-        }
-        else{
+            }
+        }
+        else if (it_ != HUD::getSingleton().getRadarObjects().end())
+        {
             focus_->resetMaterial();
-            if(it_ != HUD::getSingleton().getRadarObjects().end()){
+            ++it_;
+            if (it_ != HUD::getSingleton().getRadarObjects().end())
                 focus_ = *it_;
-                ++it_;
-            }
-            else focus_ = NULL;
+            else
+                focus_ = 0;
+        }
+        else
+        {
+            focus_ = 0;
         }
         updateFocus();
     }
 
-    void Navigation::updateFocus(){
-        if(focus_ == NULL){
+    void Navigation::updateFocus()
+    {
+        if (focus_)
+        {
+            navMarker_->show();
+            navText_->show();
+            focus_->setColour(ColourValue::White);
+        }
+        else
+        {
             navMarker_->hide();
             aimMarker_->hide();
             navText_->hide();
         }
-        else{
-            navMarker_->show();
-            navText_->show();
-            focus_->setColour(ColourValue::White);
-        }
     }
 
@@ -285,11 +308,13 @@
     {
         this->focus_ = 0;
-        this->it_ = HUD::getSingleton().getRadarObjects().end();
         this->updateFocus();
     }
 
-    float Navigation::getDist2Focus() const {
-        if(focus_ == NULL) return(0.0);
-        return((focus_->getPosition()-SpaceShip::getLocalShip()->getPosition()).length());
+    float Navigation::getDist2Focus() const
+    {
+        if (focus_)
+            return (focus_->getPosition() - SpaceShip::getLocalShip()->getPosition()).length();
+        else
+            return 0;
     }
 }
