[Orxonox-commit 5481] r10144 - in code/branches/towerdefenseHS14: data/levels data/levels/includes data/levels/templates src/libraries/core/input src/modules/objects src/modules/towerdefense src/orxonox/controllers src/orxonox/worldentities

maxima at orxonox.net maxima at orxonox.net
Wed Dec 3 12:49:16 CET 2014


Author: maxima
Date: 2014-12-03 12:49:15 +0100 (Wed, 03 Dec 2014)
New Revision: 10144

Added:
   code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt
Modified:
   code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi
   code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt
   code/branches/towerdefenseHS14/data/levels/templates/tower.oxt
   code/branches/towerdefenseHS14/data/levels/towerDefense.oxw
   code/branches/towerdefenseHS14/data/levels/turretTest.oxw
   code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc
   code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt
   code/branches/towerdefenseHS14/src/modules/objects/Turret.cc
   code/branches/towerdefenseHS14/src/modules/objects/Turret.h
   code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
   code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc
   code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc
Log:
Geaenderte Turret Klassen hinzugefuegt. Neues Template towerturret. Dort wurde an den TDTower ein Turret attached. So schiesst der Tower nun auf die Enemies.

Modified: code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi
===================================================================
--- code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/data/levels/includes/weaponSettingsTurret.oxi	2014-12-03 11:49:15 UTC (rev 10144)
@@ -10,13 +10,13 @@
           <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
         </links>
         <Weapon>
-          <attached>
-            <Model mesh="sphere.mesh" position="3,3,-2.2" scale=0.6 />
-          </attached>
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset=" 3, 3,-2.2" />
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset=" 3,-3,-2.2" />
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset="-3, 3,-2.2" />
-          <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset="-3,-3,-2.2" />
+          <!-- <attached>
+            <Model mesh="sphere.mesh" position="1.7,1.7,-24.5" scale=0.6 />
+          </attached> -->
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="1.7, 1.7,-30" />
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="1.7, -1.7,-30" />
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="-1.7, 1.7,-30" />
+          <HsW01 mode=0 munitionpershot=0 delay=0 damage=1 material="Flares/point_lensflare" muzzleoffset="-1.7, -1.7,-30" />
         </Weapon>
       </WeaponPack>
     </weapons>

Modified: code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt
===================================================================
--- code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/data/levels/templates/enemytowerdefense.oxt	2014-12-03 11:49:15 UTC (rev 10144)
@@ -6,9 +6,9 @@
    spawnparticleduration  = 3
    explosionchunks        = 6
 
-   health            = 100
-   maxhealth         = 200
-   initialhealth     = 100
+   health            = 1
+   maxhealth         = 2
+   initialhealth     = 1
 
    shieldhealth        = 30
    initialshieldhealth = 30

Added: code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt
===================================================================
--- code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt	                        (rev 0)
+++ code/branches/towerdefenseHS14/data/levels/templates/standardTurret.oxt	2014-12-03 11:49:15 UTC (rev 10144)
@@ -0,0 +1,40 @@
+<Template name=standardturret>
+  <Turret collisionType="dynamic">
+    <attached>
+      <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" pitch=-90/>
+      <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" pitch=-90/>
+
+      <Turret position="0,0,-10" collisionType="dynamic" angularDamping=0.999999 mass=100 maxPitch=90 maxYaw=90 maxAttackRadius=2000 minAttackRadius=30>
+        <attached>
+          <Model position="0,0,0" pitch="-90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/>
+        </attached>
+        <collisionShapes>
+          <SphereCollisionShape radius="10"   position = "0,0,0"/>
+        </collisionShapes>
+        <controller>
+          <TurretController/>
+        </controller>
+        <?lua
+          include("../includes/weaponSettingsTurret.oxi")
+        ?>
+      </Turret>
+    </attached>
+    
+    <controller>
+      <TeamTargetProxy/>
+    </controller>
+  </Turret>
+</Template>
+
+<Template name=spaceshipturretcameras defaults=0>
+  <SpaceShip>
+    <camerapositions>
+      <CameraPosition position="0,10, 40" drag=true mouselook=true />
+      <CameraPosition position="0,20, 80" drag=true mouselook=true />
+      <CameraPosition position="0,30,120" drag=true mouselook=true />
+    </camerapositions>
+  </SpaceShip>
+</Template>
\ No newline at end of file

