Index: code/branches/map/src/orxonox/objects/RadarViewable.cc
===================================================================
--- code/branches/map/src/orxonox/objects/RadarViewable.cc	(revision 2913)
+++ code/branches/map/src/orxonox/objects/RadarViewable.cc	(revision 2942)
@@ -35,4 +35,8 @@
 #include "objects/worldentities/WorldEntity.h"
 #include "objects/Radar.h"
+#include "util/String.h"
+#include <OgreManualObject.h>
+#include "overlays/map/Map.h"
+#include "orxonox/tools/DynamicLines.h"
 
 namespace orxonox
@@ -47,6 +51,62 @@
         , MapNode_(NULL)
         , MapEntity_(NULL)
+        , line_(NULL)
     {
         RegisterRootObject(RadarViewable);
+
+        this->uniqueId_=getUniqueNumberString();
+/*
+        if(Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr())
+        {
+            this->addEntity();
+        }
+
+        */
+    }
+
+
+    RadarViewable::~RadarViewable()
+    {
+        delete MapNode_;
+        delete MapEntity_;
+    }
+
+    void RadarViewable::addMapEntity()
+    { //TODO Check shape and add accordantly
+        if( this->MapNode_ && !this->MapEntity_ && Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr() )
+        {
+            COUT(0) << "Adding " << this->uniqueId_ << " to Map.\n";
+            this->MapEntity_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createEntity( this->uniqueId_, "drone.mesh");
+            /*this->line_ =  Map::getSingletonPtr()->getMapSceneManagerPtr()->createManualObject(this->uniqueId_ + "_l"); 
+            this->line_->begin("Map/line_", Ogre::RenderOperation::OT_LINE_STRIP); 
+            //line_->position(0, -it->getRVWorldPosition().y, 0); 
+            //this->line_->position(0, -20, 0); 
+            this->line_->position(0, 0, -10); //Front Arrow
+            this->line_->position(0, 0, 0);
+
+            this->line_->end(); */
+            this->line_ = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
+            this->line_->addPoint( Vector3(0,0,0) );
+            this->line_->addPoint( Vector3(0,0,0) );
+
+            this->MapNode_->attachObject( this->MapEntity_ );
+            this->MapNode_->attachObject( this->line_ );
+        }
+        else
+        {
+            COUT(0) << "Unable to load " << this->uniqueId_ << " to Map.\n";
+        }
+    }
+
+    void RadarViewable::updateMapPosition()
+    {
+        if( this->MapNode_ )
+        {
+            this->MapNode_->setPosition( this->getRVWorldPosition() );
+            this->MapNode_->translate( this->getRVOrientedVelocity(), (Ogre::Node::TransformSpace)3 );
+            this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() );
+Vector3 v = this->getRVWorldPosition();
+            this->line_->setPoint(1, Vector3(0,v.y,0) );
+        }
     }
 
Index: code/branches/map/src/orxonox/objects/RadarViewable.h
===================================================================
--- code/branches/map/src/orxonox/objects/RadarViewable.h	(revision 2913)
+++ code/branches/map/src/orxonox/objects/RadarViewable.h	(revision 2942)
@@ -37,6 +37,9 @@
 #include "core/OrxonoxClass.h"
 
+#include <string>
 #include <OgreSceneNode.h>
 #include <OgreEntity.h>
+#include <OgreManualObject.h>
+#include "orxonox/tools/DynamicLines.h"
 
 namespace orxonox
@@ -55,7 +58,8 @@
         };
 
+
     public:
         RadarViewable();
-        virtual ~RadarViewable() { }
+        virtual ~RadarViewable();
 
         inline void setRadarObjectCamouflage(float camouflage)
@@ -96,5 +100,7 @@
         Ogre::SceneNode * MapNode_;
         Ogre::Entity * MapEntity_;
-
+        DynamicLines* line_;
+        void addMapEntity();
+        void updateMapPosition();
     private:
         void validate(const WorldEntity* object) const
@@ -107,4 +113,7 @@
         }
 
+        
+        std::string uniqueId_;
+
         float radarObjectCamouflage_;
         Shape radarObjectShape_;
