Index: code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
===================================================================
--- code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt	(revision 10031)
+++ code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt	(revision 10039)
@@ -49,5 +49,5 @@
       <BlinkingBillboard position="-17,-1.5,0" material="Examples/Flare" colour="0.5, 1.0, 0.3" amplitude=0.1 frequency=0.5 phase=180 quadratic=1 />
 
-              <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
+               <!-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
             <templates>
               <Template link=spaceshipturrettest />
@@ -56,5 +56,5 @@
               <TurretController team=10 />
             </controller>
-        </Turret>
+        </Turret> -->
 
     </attached>
Index: code/branches/turretFS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/turretFS14/data/levels/turretTest.oxw	(revision 10031)
+++ code/branches/turretFS14/data/levels/turretTest.oxw	(revision 10039)
@@ -34,5 +34,5 @@
 
 
-<MovableEntity position="0,0,0" yaw=0 pitch=0>
+<SpaceShip position="-100,0,0" yaw=0 pitch=0>
     <attached>
         <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
@@ -42,5 +42,5 @@
         <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" />
 
-        <!-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
+        <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
             <templates>
               <Template link=spaceshipturrettest />
@@ -49,5 +49,5 @@
               <TurretController team=10 />
             </controller>
-        </Turret> -->
+        </Turret>
 
         <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
@@ -58,7 +58,31 @@
 
     </attached>
-</MovableEntity>
+</SpaceShip>
 
+<SpaceShip position="100,0,0" yaw=0 pitch=0>
+    <attached>
+        <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
+        <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" />
+        <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" />
+        <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" />
+        <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" />
 
+        <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
+            <templates>
+              <Template link=spaceshipturrettest />
+            </templates>
+            <controller>
+              <TurretController team=9 />
+            </controller>
+        </Turret>
+
+        <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
+
+        <Model mesh="sphere.mesh" position="0,25,0" scale=1/>
+
+        <Model mesh="sphere.mesh" position="0,0,30" scale=1/>
+
+    </attached>
+</SpaceShip>
 
 
Index: code/branches/turretFS14/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/turretFS14/src/libraries/core/input/InputManager.cc	(revision 10031)
+++ code/branches/turretFS14/src/libraries/core/input/InputManager.cc	(revision 10039)
@@ -175,11 +175,11 @@
 
         if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
-        {
+        {   // HACK MARTIN for debugging, changed values here to true
             if (CommandLineParser::getValue("keyboard_no_grab").get<bool>())
                 paramList.insert(StringPair("x11_keyboard_grab", "false"));
             else
-                paramList.insert(StringPair("x11_keyboard_grab", "true"));
-            paramList.insert(StringPair("x11_mouse_grab",  "true"));
-            paramList.insert(StringPair("x11_mouse_hide", "true"));
+                paramList.insert(StringPair("x11_keyboard_grab", "false"));
+            paramList.insert(StringPair("x11_mouse_grab",  "false"));
+            paramList.insert(StringPair("x11_mouse_hide", "false"));
         }
         else
Index: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10039)
@@ -44,13 +44,4 @@
     {
         RegisterObject(Turret);
-        this->startOrient_ = Quaternion::IDENTITY;
-        this->startDir_ = Vector3::ZERO;
-        this->localZ_ = Vector3::UNIT_Z;
-        this->localY_ = Vector3::UNIT_Y;
-        this->localX_ = Vector3::UNIT_X;
-        this->maxPitch_ = 0;
-        this->maxYaw_ = 0;
-        this->attackRadius_ = 200;
-        this->gotOrient_ = false;
         this->rotationThrust_ = 50;
 
@@ -110,40 +101,6 @@
     }
 
