Index: code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc~
===================================================================
--- code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc~	(revision 1308)
+++ code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc~	(revision 1335)
@@ -41,4 +41,5 @@
 #include <OgreStringConverter.h>
 #include "RadarOverlayElement.h"
+#include "GraphicsEngine.h"
 
 namespace orxonox
@@ -52,71 +53,96 @@
     }
 
-    void RadarOverlayElement::initialise(){
-        PanelOverlayElement::initialise();
-    }
-
-    void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){
-        dim_ = dim;
-        left_ = left;
-        top_ = top;
-        count_ = 100;
+    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
+		om = &Ogre::OverlayManager::getSingleton();        
+        dimRel_ = dimRel;
+        leftRel_ = leftRel;
+        topRel_ = topRel;
         container_ = container;
 
         shipPos_ = Vector3(0.0, 0.0, 0.0);
-        targetPos_ = Vector3(42.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_;
-     
+
         setMetricsMode(Ogre::GMM_PIXELS);
-        setPosition(left,top);
-        setDimensions(dim_,dim_);
         setMaterialName("Orxonox/Radar");
-
-        om = &Ogre::OverlayManager::getSingleton();
-        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
-        point->show();
-        container->addChild(point);
-        point->setMaterialName("Orxonox/RedPoint");
-        point->setDimensions(5,5);
-        point->setMetricsMode(Ogre::GMM_PIXELS);
-
+        resize();
+        
+        container_->addChild(this);
     }
 
-//    void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
-//        dirX_=dirX;
-//        dirY_=dirY;
-//        dirZ_=dirZ;
-//        ortX_=ortX;
-//        ortY_=ortY;
-//        ortZ_=ortZ;
-//    }
+    void RadarOverlayElement::resize() {
+        // if window is resized, we must adapt these...
+        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
+        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
+        dim_ = dimRel_*windowH_;
+        left_ = leftRel_*windowW_-dim_/2;
+        top_ = topRel_*windowH_-dim_/2;
+        setPosition(left_, top_);
+        setDimensions(dim_,dim_);
+    }
 
     void RadarOverlayElement::update() {
-    	if(count_++ >= 100) {		// for testing purposes
-			count_ = 0;
-			COUT(3) << "pos:  " << shipPos_ << std::endl;
-			COUT(3) << "dir:  " << currentDir_ << std::endl;
-			COUT(3) << "orth: " << currentOrth_ << std::endl << std::endl;     	
-    	}
         shipPos_ = SpaceShip::instance_s->getPosition();
         currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; 		// according to beni....
 		currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
+
+		if(tomato_ == NULL) return;		
 		
-		radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
-        phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
-        vec_ = currentDir_.crossProduct(currentOrth_);
-        if(vec_.dotProduct(targetPos_ - shipPos_) > 0) right_ = true;
-        else right_=false;
-        
-        if (right_){
-            point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);         
+		tomato_->radius_ = acos((currentDir_.dotProduct(tomato_->pos_ - shipPos_))/
+			((tomato_->pos_ - shipPos_).length()*currentDir_.length()));
+        tomato_->phi_ = acos((currentOrth_.dotProduct(tomato_->pos_ - shipPos_))/
+        	((tomato_->pos_ - shipPos_).length()*currentOrth_.length()));
+        if((currentDir_.crossProduct(currentOrth_)).dotProduct(tomato_->pos_ - shipPos_) > 0) 
+        	tomato_->right_ = true;
+        else tomato_->right_=false;
+
+        if (tomato_->right_){
+            tomato_->panel_->setPosition(sin(tomato_->phi_)*tomato_->radius_/
+            	3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2);
         }
         else {
-            point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
+            tomato_->panel_->setPosition(-sin(tomato_->phi_)*tomato_->radius_/
+            	3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2);
         }
+        COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
+        COUT(3) << tomato_->radius_ << "  " << tomato_->phi_ << std::endl;
+        COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
     }
-
+    
+    void RadarOverlayElement::addObject(Vector3 pos){
+		tomato_ = new RadarObject(container_);
+		tomato_->pos_ = pos;
+	}
+	
+	//// RadarObject ////
+	
+	int RadarObject::count = 0;
+	
+	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(){
+		om = &Ogre::OverlayManager::getSingleton();
+		panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
+			"Object"+Ogre::StringConverter::toString(count++)));
+		panel_->setMaterialName("Orxonox/RedDot");
+		panel_->setDimensions(5,5);
+        panel_->setMetricsMode(Ogre::GMM_PIXELS);
+        panel_->show();
+        container_->addChild(panel_);
+	}
 }
 
