Index: code/trunk/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/FormationController.cc	(revision 9265)
+++ code/trunk/src/orxonox/controllers/FormationController.cc	(revision 9348)
@@ -50,25 +50,25 @@
 {
 
-  SetConsoleCommand("FormationController", "formationflight",  &FormationController::formationflight);
-  SetConsoleCommand("FormationController", "masteraction",     &FormationController::masteraction);
-  SetConsoleCommand("FormationController", "followme",         &FormationController::followme);
-  SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
-  SetConsoleCommand("FormationController", "formationsize",    &FormationController::formationsize);
-
-
-
-
-  static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
-  static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
-  static const float FORMATION_LENGTH =  110;
-  static const float FORMATION_WIDTH =  110;
-  static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
-  static const float SPEED_MASTER = 0.6f;
-  static const float ROTATEFACTOR_MASTER = 0.2f;
-  static const float SPEED_FREE = 0.8f;
-  static const float ROTATEFACTOR_FREE = 0.8f;
-
-  FormationController::FormationController(BaseObject* creator) : Controller(creator)
-  {
+    SetConsoleCommand("FormationController", "formationflight",  &FormationController::formationflight);
+    SetConsoleCommand("FormationController", "masteraction",     &FormationController::masteraction);
+    SetConsoleCommand("FormationController", "followme",         &FormationController::followme);
+    SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
+    SetConsoleCommand("FormationController", "formationsize",    &FormationController::formationsize);
+
+
+
+
+    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
+    static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
+    static const float FORMATION_LENGTH =  110;
+    static const float FORMATION_WIDTH =  110;
+    static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
+    static const float SPEED_MASTER = 0.6f;
+    static const float ROTATEFACTOR_MASTER = 0.2f;
+    static const float SPEED_FREE = 0.8f;
+    static const float ROTATEFACTOR_FREE = 0.8f;
+
+    FormationController::FormationController(BaseObject* creator) : Controller(creator)
+    {
         RegisterObject(FormationController);
 
@@ -91,9 +91,9 @@
         this->team_=-1;
         this->target_.setCallback(createFunctor(&FormationController::targetDied, this));
-  }
-
-  FormationController::~FormationController()
-  {
-    if (this->isInitialized())
+    }
+
+    FormationController::~FormationController()
+    {
+        if (this->isInitialized())
         {
             this->removeFromFormation();
@@ -123,7 +123,7 @@
             }
         }
-  }
-
-  void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    }
+
+    void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(FormationController, XMLPort, xmlelement, mode);
@@ -137,9 +137,9 @@
 
 
-  /**
+    /**
         @brief Activates / deactivates formationflight behaviour
         @param form activate formflight if form is true
     */
-  void FormationController::formationflight(const bool form)
+    void FormationController::formationflight(const bool form)
     {
         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
@@ -168,5 +168,5 @@
     }
 
-  /**
+    /**
         @brief Get all masters to do a "specific master action"
         @param action which action to perform (integer, so it can be called with a console command (tmp solution))
@@ -198,5 +198,5 @@
     }
 
-  /**
+    /**
         @brief Sets shooting behaviour of pawns.
         @param passive if true, bots won't shoot.
@@ -225,5 +225,5 @@
     }
 
-  /**
+    /**
         @brief Sets maximal formation size
         @param size maximal formation size.
@@ -280,7 +280,8 @@
         }
 
-        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
         float distance = (target - this->getControllableEntity()->getPosition()).length();
-
+        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
+        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
 
         if(this->state_ == FREE)
@@ -289,9 +290,9 @@
             {
                 // Multiply with ROTATEFACTOR_FREE to make them a bit slower
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
-            }
-
-            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * rotateX);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * rotateY);
+            }
+
+            if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
             {
               this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
@@ -305,6 +306,6 @@
             if (this->target_ || distance > 10)
             {
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * rotateX);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * rotateY);
             }
 
@@ -320,22 +321,22 @@
         {
 
-           this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
-           this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * rotateX);
+            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * rotateY);
 
             if (distance < 300)
             {
-		 if (bHasTargetOrientation_)
-		    {
-			copyTargetOrientation();
-		    }
+                if (bHasTargetOrientation_)
+                {
+                    copyTargetOrientation();
+                }
                 if (distance < 100)
-                {   //linear speed reduction
+                { //linear speed reduction
                     this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
-
-                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
-
-            } else {
+                }
+                else
+                    this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
+            }
+            else
                 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
-            }
         }
 
@@ -343,17 +344,17 @@
         {
             this->positionReached();
-	    bHasTargetOrientation_=false;
-        }
-    }
-
-
-
-  void FormationController::moveToTargetPosition()
+            bHasTargetOrientation_=false;
+        }
+    }
+
+
+
+    void FormationController::moveToTargetPosition()
     {
         this->moveToPosition(this->targetPosition_);
     }
 
-  //copy the Roll orientation of given Quaternion.
-  void FormationController::copyOrientation(const Quaternion& orient)
+    //copy the Roll orientation of given Quaternion.
+    void FormationController::copyOrientation(const Quaternion& orient)
     {
         //roll angle difference in radian
@@ -373,5 +374,5 @@
 
 
-   /**
+    /**
         @brief Unregisters a slave from its master. Initiated by a slave.
     */