Modified: code/branches/towerdefenseHS14/data/levels/templates/tower.oxt
===================================================================
--- code/branches/towerdefenseHS14/data/levels/templates/tower.oxt	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/data/levels/templates/tower.oxt	2014-12-03 11:49:15 UTC (rev 10144)
@@ -25,18 +25,7 @@
     <attached>
         <Model position="0,0,0" scale=45 mesh="Tower.mesh" />
         
-        <Turret position="0,0,-100" collisionType="dynamic" angularDamping=0.999999 mass=100 maxPitch=90 maxYaw=90 maxAttackRadius=2000 minAttackRadius=30>
         
-	        <collisionShapes>
-	          	<SphereCollisionShape radius="10"   position = "0,0,0"/>
-	        </collisionShapes>
-	       	<controller>
-          		<TurretController/>
-        	</controller>
-	        <?lua
-	          	include("../includes/weaponSettingsTurret.oxi")
-	        ?>
-      	</Turret>
     </attached>
 
     <!--collisionShapes>
@@ -49,3 +38,45 @@
   </TowerDefenseTower>
 </Template>
 
+
+
+<Template name=towerturret>
+  <TowerDefenseTower
+
+
+   explosionchunks        = 6
+
+   reloadrate          = 3
+   reloadwaittime      = 1
+
+   collisionType     = "dynamic"
+   team = 1
+
+
+  >
+  <attached>
+
+    <Model position="0,0,0" scale=45 mesh="Tower.mesh" />
+    <Turret collisionType="dynamic" position="0,0,10" direction="0,0,1" pitch="0" yaw="0" roll="0" angularDamping=0.999999 mass=100 maxPitch=90 maxYaw=90 maxAttackRadius=1000 minAttackRadius=30>
+
+      <controller>
+        <TurretController/>
+      </controller>
+      <?lua
+        include("../includes/weaponSettingsTurret.oxi")
+      ?>
+    </Turret>
+  </attached>
+    
+
+
+
+    <!--collisionShapes>
+
+    </collisionShapes-->
+
+<?lua
+  include("../includes/towerWeaponSettings.oxi")
+?>
+  </TowerDefenseTower>
+</Template>
\ No newline at end of file

Modified: code/branches/towerdefenseHS14/data/levels/towerDefense.oxw
===================================================================
--- code/branches/towerdefenseHS14/data/levels/towerDefense.oxw	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/data/levels/towerDefense.oxw	2014-12-03 11:49:15 UTC (rev 10144)
@@ -21,11 +21,12 @@
   include("templates/spaceshipPirate.oxt")
   include("templates/tower.oxt")
   include("templates/enemytowerdefense.oxt")
+  include("templates/standardTurret.oxt")
 ?>
 
 <!-- Specify the position of the camera -->
 <Template name=centerpointmarkcamera defaults=0>
-  <Pawn>
+  <Pawn team=1>
     <camerapositions>
       <CameraPosition position="0,0,1500"/>
     </camerapositions>
@@ -34,7 +35,7 @@
 
 <!-- Loads a mesh to mark the center-->
 <Template name=centerpointmark>
-  <Pawn camerapositiontemplate=centerpointmarkcamera>
+  <Pawn team=1 camerapositiontemplate=centerpointmarkcamera>
     <attached>
       <Model position="0,0,0" mesh="cylinder.mesh" scale3D="1,1,1" /> <!-- the camera is attached to this -->
     </attached>
@@ -70,7 +71,7 @@
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
 
     <!-- Spawns the camera, attached to a crate -->
-    <SpawnPoint team=0 position="0,0,0" spawnclass=Pawn pawndesign=centerpointmark />
+    <SpawnPoint team=1 position="0,0,0" spawnclass=Pawn pawndesign=centerpointmark />
     <!--TeamSpawnPoint team=1 position="-7,7,4" direction="-1,0,0" roll=90 yaw=0 spawnclass=SpaceShip pawndesign=spaceshipassff /-->
 
     <!--SpawnPoint team=1 position="0,0,10" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff  /-->
@@ -80,7 +81,7 @@
 
 
     <!--invisible entity to attach towers to, since playfield is static and towers are dynamic-->
-    <StaticEntity position=0,0,0>
+    <StaticEntity team =1 position=0,0,0>
 
         <attached>
             <Model position="-50,-50,0" mesh="Playfield_ME.mesh" scale=80 />
@@ -117,6 +118,7 @@
     direction="0,0,0"
     collisionType=dynamic
     mass=100000
+    team=1
     />
 
   </Scene>