Index: code/branches/map/src/orxonox/objects/controllers/HumanController.cc
===================================================================
--- code/branches/map/src/orxonox/objects/controllers/HumanController.cc	(revision 2913)
+++ code/branches/map/src/orxonox/objects/controllers/HumanController.cc	(revision 2942)
@@ -35,4 +35,5 @@
 #include "objects/worldentities/pawns/Pawn.h"
 #include "objects/gametypes/Gametype.h"
+#include "overlays/map/Map.h"
 
 namespace orxonox
@@ -92,4 +93,10 @@
     void HumanController::rotateYaw(const Vector2& value)
     {
+        //Hack to enable mouselook in map
+        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
+        {
+            Map::getSingletonPtr()->rotateYaw(value);
+            return;
+        }
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
             HumanController::localController_s->controllableEntity_->rotateYaw(value);
@@ -98,4 +105,10 @@
     void HumanController::rotatePitch(const Vector2& value)
     {
+        //Hack to enable mouselook in map
+        if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
+        {
+            Map::getSingletonPtr()->rotatePitch(value);
+            return;
+        }
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
             HumanController::localController_s->controllableEntity_->rotatePitch(value);
Index: code/branches/map/src/orxonox/objects/controllers/HumanController.h
===================================================================
--- code/branches/map/src/orxonox/objects/controllers/HumanController.h	(revision 2913)
+++ code/branches/map/src/orxonox/objects/controllers/HumanController.h	(revision 2942)
@@ -66,4 +66,7 @@
             static void killBots(unsigned int amount = 0);
 
+            //friend class, for mouselook
+            friend class Map;
+
         private:
             static HumanController* localController_s;
Index: code/branches/map/src/orxonox/overlays/map/Map.cc
===================================================================
--- code/branches/map/src/orxonox/overlays/map/Map.cc	(revision 2913)
+++ code/branches/map/src/orxonox/overlays/map/Map.cc	(revision 2942)
@@ -28,4 +28,5 @@
  
 #include <string>
+#include "util/String.h"
 #include <OgreSceneManager.h>
 #include <OgreSceneNode.h>
@@ -33,9 +34,10 @@
 #include <OgreNode.h>
 
+
 #include <OgreRenderWindow.h>
 #include <OgreRenderTexture.h>
 #include <OgreTexture.h>
 #include <OgreViewport.h>
-#include <OgreMaterial.h>
+
 #include <OgreMaterialManager.h>
 #include <OgreRoot.h>
@@ -53,14 +55,19 @@
 #include "objects/Scene.h"
 #include "objects/RadarViewable.h"
+#include "objects/controllers/HumanController.h"
  
  namespace orxonox
  {
     CreateFactory(Map);
-     SetConsoleCommand(Map, openMap, true);
+    SetConsoleCommand(Map, openMap, true);
+    SetConsoleCommand(Map, rotateYaw, true).setAsInputCommand();
+    SetConsoleCommand(Map, rotatePitch, true).setAsInputCommand();
+
+    Map* Map::singletonMap_s = 0;
     
     Map::Map(BaseObject* creator) : OrxonoxOverlay(creator)
     {
         RegisterObject(Map);
-        
+        Map::singletonMap_s=this;
         //Getting Scene Manager (Hack)
         ObjectList<Scene>::iterator it = ObjectList<Scene>::begin();
@@ -88,5 +95,5 @@
         */
 	
-        
+        this->mouseLookSpeed_ = 200;
         
 
@@ -99,4 +106,5 @@
         mReflectCam_->setAspectRatio(1);
 
+        //Create overlay material
         std::string camMat_id = "RttMat";
         Ogre::MaterialPtr material = this->createRenderCamera(mReflectCam_, camMat_id);
@@ -145,6 +153,37 @@
         overlay_->hide();
 
-    }
-    
+        //Create plane in map
+        Ogre::Entity* plane_ent = this->mapSceneM_->createEntity( "MapPlane", "plane.mesh");
+        Ogre::SceneNode* plane_node = this->mapSceneM_->getRootSceneNode()->createChildSceneNode();
+        
+        //Ogre::MaterialPtr plane_mat = Ogre::MaterialManager::getSingleton().create("mapgrid", "General");
+        //plane_mat->getTechnique(0)->getPass(0)->createTextureUnitState("mapgrid.tga");
+        //plane_ent->setMaterialName("mapgrid");
+        plane_ent->setMaterialName("Map/Grid");
+        plane_node->attachObject(plane_ent);
+        plane_node->scale(10,1,10);
+        //Ogre::Material plane_mat = Ogre::MaterialManager::getSingletonPtr()->getByName("rock");
+        
+
+        //ToDo create material script
+        Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("Map/Line","General"); 
+        myManualObjectMaterial->setReceiveShadows(false); 
+        myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
+        myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(1,1,0,0); 
+        myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(1,1,0); 
+        myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1,1,0);
+
+    }
+
+    Map::~Map()
+    {
+        singletonMap_s = 0;
+        //delete sManager_;
+        //delete rootNode_;
+        //delete oManager_;
+        //delete mReflectCam_;
+        //delete mapSceneM_;
+    }
+
     Ogre::MaterialPtr Map::createRenderCamera(Ogre::Camera * cam, std::string matName)
     {
@@ -168,11 +207,10 @@
     void Map::updatePositions()
     {
+
 //Ogre::Entity * ent;// = mapSceneM_->createEntity("ent1", "drone.mesh");
-       int i=0; 
        for(ObjectList<orxonox::RadarViewable>::iterator it = ObjectList<orxonox::RadarViewable>::begin();
             it!=ObjectList<orxonox::RadarViewable>::end();
             it++)
         {
-            i++;
             //COUT(0) << "Radar_Position: " << it->getRVWorldPosition() << std::endl;
             //Ogre::SceneNode node = it->getMapNode();
@@ -182,12 +220,21 @@
                 it->MapNode_ = rootNode_->createChildSceneNode( it->getRVWorldPosition() );
                 //it->MapNode_->translate( it->getRVOrientedVelocity(), Ogre::TS_WORLD );
+                /*if(it->getRadarObjectShape() == RadarViewable::Dot)
+                {
+                    //if( !(it->MapEntity_) )//check wether the entity is already attached
+                    //{
+                        //it->MapEntity_ = this->mapSceneM_->createEntity( getUniqueNumberString(), "drone.mesh");
+                        //it->addEntity();
+                        //it->MapNode_->attachObject( it->MapEntity_ );
+                        //it->MapNode_->attachObject( it->line_ );
+                   // }
+                }*/
+                it->addMapEntity();
             }
-            it->MapNode_->setPosition( it->getRVWorldPosition() );
-            it->MapNode_->translate( it->getRVOrientedVelocity(), (Ogre::Node::TransformSpace)3 );
-            if( !(it->MapEntity_) )
-            {
-                it->MapEntity_ = mapSceneM_->createEntity( "MapEnt"+i, "drone.mesh");
-                it->MapNode_->attachObject( it->MapEntity_ );
-            }
+
+            it->updateMapPosition();
+
+
+
             
         
@@ -218,5 +265,7 @@
             this->overlay_->show();
             this->isVisible_=1;
-            //updatePositions();
+            //set mouselook when showing map
+            if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && !HumanController::localController_s->controllableEntity_->isInMouseLook())
+            HumanController::localController_s->controllableEntity_->mouseLook();
         }
         else
@@ -224,4 +273,6 @@
             this->overlay_->hide();
             this->isVisible_=0;
+            if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->isInMouseLook())
+            HumanController::localController_s->controllableEntity_->mouseLook();
         }
     }