-    bool Turret::isInRange(Vector3 position)
-    {
-        Vector3 distance = position - this->getPosition();
-        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
-        {
-            return false;
-        }
-
-        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
-        Vector3 dirProjected = dir;
-        dirProjected.x = 0;
-        Vector3 startDirProjected = this->startDir_;
-        startDirProjected.x = 0;
-        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
-        if(angle > this->maxPitch_)
-        {
-            return false;
-        }
-
-        dirProjected = dir;
-        dirProjected.y = 0;
-        startDirProjected = this->startDir_;
-        startDirProjected.y = 0;
-        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
-        if(angle > this->maxYaw_)
-        {
-            return false;
-        }
-        return true;
-    }
-
     void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
-        XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
-        XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
-        XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
         SUPER(Turret, XMLPort, xmlelement, mode);
     }
@@ -153,24 +110,13 @@
         SUPER(Turret, tick, dt);
 
-        if(!gotOrient_)
-        {
-            this->startOrient_ = this->getOrientation();
-            this->localX_ = this->startOrient_ * this->localX_;
-            this->localX_.normalise();
-            this->localY_ = this->startOrient_ * this->localY_;
-            this->localY_.normalise();
-            this->localZ_ = this->startOrient_ * this->localZ_;
-            this->localZ_.normalise();
+        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
+        this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
 
-            //startDir should always be (0,0,-1)
-            this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
 
-            this->gotOrient_ = true;
-        }
+        pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
+        yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
+        roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
 
-        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
-        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
         this->localAngularAcceleration_.setValue(0, 0, 0);
     }
-
 }
Index: code/branches/turretFS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.h	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/Turret.h	(revision 10039)
@@ -54,35 +54,6 @@
             virtual void tick(float dt);
 
-            virtual bool isInRange(Vector3 position);
-
-            inline void setMaxPitch(Ogre::Real pitch)
-                {this->maxPitch_ = pitch;}
-
-            inline Ogre::Real getMaxPitch()
-                {return this->maxPitch_;}
-
-            inline void setMaxYaw(Ogre::Real yaw)
-                {this->maxYaw_ = yaw;}
-
-            inline Ogre::Real getMaxYaw()
-                {return this->maxYaw_;}
-
-            inline void setAttackRadius(float radius)
-                {this->attackRadius_ = radius;}
-
-            inline float getAttackRadius()
-                {return this->attackRadius_;}
-
 
         private:
-            bool gotOrient_;
-            Ogre::Real maxPitch_;
-            Ogre::Real maxYaw_;
-            float attackRadius_;
-            Quaternion startOrient_;
-            Vector3 startDir_;
-            Vector3 localZ_;
-            Vector3 localY_;
-            Vector3 localX_;
             float rotationThrust_;
 
@@ -92,3 +63,2 @@
 
 #endif
-
Index: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc	(revision 10039)
@@ -38,4 +38,14 @@
  	{
  		RegisterObject(TurretController);
+ 		this->startOrient_ = Quaternion::IDENTITY;
+        this->startDir_ = Vector3::ZERO;
+        this->localZ_ = Vector3::UNIT_Z;
+        this->localY_ = Vector3::UNIT_Y;
+        this->localX_ = Vector3::UNIT_X;
+        this->attackRadius_ = 200;
+        this->maxPitch_ = 90;
+        this->maxYaw_ = 90;
+        this->gotOrient_ = false;
+        orxout() << "Constructor " << this << endl;
  	}
 