@@ -463,9 +464,9 @@
         }
     }
- /**
+
+    /**
         @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
     */
-
-void FormationController::commandSlaves()
+    void FormationController::commandSlaves()
     {
         if(this->state_ != MASTER) return;
@@ -481,9 +482,9 @@
         }
         else
-	// formation:
+        // formation:
         {
             dest += 1.0f*orient*WorldEntity::BACK;
             Vector3 pos = Vector3::ZERO;
-	         bool left=true;
+            bool left=true;
             int i = 1;
 
@@ -683,9 +684,10 @@
 
         if (specificMasterActionHoldCount_ == 0)
-         {
+        {
             this->specificMasterAction_ = NONE;
             this->searchNewTarget();
-         }
-        else specificMasterActionHoldCount_--;
+        }
+        else
+            specificMasterActionHoldCount_--;
     }
 
@@ -711,10 +713,10 @@
     void FormationController::turn180()
     {
-            Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
-
-            this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
-            this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
-
-            this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
+        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
+
+        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
+        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
+
+        this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     }
 
@@ -734,6 +736,6 @@
     void FormationController::spin()
     {
-            this->moveToTargetPosition();
-            this->getControllableEntity()->rotateRoll(0.8f);
+        this->moveToTargetPosition();
+        this->getControllableEntity()->rotateRoll(0.8f);
     }
 
@@ -773,24 +775,19 @@
         if((humanPawn != NULL) && (allMasters.size() != 0))
         {
-                float posHuman = humanPawn->getPosition().length();
-                float distance = 0.0f;
-                float minDistance = FLT_MAX;
-                int index = 0;
-                int i = 0;
-
-                for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
-                    {
-                        if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
-                        distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
-                        if(distance < minDistance) index = i;
-                    }
-                allMasters[index]->followInit(humanPawn);
-            }
-
-    }
-
-
-
-
+            float posHuman = humanPawn->getPosition().length();
+            float distance = 0.0f;
+            float minDistance = FLT_MAX;
+            int index = 0;
+            int i = 0;
+
+            for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
+            {
+                if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
+                distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
+                if(distance < minDistance) index = i;
+            }
+            allMasters[index]->followInit(humanPawn);
+        }
+    }
 
     /**
@@ -814,5 +811,5 @@
     }
 
-   /**
+    /**
         @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
     */
@@ -842,5 +839,5 @@
 
 
-  /**
+    /**
         @brief Master follows target with adjusted speed. Called within tick.
     */
@@ -854,5 +851,5 @@
 
 
-  void FormationController::setTargetPosition(const Vector3& target)
+    void FormationController::setTargetPosition(const Vector3& target)
     {
         this->targetPosition_ = target;
@@ -918,5 +915,5 @@
     }
 
-  void FormationController::forgetTarget()
+    void FormationController::forgetTarget()
     {
         this->target_ = 0;
@@ -924,5 +921,5 @@
     }
 
-   void FormationController::targetDied()
+    void FormationController::targetDied()
     {
         this->forgetTarget();
@@ -930,5 +927,5 @@
     }
 
-  bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+    bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     {
         if (entity1 == entity2)
@@ -1054,5 +1051,5 @@
             return;
 
-        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
         float distance = (target - this->getControllableEntity()->getPosition()).length();
 
@@ -1060,6 +1057,6 @@
             {
                 // Multiply with ROTATEFACTOR_FREE to make them a bit slower
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * clamp(coord.x * 10, -1.0f, 1.0f));
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * clamp(coord.y * 10, -1.0f, 1.0f));
                 this->getControllableEntity()->moveFrontBack(SPEED_FREE);
             }
Index: code/trunk/src/orxonox/controllers/FormationController.h
===================================================================
--- code/trunk/src/orxonox/controllers/FormationController.h	(revision 9265)
+++ code/trunk/src/orxonox/controllers/FormationController.h	(revision 9348)
Index: code/trunk/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.cc	(revision 9265)
+++ code/trunk/src/orxonox/controllers/NewHumanController.cc	(revision 9348)
@@ -298,5 +298,5 @@
         //Used in HumanController for formationFlight
         HumanController::hit(originator,contactpoint,damage);
-        
+
         if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
         {
@@ -397,5 +397,5 @@
                 try
                 {
-                    wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
+                    wePtr = orxonox_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
                 }
                 catch (...)