@@ -235,5 +286,5 @@
         {
         //Map * m = it->getMap();
-        COUT(0) << it->isVisible_ << std::endl;
+        //COUT(0) << it->isVisible_ << std::endl;
         it->toggleVisibility();
         //it->updatePositions();
@@ -244,6 +295,24 @@
     {
         //sNode_->lookAt(Vector3::NEGATIVE_UNIT_Z, Ogre::Node::TS_WORLD, Vector3::NEGATIVE_UNIT_Z);
-        updatePositions();
-        
+        if( this->isVisible_ )
+            updatePositions();
+        //mReflectCam_->roll(Degree(1));
+        
+    }
+
+    void Map::rotateYaw(const Vector2& value)
+    {
+        //if (this->bMouseLook_)
+            //this->mReflectCam_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
+        if(Map::singletonMap_s)
+            singletonMap_s->mReflectCam_->setOrientation(singletonMap_s->mReflectCam_->getOrientation() * Quaternion( (Degree)(value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_Y));
+    }
+
+    void Map::rotatePitch(const Vector2& value)
+    {
+        //if (this->bMouseLook_)
+            //this->mReflectCam_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
+        if(Map::singletonMap_s)
+            singletonMap_s->mReflectCam_->setOrientation(singletonMap_s->mReflectCam_->getOrientation() * Quaternion( (Degree)(-value.y * singletonMap_s->mouseLookSpeed_) , Vector3::UNIT_X));
     }
     
Index: code/branches/map/src/orxonox/overlays/map/Map.h
===================================================================
--- code/branches/map/src/orxonox/overlays/map/Map.h	(revision 2913)
+++ code/branches/map/src/orxonox/overlays/map/Map.h	(revision 2942)
@@ -54,5 +54,5 @@
     public: // functions
         Map(BaseObject* creator);
-        virtual ~Map() {}
+        ~Map();
 
         virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
@@ -65,11 +65,35 @@
 
         static const int maxRange_s=1000;
+
+        static void rotateYaw(const Vector2& value);
+        static void rotatePitch(const Vector2& value);
+
+        // variables
+
+
+        bool inline getVisibility()
+            { return this->isVisible_; };
+
+        static inline Ogre::SceneManager* getMapSceneManagerPtr()
+        {
+            return Map::singletonMap_s->mapSceneM_;
+        }
+        static inline Map* getSingletonPtr()
+        {
+            return Map::singletonMap_s;
+        }
+
+
+
         
     private: // functions
+
         void toggleVisibility();
         void updatePositions();
-
+        
 
     private: // variables
+        static Map* singletonMap_s;
+
         Ogre::SceneManager* sManager_;
         Ogre::SceneManager* mapSceneM_;
@@ -77,7 +101,6 @@
         Ogre::OverlayManager * oManager_;
         Ogre::Camera* mReflectCam_;
-
-        
-        
+        //Ogre::SceneNode* playerShipNode_;
+        int mouseLookSpeed_;
         bool isVisible_;
     };
Index: code/branches/map/src/orxonox/tools/CMakeLists.txt
===================================================================
--- code/branches/map/src/orxonox/tools/CMakeLists.txt	(revision 2913)
+++ code/branches/map/src/orxonox/tools/CMakeLists.txt	(revision 2942)
@@ -7,3 +7,5 @@
   Timer.cc
   WindowEventListener.cc
+  DynamicLines.cpp
+  DynamicRenderable.cpp
 )