Modified: code/branches/towerdefenseHS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/towerdefenseHS14/data/levels/turretTest.oxw	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/data/levels/turretTest.oxw	2014-12-03 11:49:15 UTC (rev 10144)
@@ -2,7 +2,7 @@
 
 <LevelInfo
  name = "turret Test"
- description = "A level with a turret in it."
+ description = "A level to test turrets with."
  tags = "test"
  screenshot = "emptylevel.png"
 />
@@ -15,8 +15,7 @@
 
 <?lua
   include("templates/spaceshipAssff.oxt")
-  include("templates/spaceshipPirate.oxt")
-  include("templates/spaceshipTurret.oxt")
+  include("templates/standardTurret.oxt")
 ?>
 
 <Level>
@@ -32,31 +31,26 @@
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
     <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
 
+<SpaceShip position = "0,0,800" collisionType="dynamic" team=10>
+  <controller>
+    <TeamTargetProxy team=10/>
+  </controller>
+  <attached>
+    <Model position="0,0,0" mesh="plane.mesh" scale3D="20,20,20" pitch=-90/>
 
-<StaticEntity position="0,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" />
-    </attached>
-</StaticEntity>
+    <?lua for i = 1, 10, 1 do ?>
+      <Turret position="<?lua print(150-i*30) ?>,<?lua print(150-i*30) ?>,0" pitch="0" yaw="0" roll="0">
+        <templates>
+          <Template link=standardturret />
+        </templates>
+      </Turret>
+    <?lua end ?>
 
-
-
-<Turret position="0,10,0" pitch="90" yaw="0" roll="0">
-    <templates>
-        <Template link=spaceshipturret />
-    </templates>
-    <controller>
-        <WaypointPatrolController alertnessradius=100 team=10>
-        </WaypointPatrolController>
-     </controller>
-</Turret>
-
-
-
+  </attached>
+  <collisionShapes>
+    <BoxCollisionShape radius="10"   position="0,0,0" halfExtents="200, 200, 0"/>
+  </collisionShapes>
+</SpaceShip>
     
   </Scene>
 </Level>

Modified: code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/libraries/core/input/InputManager.cc	2014-12-03 11:49:15 UTC (rev 10144)
@@ -174,13 +174,13 @@
         paramList.insert(StringPair("XAutoRepeatOn", "true"));
 
         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
         {

Modified: code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt
===================================================================
--- code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/modules/objects/CMakeLists.txt	2014-12-03 11:49:15 UTC (rev 10144)
@@ -10,6 +10,7 @@
 ADD_SUBDIRECTORY(collisionshapes)
 ADD_SUBDIRECTORY(eventsystem)
 ADD_SUBDIRECTORY(triggers)
+ADD_SUBDIRECTORY(controllers)
 
 ORXONOX_ADD_LIBRARY(objects
   MODULE

Modified: code/branches/towerdefenseHS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/objects/Turret.cc	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/modules/objects/Turret.cc	2014-12-03 11:49:15 UTC (rev 10144)
@@ -20,7 +20,7 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *   Author:
- *      Marian Runo
+ *      Marian Runo, Martin Mueller
  *   Co-authors:
  *      ...
  *
@@ -28,58 +28,257 @@
 
 #include "Turret.h"
 #include "core/CoreIncludes.h"
-#include "OgreQuaternion.h"
 #include "core/XMLPort.h"
-#include "controllers/WaypointPatrolController.h"
+#include "Scene.h"
+#include <OgreSceneManager.h>
 
+
 namespace orxonox
 {
     RegisterClass(Turret);
 
+
+
     /**
-     * @brief Constructor
+        @brief 
+        Sets default values for all variables. Also hides the turret from the radar.
+
+        @param context
+        The context
      */
-    Turret::Turret(Context* context) : SpaceShip(context)
+    Turret::Turret(Context* context) : Pawn(context)
     {
         RegisterObject(Turret);
-        this->controller_ = new WaypointPatrolController(this->getContext());
+        this->rotationThrust_ = 50;
+        this->startDir_ = Vector3::ZERO;
+        this->localZ_ = Vector3::UNIT_Z;
+        this->localY_ = Vector3::UNIT_Y;
+        this->localX_ = Vector3::UNIT_X;
+        this->maxAttackRadius_ = 200;
+        this->minAttackRadius_ = 0;
+        this->maxPitch_ = 90;
+        this->maxYaw_ = 90;
+        this->once_ = false;
+        this->rotation_ = Quaternion::IDENTITY;
+
+        this->setRadarVisibility(false);
+
+        //this->rayTest_ = this->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
     }
 
     /**
-     * @brief Destructor
+        @brief 
+        Destructor. Destroys the rayTest_ element (if it was used)  .
      */
     Turret::~Turret()
     {
+        //this->getScene()->getSceneManager()->destroyQuery(this->rayTest_);
+    }
 
+    /**
+        @brief
+        Checks, if a WorldEntity is inside the turret's range.
+
+        This function is safe to use on turrets that are attached, rotated, etc.
+        The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius.
+
+        @param target
+        The WorldEntity to check
+
+        @return
+        The squared distance to the position. -1, if it's ouside of range
+    */
+    float Turret::isInRange(const WorldEntity* target )
+    {
+        //Check distance
+        Vector3 distance = target->getWorldPosition() - this->getWorldPosition();
+        float distanceVal = distance.squaredLength();
+        if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_))
+        {
+            return -1.f;
+        }
+
+        //Check pitch
+        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 -1.f;
+        }
+
+        //Check yaw
+        dirProjected = dir;
+        dirProjected.y = 0;
+        startDirProjected = this->startDir_;
+        startDirProjected.y = 0;
+        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxYaw_)
+        {
+            return -1.f;
+        }
+
+        //TODO: Finish this. Find a way to convert objects from Ogre to Orxonox
+        /*Ogre::Ray ray = Ogre::Ray(this->getWorldPosition(), distance);
+        this->rayTest_->setRay(ray);
+        Ogre::RaySceneQueryResult result = this->rayTest_->execute();*/
+
+
+        return distanceVal;
     }
 
