Index: code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc	(revision 2041)
+++ code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc	(revision 2042)
@@ -37,4 +37,5 @@
 #include "objects/infos/PlayerInfo.h"
 #include "objects/worldentities/Camera.h"
+#include "objects/worldentities/CameraPosition.h"
 #include "overlays/OverlayGroup.h"
 
@@ -92,4 +93,55 @@
 
         XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode);
+        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
+
+        XMLPortObject(ControllableEntity, WorldEntity, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
+    }
+
+    void ControllableEntity::addCameraPosition(CameraPosition* position)
+    {
+        this->attach(position);
+        this->cameraPositions_.push_back(position);
+    }
+
+    CameraPosition* ControllableEntity::getCameraPosition(unsigned int index) const
+    {
+        unsigned int i = 0;
+        for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
+        {
+            if (i == index)
+                return (*it);
+            ++i;
+        }
+        return 0;
+    }
+
+    void ControllableEntity::switchCamera()
+    {
+        if (this->camera_)
+        {
+            if (this->camera_->getParent() == this && this->cameraPositions_.size() > 0)
+            {
+                this->cameraPositions_.front()->attachCamera(this->camera_);
+            }
+            else if (this->cameraPositions_.size() > 0)
+            {
+                for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
+                {
+                    if ((*it) == this->camera_->getParent())
+                    {
+                        ++it;
+                        if (it != this->cameraPositions_.end())
+                            (*it)->attachCamera(this->camera_);
+                        else
+                            (*this->cameraPositions_.begin())->attachCamera(this->camera_);
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                this->attach(this->camera_);
+            }
+        }
     }
 
@@ -105,5 +157,4 @@
         this->playerID_ = player->getObjectID();
         this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
-
         if (this->bControlled_)
         {
@@ -111,5 +162,8 @@
 
             if (!Core::isMaster())
+            {
+COUT(0) << "CE: bidirectional synchronization" << std::endl;
                 this->setObjectMode(network::direction::bidirectional);
+            }
         }
     }
@@ -145,5 +199,10 @@
         this->camera_ = new Camera(this);
         this->camera_->requestFocus();
-        this->attach(this->camera_);
+        if (this->cameraPositionTemplate_ != "")
+            this->addTemplate(this->cameraPositionTemplate_);
+        if (this->cameraPositions_.size() > 0)
+            this->cameraPositions_.front()->attachCamera(this->camera_);
+        else
+            this->attach(this->camera_);
 
         if (this->hudtemplate_ != "")
@@ -157,5 +216,5 @@
     {
         std::cout << "###### stop local control" << std::endl;
-        this->detach(this->camera_);
+        this->camera_->detachFromParent();
         delete this->camera_;
         this->camera_ = 0;
@@ -187,4 +246,6 @@
     void ControllableEntity::registerVariables()
     {
+        REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient);
+
         REGISTERDATA(this->server_position_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
         REGISTERDATA(this->server_velocity_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