Index: code/branches/map/src/orxonox/tools/DynamicLines.cpp
===================================================================
--- code/branches/map/src/orxonox/tools/DynamicLines.cpp	(revision 2942)
+++ code/branches/map/src/orxonox/tools/DynamicLines.cpp	(revision 2942)
@@ -0,0 +1,142 @@
+#include "DynamicLines.h"
+#include <Ogre.h>
+#include <cassert>
+#include <cmath>
+
+using namespace Ogre;
+
+enum {
+  POSITION_BINDING,
+  TEXCOORD_BINDING
+};
+
+DynamicLines::DynamicLines(OperationType opType)
+{
+  initialize(opType,false);
+  setMaterial("BaseWhiteNoLighting");
+  mDirty = true;
+}
+
+DynamicLines::~DynamicLines()
+{
+}
+
+void DynamicLines::setOperationType(OperationType opType)
+{
+  mRenderOp.operationType = opType;
+}
+
+RenderOperation::OperationType DynamicLines::getOperationType() const
+{
+  return mRenderOp.operationType;
+}
+
+void DynamicLines::addPoint(const Vector3 &p)
+{
+   mPoints.push_back(p);
+   mDirty = true;
+}
+void DynamicLines::addPoint(Real x, Real y, Real z)
+{
+   mPoints.push_back(Vector3(x,y,z));
+   mDirty = true;
+}
+const Vector3& DynamicLines::getPoint(unsigned short index) const
+{
+   assert(index < mPoints.size() && "Point index is out of bounds!!");
+   return mPoints[index];
+}
+unsigned short DynamicLines::getNumPoints(void) const
+{
+  return (unsigned short)mPoints.size();
+}
+void DynamicLines::setPoint(unsigned short index, const Vector3 &value)
+{
+  assert(index < mPoints.size() && "Point index is out of bounds!!");
+
+  mPoints[index] = value;
+  mDirty = true;
+}
+void DynamicLines::clear()
+{
+  mPoints.clear();
+  mDirty = true;
+}
+
+void DynamicLines::update()
+{
+  if (mDirty) fillHardwareBuffers();
+}
+
+void DynamicLines::createVertexDeclaration()
+{
+  VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
+  decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
+}
+
+void DynamicLines::fillHardwareBuffers()
+{
+  int size = mPoints.size();
+
+  prepareHardwareBuffers(size,0);
+
+  if (!size) { 
+    mBox.setExtents(Vector3::ZERO,Vector3::ZERO);
+    mDirty=false;
+    return;
+  }
+  
+  Vector3 vaabMin = mPoints[0];
+  Vector3 vaabMax = mPoints[0];
+
+  HardwareVertexBufferSharedPtr vbuf =
+    mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);
+
+  Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
+  {
+   for(int i = 0; i < size; i++)
+   {
+      *prPos++ = mPoints[i].x;
+      *prPos++ = mPoints[i].y;
+      *prPos++ = mPoints[i].z;
+
+      if(mPoints[i].x < vaabMin.x)
+         vaabMin.x = mPoints[i].x;
+      if(mPoints[i].y < vaabMin.y)
+         vaabMin.y = mPoints[i].y;
+      if(mPoints[i].z < vaabMin.z)
+         vaabMin.z = mPoints[i].z;
+
+      if(mPoints[i].x > vaabMax.x)
+         vaabMax.x = mPoints[i].x;
+      if(mPoints[i].y > vaabMax.y)
+         vaabMax.y = mPoints[i].y;
+      if(mPoints[i].z > vaabMax.z)
+         vaabMax.z = mPoints[i].z;
+   }
+  }
+  vbuf->unlock();
+
+  mBox.setExtents(vaabMin, vaabMax);
+
+  mDirty = false;
+}
+
+/*
+void DynamicLines::getWorldTransforms(Matrix4 *xform) const
+{
+   // return identity matrix to prevent parent transforms
+   *xform = Matrix4::IDENTITY;
+}
+*/
+/*
+const Quaternion &DynamicLines::getWorldOrientation(void) const
+{
+   return Quaternion::IDENTITY;
+}
+
+const Vector3 &DynamicLines::getWorldPosition(void) const
+{
+   return Vector3::ZERO;
+}
+*/
Index: code/branches/map/src/orxonox/tools/DynamicLines.h
===================================================================
--- code/branches/map/src/orxonox/tools/DynamicLines.h	(revision 2942)
+++ code/branches/map/src/orxonox/tools/DynamicLines.h	(revision 2942)
@@ -0,0 +1,66 @@
+#ifndef _DYNAMIC_LINES_H_
+#define _DYNAMIC_LINES_H_
+
+#include "DynamicRenderable.h"
+#include <vector>
+
+
+class DynamicLines : public DynamicRenderable
+{
+  typedef Ogre::Vector3 Vector3;
+  typedef Ogre::Quaternion Quaternion;
+  typedef Ogre::Camera Camera;
+  typedef Ogre::Real Real;
+  typedef Ogre::RenderOperation::OperationType OperationType;
+
+public:
+  /// Constructor - see setOperationType() for description of argument.
+  DynamicLines(OperationType opType=Ogre::RenderOperation::OT_LINE_STRIP);
+  virtual ~DynamicLines();
+
+  /// Add a point to the point list
+  void addPoint(const Ogre::Vector3 &p);
+  /// Add a point to the point list
+  void addPoint(Real x, Real y, Real z);
+
+  /// Change the location of an existing point in the point list
+  void setPoint(unsigned short index, const Vector3 &value);
+
+  /// Return the location of an existing point in the point list
+  const Vector3& getPoint(unsigned short index) const;
+
+  /// Return the total number of points in the point list
+  unsigned short getNumPoints(void) const;
+
+  /// Remove all points from the point list
+  void clear();
+
+  /// Call this to update the hardware buffer after making changes.  
+  void update();
+
+  /** Set the type of operation to draw with.
+   * @param opType Can be one of 
+   *    - RenderOperation::OT_LINE_STRIP
+   *    - RenderOperation::OT_LINE_LIST
+   *    - RenderOperation::OT_POINT_LIST
+   *    - RenderOperation::OT_TRIANGLE_LIST
+   *    - RenderOperation::OT_TRIANGLE_STRIP
+   *    - RenderOperation::OT_TRIANGLE_FAN
+   *    The default is OT_LINE_STRIP.
+   */
+  void setOperationType(OperationType opType);
+  OperationType getOperationType() const;
+
+protected:
+  /// Implementation DynamicRenderable, creates a simple vertex-only decl
+  virtual void createVertexDeclaration();
+  /// Implementation DynamicRenderable, pushes point list out to hardware memory
+  virtual void fillHardwareBuffers();
+
+private:
+  std::vector<Vector3> mPoints;
+  bool mDirty;
+};
+
+
+#endif
Index: code/branches/map/src/orxonox/tools/DynamicRenderable.cpp
===================================================================
--- code/branches/map/src/orxonox/tools/DynamicRenderable.cpp	(revision 2942)
+++ code/branches/map/src/orxonox/tools/DynamicRenderable.cpp	(revision 2942)
@@ -0,0 +1,133 @@
+#include "DynamicRenderable.h"
+#include <OgreCamera.h>
+#include <OgreHardwareBufferManager.h>
+
+using namespace Ogre;
+
+DynamicRenderable::DynamicRenderable()
+{
+}
+
+DynamicRenderable::~DynamicRenderable()
+{
+  delete mRenderOp.vertexData;
+  delete mRenderOp.indexData;
+}
+
+void DynamicRenderable::initialize(RenderOperation::OperationType operationType,
+                                   bool useIndices)
+{
+  // Initialize render operation
+  mRenderOp.operationType = operationType;
+  mRenderOp.useIndexes = useIndices;
+  mRenderOp.vertexData = new VertexData;
+  if (mRenderOp.useIndexes)
+    mRenderOp.indexData = new IndexData;
+
+  // Reset buffer capacities
+  mVertexBufferCapacity = 0;
+  mIndexBufferCapacity = 0;
+
+  // Create vertex declaration
+  createVertexDeclaration();
+}
+
+void DynamicRenderable::prepareHardwareBuffers(size_t vertexCount, 
+                                               size_t indexCount)
+{
+  // Prepare vertex buffer
+  size_t newVertCapacity = mVertexBufferCapacity;
+  if ((vertexCount > mVertexBufferCapacity) ||
+      (!mVertexBufferCapacity))
+  {
+    // vertexCount exceeds current capacity!
+    // It is necessary to reallocate the buffer.
+
+    // Check if this is the first call
+    if (!newVertCapacity)
+      newVertCapacity = 1;
+
+    // Make capacity the next power of two
+    while (newVertCapacity < vertexCount)
+      newVertCapacity <<= 1;
+  }
+  else if (vertexCount < mVertexBufferCapacity>>1) {
+    // Make capacity the previous power of two
+    while (vertexCount < newVertCapacity>>1)
+      newVertCapacity >>= 1;
+  }
+  if (newVertCapacity != mVertexBufferCapacity) 
+  {
+    mVertexBufferCapacity = newVertCapacity;
+    // Create new vertex buffer
+    HardwareVertexBufferSharedPtr vbuf =
+      HardwareBufferManager::getSingleton().createVertexBuffer(
+        mRenderOp.vertexData->vertexDeclaration->getVertexSize(0),
+        mVertexBufferCapacity,
+        HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); // TODO: Custom HBU_?
+
+    // Bind buffer
+    mRenderOp.vertexData->vertexBufferBinding->setBinding(0, vbuf);
+  }
+  // Update vertex count in the render operation
+  mRenderOp.vertexData->vertexCount = vertexCount;
+
+  if (mRenderOp.useIndexes)
+  {
+    OgreAssert(indexCount <= std::numeric_limits<unsigned short>::max(), "indexCount exceeds 16 bit");
+
+    size_t newIndexCapacity = mIndexBufferCapacity;
+    // Prepare index buffer
+    if ((indexCount > newIndexCapacity) ||
+        (!newIndexCapacity))
+    {
+      // indexCount exceeds current capacity!
+      // It is necessary to reallocate the buffer.
+
+      // Check if this is the first call
+      if (!newIndexCapacity)
+        newIndexCapacity = 1;
+
+      // Make capacity the next power of two
+      while (newIndexCapacity < indexCount)
+        newIndexCapacity <<= 1;
+
+    }
+    else if (indexCount < newIndexCapacity>>1) 
+    {
+      // Make capacity the previous power of two
+      while (indexCount < newIndexCapacity>>1)
+        newIndexCapacity >>= 1;
+    }
+
+    if (newIndexCapacity != mIndexBufferCapacity)
+    {
+      mIndexBufferCapacity = newIndexCapacity;
+      // Create new index buffer
+      mRenderOp.indexData->indexBuffer =
+        HardwareBufferManager::getSingleton().createIndexBuffer(
+          HardwareIndexBuffer::IT_16BIT,
+          mIndexBufferCapacity,
+          HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); // TODO: Custom HBU_?
+    }
+
+    // Update index count in the render operation
+    mRenderOp.indexData->indexCount = indexCount;
+  }
+}
+
+Real DynamicRenderable::getBoundingRadius(void) const
+{
+  return Math::Sqrt(std::max(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength()));
+}
+
+Real DynamicRenderable::getSquaredViewDepth(const Camera* cam) const
+{
+   Vector3 vMin, vMax, vMid, vDist;
+   vMin = mBox.getMinimum();
+   vMax = mBox.getMaximum();
+   vMid = ((vMax - vMin) * 0.5) + vMin;
+   vDist = cam->getDerivedPosition() - vMid;
+
+   return vDist.squaredLength();
+}
Index: code/branches/map/src/orxonox/tools/DynamicRenderable.h
===================================================================
--- code/branches/map/src/orxonox/tools/DynamicRenderable.h	(revision 2942)
+++ code/branches/map/src/orxonox/tools/DynamicRenderable.h	(revision 2942)
@@ -0,0 +1,69 @@
+#ifndef DYNAMIC_RENDERABLE_H
+#define DYNAMIC_RENDERABLE_H
+
+#include <OgreSimpleRenderable.h>
+
+/// Abstract base class providing mechanisms for dynamically growing hardware buffers.
+class DynamicRenderable : public Ogre::SimpleRenderable
+{
+public:
+  /// Constructor
+  DynamicRenderable();
+  /// Virtual destructor
+  virtual ~DynamicRenderable();
+
+  /** Initializes the dynamic renderable.
+   @remarks
+      This function should only be called once. It initializes the
+      render operation, and calls the abstract function
+      createVertexDeclaration().
+   @param operationType The type of render operation to perform.
+   @param useIndices Specifies whether to use indices to determine the
+          vertices to use as input. */
+  void initialize(Ogre::RenderOperation::OperationType operationType,
+                  bool useIndices);
+
+  /// Implementation of Ogre::SimpleRenderable
+  virtual Ogre::Real getBoundingRadius(void) const;
+  /// Implementation of Ogre::SimpleRenderable
+  virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
+
+protected:
+  /// Maximum capacity of the currently allocated vertex buffer.
+  size_t mVertexBufferCapacity;
+  /// Maximum capacity of the currently allocated index buffer.
+  size_t mIndexBufferCapacity;
+
+  /** Creates the vertex declaration.
+   @remarks
+      Override and set mRenderOp.vertexData->vertexDeclaration here.
+      mRenderOp.vertexData will be created for you before this method
+      is called. */
+  virtual void createVertexDeclaration() = 0;
+
+  /** Prepares the hardware buffers for the requested vertex and index counts.
+   @remarks
+      This function must be called before locking the buffers in
+      fillHardwareBuffers(). It guarantees that the hardware buffers
+      are large enough to hold at least the requested number of
+      vertices and indices (if using indices). The buffers are
+      possibly reallocated to achieve this.
+   @par
+      The vertex and index count in the render operation are set to
+      the values of vertexCount and indexCount respectively.
+   @param vertexCount The number of vertices the buffer must hold.
+
+   @param indexCount The number of indices the buffer must hold. This
+          parameter is ignored if not using indices. */
+  void prepareHardwareBuffers(size_t vertexCount, size_t indexCount);
+
+  /** Fills the hardware vertex and index buffers with data.
+   @remarks
+      This function must call prepareHardwareBuffers() before locking
+      the buffers to ensure the they are large enough for the data to
+      be written. Afterwards the vertex and index buffers (if using
+      indices) can be locked, and data can be written to them. */
+  virtual void fillHardwareBuffers() = 0;
+};
+
+#endif // DYNAMIC_RENDERABLE_H