+    /**
+        @brief
+        Rotates the turret to make it aim at a certain position.
 
-    void Turret::rotatePitch(const Vector2& value)
+        @note
+        There are no checks, if the position is valid (i.e. if the turret is allowed to aim there).
+        This function must be called again for every tick, or the turret will stop rotating.
+
+        @param position
+        The position to aim at
+    */
+    void Turret::aimAtPosition(const Vector3& position)
     {
-        orxout()<< "Turret rotate Pitch"<< endl;
+        Vector3 currDir = this->getWorldOrientation() * WorldEntity::FRONT;
+        Vector3 targetDir = position - this->getWorldPosition();
 
-        const Quaternion& orient = this->getOrientation();
-        Radian pitch = orient.getPitch();
+        this->rotation_ = currDir.getRotationTo(targetDir);
+    }
 
-        if((value.x > 0 && pitch < Radian(180)) || (value.x < 0 && pitch > Radian(0)))
-            SpaceShip::rotatePitch(value);
+    /**
+        @brief
+        Does currently nothing.
+
+        Should rotate the turret with the specified pitch. Contains a failed attempt at limiting said rotation.
+    */
+    void Turret::rotatePitch(const Vector2& value)
+    {    
+        //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
+        /*
+        Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+        Vector3 currentDirProjected = currentDir;
+        currentDirProjected.x = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.x = 0;     
+        Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees();
+        //orxout() << "Pitch: " << angle << endl;   
+        //if(angle < this->maxPitch_ || (currentDirProjected.y <= 0 && value.x > 0) || (currentDirProjected.y > 0 && value.x < 0) )
+        {
+            this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
+        }
+        */
     }
 
+    /**
+        @brief
+        Does currently nothing.
 
-    void Turret::setAlertnessRadius(float value)
+        Should rotate the turret with the specified yaw. Contains a failed attempt at limiting said rotation.
+    */
+    void Turret::rotateYaw(const Vector2& value)
     {
-        this->controller_->setAlertnessRadius(value);
+        //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
+        /*
+        Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+        Vector3 currentDirProjected = currentDir;
+        currentDirProjected.y = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.y = 0;
+        Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees();
+        orxout() << "Yaw: " << angle << endl;
+        if(angle < this->maxYaw_ || (currentDirProjected.x <= 0 && value.x < 0) || (currentDirProjected.x > 0 && value.x > 0))
+        {
+            this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
+        }
+        */
     }
-    float Turret::getAlertnessRadius()
+
+    /**
+        @brief
+        Does currently nothing.
+
+        May be used to limit turret's rotation in the future.
+    */
+    void Turret::rotateRoll(const Vector2& value)
     {
-        return this->controller_->getAlertnessRadius();
     }
 
