Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10049


Ignore:
Timestamp:
May 8, 2014, 4:04:53 PM (10 years ago)
Author:
muemart
Message:

Delete the old turret templates and make new ones. Adjust the weapon positions for the turret. Add a proxy controller for teams and targets. Add comments

Location:
code/branches/turretFS14
Files:
3 added
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/turretFS14/data/levels/includes/weaponSettingsTurret.oxi

    r9664 r10049  
    1111        </links>
    1212        <Weapon>
    13           <attached>
    14             <Model mesh="sphere.mesh" position="3,3,-2.2" scale=0.6 />
    15           </attached>
    16           <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset=" 3, 3,-2.2" />
    17           <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset=" 3,-3,-2.2" />
    18           <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset="-3, 3,-2.2" />
    19           <HsW01 mode=0 munitionpershot=0 delay=0 damage=3.14159 material="Flares/point_lensflare" muzzleoffset="-3,-3,-2.2" />
     13          <!-- <attached>
     14            <Model mesh="sphere.mesh" position="1.7,1.7,-24.5" scale=0.6 />
     15          </attached> -->
     16          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="1.7, 1.7,-30" />
     17          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="1.7, -1.7,-30" />
     18          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-1.7, 1.7,-30" />
     19          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-1.7, -1.7,-30" />
    2020        </Weapon>
    2121      </WeaponPack>
  • code/branches/turretFS14/data/levels/turretTest.oxw

    r10044 r10049  
    1616<?lua
    1717  include("templates/spaceshipAssff.oxt")
    18   include("templates/spaceshipPirate.oxt")
    19   include("templates/spaceshipTurretTest.oxt")
     18  include("templates/spaceshipTransporter.oxt")
     19  include("templates/standardTurret.oxt")
    2020?>
    2121
     
    3333    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3434
    35 
    36 <!-- <SpaceShip position="-100,0,0" yaw=0 pitch=0>
    37     <attached>
    38         <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
    39         <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" />
    40         <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" />
    41         <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" />
    42         <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" />
    43 
    44         <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
    45             <templates>
    46               <Template link=spaceshipturrettest />
    47             </templates>
    48             <controller>
    49               <TurretController team=10 />
    50             </controller>
    51         </Turret>
    52 
    53         <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
    54 
    55         <Model mesh="sphere.mesh" position="0,25,0" scale=1/>
    56 
    57         <Model mesh="sphere.mesh" position="0,0,30" scale=1/>
    58 
    59     </attached>
    60 </SpaceShip> -->
    61 
    62 
    63 <StaticEntity position="100,0,0">
     35<SpaceShip>
    6436  <attached>
    65     <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
    66 
    67     <Model mesh="sphere.mesh" position="0,25,0" scale=1.5/>
    68 
    69     <Model mesh="sphere.mesh" position="0,0,30" scale=2/>
     37    <Turret position="10,2,0" pitch="90" yaw="0" roll="0" scale3D="0.2,0.2,0.2">
     38      <templates>
     39        <Template link=standardturret />
     40      </templates>
     41    </Turret>   
     42    <Turret position="-10,2,0" pitch="90" yaw="0" roll="0" scale3D="0.2,0.2,0.2">
     43      <templates>
     44        <Template link=standardturret />
     45      </templates>
     46    </Turret>   
     47    <Turret position="0,2,0" pitch="90" yaw="0" roll="0" scale3D="0.2,0.2,0.2">
     48      <templates>
     49        <Template link=standardturret />
     50      </templates>
     51    </Turret>   
    7052  </attached>
    71  
    72 </StaticEntity>
    73 <SpaceShip position="100,0,0" yaw=0 pitch=90>
    74     <attached>
    75         <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
    76         <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" />
    77         <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" />
    78         <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" />
    79         <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" />
    80 
    81         <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
    82             <templates>
    83               <Template link=spaceshipturrettest />
    84             </templates>
    85             <controller>
    86               <TurretController team=10 />
    87             </controller>
    88         </Turret>
    89 
    90 
    91 
    92     </attached>
     53  <templates>
     54    <Template link=spaceshipassff />
     55  </templates>
     56<!--   <controller>
     57    <AIController />
     58  </controller> -->
    9359</SpaceShip>
    9460
  • code/branches/turretFS14/src/modules/objects/Turret.cc

    r10044 r10049  
    3838
    3939    /**
    40      * @brief Constructor
     40        @brief
     41        Sets default values for all variables. Also hides the turret from the radar.
     42
     43        @param context
     44        The context
    4145     */
    4246    Turret::Turret(Context* context) : Pawn(context)
     
    4852        this->localY_ = Vector3::UNIT_Y;
    4953        this->localX_ = Vector3::UNIT_X;
    50         this->attackRadius_ = 200;
     54        this->maxAttackRadius_ = 200;
     55        this->minAttackRadius_ = 0;
    5156        this->maxPitch_ = 90;
    5257        this->maxYaw_ = 90;
     
    5863
    5964    /**
    60      * @brief Destructor
     65        @brief
     66        Destructor. Nothing to see here.
    6167     */
    6268    Turret::~Turret()
     
    6571    }
    6672
    67 
     73    /**
     74        @brief
     75        Checks, if a (world)position is inside the turret's range.
     76
     77        This function is safe to use on turrets that are attached, rotated, etc.
     78        The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius'.
     79
     80        @param position
     81        The position to check
     82    */
    6883    bool Turret::isInRange(const Vector3 &position)
    6984    {
    7085        //Check distance
    7186        Vector3 distance = position - this->getWorldPosition();
    72         if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
     87        float distanceVal = distance.squaredLength();
     88        if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_))
    7389        {
    7490            return false;
     
    100116    }
    101117
     118    /**
     119        @brief
     120        Rotates the turret to make it aim at a certain position.
     121
     122        @note
     123        There are no checks, if the position is valid (i.e. if the turret is allowed to aim there).
     124        This function must be called again for every tick, or the turret will stop rotating.
     125
     126        @param position
     127        The position to aim at
     128    */
    102129    void Turret::aimAtPosition(const Vector3& position)
    103130    {
     
    106133
    107134        this->rotation_ = currDir.getRotationTo(targetDir);
    108 
    109     }
    110 
     135    }
     136
     137    /**
     138        @brief
     139        Does currently nothing.
     140
     141        Should rotate the turret with the specified pitch. Contains a failed attempt at limiting said rotation.
     142    */
    111143    void Turret::rotatePitch(const Vector2& value)
    112144    {   
     
    127159    }
    128160
     161    /**
     162        @brief
     163        Does currently nothing.
     164
     165        Should rotate the turret with the specified yaw. Contains a failed attempt at limiting said rotation.
     166    */
    129167    void Turret::rotateYaw(const Vector2& value)
    130168    {
     
    145183    }
    146184
     185    /**
     186        @brief
     187        Does currently nothing.
     188
     189        May be used to limit turret's rotation in the future.
     190    */
    147191    void Turret::rotateRoll(const Vector2& value)
    148192    {
    149193    }
    150194
     195    /**
     196        @brief
     197        Loads parameters from xml
     198
     199        Parameters loaded are: rotationThrust, maxAttackRadius, minAttackRadius, maxYaw, maxPitch
     200    */
    151201    void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    152202    {
     
    154204       
    155205        XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode);
    156         XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
     206        XMLPortParam(Turret, "maxAttackRadius", setMaxAttackRadius, getMaxAttackRadius, xmlelement, mode);
     207        XMLPortParam(Turret, "minAttackRadius", setMinAttackRadius, getMinAttackRadius, xmlelement, mode);
    157208        XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
    158209        XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
    159210    }
    160211
     212    /**
     213        @brief
     214        The turret's actions are done here.
     215
     216        Every tick, the turret gets rotated if it should, and the local axes get updated with the parent's rotation.
     217    */
    161218    void Turret::tick(float dt)
    162219    {
     
    166223        if(!this->once_)
    167224        {
    168 
     225            //Account for rotations done in xml
    169226            Quaternion startOrient = this->getOrientation();
    170227            this->localXStart_ = startOrient * this->localX_;
     
    198255        if(this->rotation_ != Quaternion::IDENTITY)
    199256        {
    200             //Don't make the rotation instantaneous
    201             Quaternion drot = Quaternion::Slerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
     257            //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great...
     258            Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
    202259            this->rotate(drot, WorldEntity::World);
    203260            this->rotation_ = Quaternion::IDENTITY;
  • code/branches/turretFS14/src/modules/objects/Turret.h

    r10044 r10049  
    2121 *
    2222 *   Author:
    23  *      Marian Runo
     23 *      Marian Runo, Martin Mueller
    2424 *   Co-authors:
    2525 *      ...
     
    2828
    2929/**
    30     @file Turret.h
    3130    @brief Definition of the Turret class.
    3231    @ingroup Objects
     
    4140namespace orxonox
    4241{
     42    /**
     43    @brief
     44        Creates a turret with limited rotation. The point of this class is to be able to attach
     45        a turret to a spaceship or a spacestation which is more or less completely autonomous in
     46        it's behaviour.
     47
     48    @note
     49        The rotation isn't limited "physically". You have to call isInRange to find out if the turret is allowed to shoot at a target.
     50    */
    4351    class _ObjectsExport Turret : public Pawn
    4452    {
     
    5664            virtual void tick(float dt);
    5765
    58             inline void setAttackRadius(float radius)
    59                 { this->attackRadius_ = radius; }
     66            /** @brief Sets the maximum distance the turret is allowed to shoot. @param radius The distance*/
     67            inline void setMaxAttackRadius(float radius)
     68                { this->maxAttackRadius_ = radius; }
    6069
     70            /** @brief Sets the minimum distance the turret is allowed to shoot. @param radius The distance*/
     71            inline void setMinAttackRadius(float radius)
     72                { this->minAttackRadius_ = radius; }
     73
     74            /** @brief Sets the maximum pitch the turret can have (in both directions). @param pitch The pitch (in one direction)*/
    6175            inline void setMaxPitch(float pitch)
    6276                { this->maxPitch_ = pitch; }
    6377
     78            /** @brief Sets the maximum yaw the turret can have (in both directions). @param yaw The yaw (in one direction)*/
    6479            inline void setMaxYaw(float yaw)
    6580                { this->maxYaw_ = yaw; }
    6681
    67             inline float getAttackRadius() const
    68                 { return this->attackRadius_; }               
     82            /** @brief Returns the maximum distance the turret is allowed to shoot. @return The distance */
     83            inline float getMaxAttackRadius() const
     84                { return this->maxAttackRadius_; }               
    6985
     86            /** @brief Returns the minimum distance the turret is allowed to shoot. @return The distance */
     87            inline float getMinAttackRadius() const
     88                { return this->minAttackRadius_; }   
     89
     90            /** @brief Returns the maximum pitch the turret can have. @return The pitch */
    7091            inline float getMaxPitch() const
    7192                { return this->maxPitch_; }
    7293
     94            /** @brief Returns the maximum yaw the turret can have. @return The yaw */
    7395            inline float getMaxYaw() const
    7496                { return this->maxYaw_; }
    7597
    7698        protected:
    77             Vector3 startDir_;
    78             Vector3 localZ_;
    79             Vector3 localZStart_;
    80             Vector3 localY_;
    81             Vector3 localYStart_;
    82             Vector3 localX_;
    83             Vector3 localXStart_;           
     99            Vector3 startDir_; //!< The initial facing direction, in local coordinates.
     100            Vector3 localZ_; //!< The local z-axis, includes for the parent's rotation and rotations done in xml.
     101            Vector3 localY_; //!< The local y-axis, includes for the parent's rotation and rotations done in xml.
     102            Vector3 localX_; //!< The local x-axis, includes for the parent's rotation and rotations done in xml.     
     103            Quaternion rotation_; //!< The rotation to be done by the turret.
    84104
    85105        private:
    86             bool once_;
     106            bool once_; //!< Flag for executing code in the tick function only once.
    87107
    88             float attackRadius_;
    89             Ogre::Real maxPitch_;
    90             Ogre::Real maxYaw_;
    91             float rotationThrust_;
     108            Vector3 localZStart_; //!< The local z-axis, without the parent's rotation.
     109            Vector3 localYStart_; //!< The local y-axis, without the parent's rotation.
     110            Vector3 localXStart_; //!< The local x-axis, without the parent's rotation.
     111            float maxAttackRadius_; //!< The maximum distance the turret is allowed to shoot.
     112            float minAttackRadius_; //!< The minimum distance the turret is allowed to shoot.
     113            Ogre::Real maxPitch_; //!< The maxmium pitch the turret can have (on one side).
     114            Ogre::Real maxYaw_; //!< The maxmium yaw the turret can have (on one side).
     115            float rotationThrust_;  //!< The velocity the turret rotates with.
    92116
    93             Quaternion rotation_;
    94117    };
    95118}
  • code/branches/turretFS14/src/modules/objects/controllers/CMakeLists.txt

    r10008 r10049  
    11ADD_SOURCE_FILES(OBJECTS_SRC_FILES
    22  TurretController.cc
     3  TeamTargetProxy.cc
    34)
  • code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc

    r10044 r10049  
    136136                        {
    137137                                this->getControllableEntity()->fire(0);
    138                                 orxout() << 42 << endl;
    139138                        }
    140139                }
  • code/branches/turretFS14/src/modules/objects/controllers/TurretController.h

    r10044 r10049  
    2727 */
    2828
    29  #ifndef _TurretController_H__
    30  #define _TurretController_H__
     29/**
     30    @brief Definition for the controller for turrets.
     31*/
     32
     33#ifndef _TurretController_H__
     34#define _TurretController_H__
    3135
    3236#include "OrxonoxPrereqs.h"
     
    3539 namespace orxonox
    3640 {
     41        /**
     42                @brief
     43                Controller for turrets. Chooses a target, and makes the turret aim/shoot at it.
     44
     45                The controllableEntity gets casted to Turret, so this controller won't work for anything else.
     46        */
    3747        class _OrxonoxExport TurretController : public ArtificialController, public Tickable
    3848        {
Note: See TracChangeset for help on using the changeset viewer.