Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 8, 2014, 4:04:53 PM (11 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.