+    /**
+        @brief
+        Loads parameters from xml
+
+        Parameters loaded are: rotationThrust, maxAttackRadius, minAttackRadius, maxYaw, maxPitch
+    */
     void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(Turret, XMLPort, xmlelement, mode);
-        XMLPortParam(Turret, "alertnessRadius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues("400");
+        
+        XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode);
+        XMLPortParam(Turret, "maxAttackRadius", setMaxAttackRadius, getMaxAttackRadius, xmlelement, mode);
+        XMLPortParam(Turret, "minAttackRadius", setMinAttackRadius, getMinAttackRadius, xmlelement, mode);
+        XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
+        XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
     }
 
+    /**
+        @brief
+        The turret's actions are done here.
 
-}
+        Every tick, the turret gets rotated if it should, and the local axes get updated with the parent's rotation.
+    
+        @param dt
+        Duration of the tick
+    */
+    void Turret::tick(float dt)
+    {
+        SUPER(Turret, tick, dt);
+
+        //Stuff isn't properly initialized in the c'tor, so we have to do it like this
+        if(!this->once_)
+        {
+            //Account for rotations done in xml
+            Quaternion startOrient = this->getOrientation();
+            this->localXStart_ = startOrient * this->localX_;
+            this->localXStart_.normalise();
+            this->localX_ = this->localXStart_;
+            this->localYStart_ = startOrient * this->localY_;
+            this->localYStart_.normalise();
+            this->localY_ = this->localYStart_;
+            this->localZStart_ = startOrient * this->localZ_;
+            this->localZStart_.normalise();
+            this->localZ_ = this->localZStart_;
+
+            //startDir should always be (0,0,-1)
+            this->startDir_ = getTransformedVector(startOrient * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+            this->once_ = true;
+
+        }
+
+        //Adjust local axes to parent's rotation
+        WorldEntity* parent = this->getParent();
+        if(parent)
+        {
+            Quaternion parentrot = parent->getWorldOrientation();
+            this->localX_ = parentrot * this->localXStart_;
+            this->localY_ = parentrot * this->localYStart_;
+            this->localZ_ = parentrot * this->localZStart_;
+        }
+
+        //rotate
+        if(this->rotation_ != Quaternion::IDENTITY)
+        {
+            //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great...
+            //TODO: make the rotation better (constant velocity etc.). At the moment, the turret rotates
+            //slower the closer it is to the destination
+            Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
+            this->rotate(drot, WorldEntity::World);
+            this->rotation_ = Quaternion::IDENTITY;
+        }
+
+    }
+}
\ No newline at end of file

Modified: code/branches/towerdefenseHS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/towerdefenseHS14/src/modules/objects/Turret.h	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/modules/objects/Turret.h	2014-12-03 11:49:15 UTC (rev 10144)
@@ -20,14 +20,13 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *   Author:
- *      Marian Runo
+ *      Marian Runo, Martin Mueller
  *   Co-authors:
  *      ...
  *
  */
 
 /**
-    @file Turret.h
     @brief Definition of the Turret class.
     @ingroup Objects
 */
@@ -36,33 +35,93 @@
 #define _Turret_H__
 
 #include "objects/ObjectsPrereqs.h"
+#include "worldentities/pawns/Pawn.h"
+#include <OgreSceneQuery.h>
 