@@ -48,5 +58,5 @@
  	{
         Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
-        if(target_ && turret->isInRange(target_->getPosition()))
+        if(target_ && this->isInRange(target_->getWorldPosition()))
         {
         	return;
@@ -62,5 +72,5 @@
         {
         	Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
-        	if(parenttarget && turret->isInRange(parenttarget->getPosition()))
+        	if(parenttarget && this->isInRange(parenttarget->getWorldPosition()))
         	{
         		this->setTarget(parenttarget);
@@ -76,5 +86,5 @@
             	continue;
 
-            if(turret->isInRange(entity->getPosition()))
+            if(this->isInRange(entity->getWorldPosition()))
             {
             	this->setTarget(entity);
@@ -85,13 +95,79 @@
  	}
 
+ 	bool TurretController::isInRange(Vector3 position)
+    {
+        Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
+        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
+        {
+            return false;
+        }
+
+        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
+        Vector3 dirProjected = dir;
+        dirProjected.x = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.x = 0;
+        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxPitch_)
+        {
+            return false;
+        }
+
+        dirProjected = dir;
+        dirProjected.y = 0;
+        startDirProjected = this->startDir_;
+        startDirProjected.y = 0;
+        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxYaw_)
+        {
+            return false;
+        }
+        return true;
+    }
+
  	void TurretController::tick(float dt)
  	{
+
+
+        if(!gotOrient_)
+        {
+            this->startOrient_ = this->getControllableEntity()->getOrientation();
+            this->localXStart_ = this->startOrient_ * this->localX_;
+            this->localXStart_.normalise();
+            this->localX_ = this->localXStart_;
+            this->localYStart_ = this->startOrient_ * this->localY_;
+            this->localYStart_.normalise();
+            this->localY_ = this->localYStart_;
+            this->localZStart_ = this->startOrient_ * this->localZ_;
+            this->localZStart_.normalise();
+            this->localZ_ = this->localZStart_;
+
+            //startDir should always be (0,0,-1)
+            this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+            this->gotOrient_ = true;
+        }
+
+        //orxout() << "Controller " << this;
+        //orxout() << "\tControllable Entity " << this->getControllableEntity() << endl;
+        WorldEntity* parent = this->getControllableEntity()->getParent();
+        if(parent)
+        {
+            Quaternion parentrot = parent->getOrientation();
+            this->localX_ = parentrot * this->localXStart_;
+            this->localY_ = parentrot * this->localYStart_;
+            this->localZ_ = parentrot * this->localZStart_;
+        }
+
+        orxout() << this->getControllableEntity()->getWorldPosition() << endl;
+
+
         if (!this->isActive() || !this->getControllableEntity())
             return;
  		this->searchTarget();
- 		this->getControllableEntity()->rotatePitch(0.2);
- 		/*if(target_)
+ 		if(target_)
  		{
  			this->aimAtTarget();
+ 			//this->getControllableEntity()->lookAt(this->targetPosition_);
  			//It says move, but really it only turns
  			this->moveToTargetPosition();
@@ -100,5 +176,5 @@
  				orxout() << 42 << endl;
  			}
- 		}*/
+ 		}
  	}
  }
Index: code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.h	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.h	(revision 10039)
@@ -44,5 +44,18 @@
 
  		private:
+            bool gotOrient_;
+            float attackRadius_;
+            Ogre::Real maxPitch_;
+            Ogre::Real maxYaw_;
+            Quaternion startOrient_;
+            Vector3 startDir_;
+            Vector3 localZ_;
+            Vector3 localZStart_;
+            Vector3 localY_;
+            Vector3 localYStart_;
+            Vector3 localX_;
+            Vector3 localXStart_;
  			void searchTarget();
+ 			bool isInRange(Vector3 position);
  	};
  }
Index: code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc	(revision 10031)
+++ code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc	(revision 10039)
@@ -94,5 +94,5 @@
         static const float hardcoded_projectile_speed = 1250;
 
-        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());
+        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
         this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
 
Index: code/branches/turretFS14/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/controllers/FormationController.cc	(revision 10031)
+++ code/branches/turretFS14/src/orxonox/controllers/FormationController.cc	(revision 10039)
@@ -277,6 +277,6 @@
         }
 
-        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
-        float distance = (target - this->getControllableEntity()->getPosition()).length();
+        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        float distance = (target - this->getControllableEntity()->getWorldPosition()).length();
         float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
         float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
Index: code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc	(revision 10031)
+++ code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc	(revision 10039)
@@ -414,4 +414,5 @@
             else if (this->isDynamic())
             {
+                //hacky hack, really shouldn't do that
                 //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
                 //return false;