-#include "worldentities/pawns/SpaceShip.h"
-
 namespace orxonox
 {
-    class _ObjectsExport Turret : public SpaceShip
+    /**
+    @brief
+        Creates a turret with limited rotation. The point of this class is to be able to attach
+        a turret to a spaceship or a spacestation which is more or less completely autonomous in
+        it's behaviour.
+
+        This class also contains a custom local coordinate system, which gets initially rotated through xml, and
+        afterwards is updated with the parent's rotation (if there is one). This allows for almost trivialal calculation
+        of pitch, yaw and roll through coordinate transformation. (TODO: Ogre should do something like this already, investigate...)
+        
+
+    @note
+        The rotation isn't limited "physically". You have to call isInRange to find out if the turret is allowed to shoot at a target.
+    */
+    class _ObjectsExport Turret : public Pawn
     {
         public:
             Turret(Context* context);
             virtual ~Turret();
 
-            //virtual void tick(float dt);
-
             virtual void rotatePitch(const Vector2& value);
+            virtual void rotateYaw(const Vector2& value);
+            virtual void rotateRoll(const Vector2& value);
+            virtual float isInRange(const WorldEntity* target);
+            virtual void aimAtPosition(const Vector3 &position);
 
-            void setAlertnessRadius(float value);
-            float getAlertnessRadius();
-
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
 
+            /** @brief Sets the maximum distance the turret is allowed to shoot. @param radius The distance*/
+            inline void setMaxAttackRadius(float radius)
+                { this->maxAttackRadius_ = radius; }
 
+            /** @brief Sets the minimum distance the turret is allowed to shoot. @param radius The distance*/
+            inline void setMinAttackRadius(float radius)
+                { this->minAttackRadius_ = radius; }
+
+            /** @brief Sets the maximum pitch the turret can have (in both directions). @param pitch The pitch (in one direction)*/
+            inline void setMaxPitch(float pitch)
+                { this->maxPitch_ = pitch; }
+
+            /** @brief Sets the maximum yaw the turret can have (in both directions). @param yaw The yaw (in one direction)*/
+            inline void setMaxYaw(float yaw)
+                { this->maxYaw_ = yaw; }
+
+            /** @brief Returns the maximum distance the turret is allowed to shoot. @return The distance */
+            inline float getMaxAttackRadius() const
+                { return this->maxAttackRadius_; }                
+
+            /** @brief Returns the minimum distance the turret is allowed to shoot. @return The distance */
+            inline float getMinAttackRadius() const
+                { return this->minAttackRadius_; }   
+
+            /** @brief Returns the maximum pitch the turret can have. @return The pitch */
+            inline float getMaxPitch() const
+                { return this->maxPitch_; }
+
+            /** @brief Returns the maximum yaw the turret can have. @return The yaw */
+            inline float getMaxYaw() const
+                { return this->maxYaw_; }
+
         protected:
-            WaypointPatrolController* controller_;
+            Vector3 startDir_; //!< The initial facing direction, in local coordinates.
+            Vector3 localZ_; //!< The local z-axis, includes for the parent's rotation and rotations done in xml.
+            Vector3 localY_; //!< The local y-axis, includes for the parent's rotation and rotations done in xml.
+            Vector3 localX_; //!< The local x-axis, includes for the parent's rotation and rotations done in xml.      
+            Quaternion rotation_; //!< The rotation to be done by the turret.
+
         private:
+            bool once_; //!< Flag for executing code in the tick function only once.
 
+            Vector3 localZStart_; //!< The local z-axis, without the parent's rotation.
+            Vector3 localYStart_; //!< The local y-axis, without the parent's rotation.
+            Vector3 localXStart_; //!< The local x-axis, without the parent's rotation.
+            float maxAttackRadius_; //!< The maximum distance the turret is allowed to shoot.
+            float minAttackRadius_; //!< The minimum distance the turret is allowed to shoot.
+            Ogre::Real maxPitch_; //!< The maxmium pitch the turret can have (on one side).
+            Ogre::Real maxYaw_; //!< The maxmium yaw the turret can have (on one side).
+            float rotationThrust_;  //!< The velocity the turret rotates with.
+            Ogre::RaySceneQuery* rayTest_; //!< Used to perform a raytest, currently unused @see isInRange
+
     };
 }
 
 #endif
-

Modified: code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
===================================================================
--- code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc	2014-12-03 11:49:15 UTC (rev 10144)
@@ -157,7 +157,7 @@
 
         for (int i = 0; i < kInitialTowerCount; i++)
         {
-            addTower(i+4,(i+5));
+            addTower(i+4,i+5);
         }
 
 
@@ -276,7 +276,7 @@
 
   //    Create tower
         TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext());
-        towernew->addTemplate("tower");
+        towernew->addTemplate("towerturret");
         towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75);
         towernew->setGame(this);
 

Modified: code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/orxonox/controllers/ArtificialController.cc	2014-12-03 11:49:15 UTC (rev 10144)
@@ -93,7 +93,7 @@
 
         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);
 
         Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());

Modified: code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc	2014-11-26 16:18:44 UTC (rev 10143)
+++ code/branches/towerdefenseHS14/src/orxonox/worldentities/WorldEntity.cc	2014-12-03 11:49:15 UTC (rev 10144)
@@ -413,8 +413,9 @@
             }
             else if (this->isDynamic())
             {
-                orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
-                return false;
+                //***HACKY HACK (to allow turrets to be attached)***
+                //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
+                //return false;
             }
             else if (this->isKinematic() && newParent->isDynamic())
             {




More information about the Orxonox-commit mailing list