Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 27, 2014, 1:36:50 PM (10 years ago)
Author:
muemart
Message:

first experiments with the turret

Location:
code/branches/turretFS14
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/turretFS14/data/levels/turretTest.oxw

    r9939 r10004  
    1717  include("templates/spaceshipAssff.oxt")
    1818  include("templates/spaceshipPirate.oxt")
    19   include("templates/spaceshipTurret.oxt")
     19  include("templates/spaceshipTurretTest.oxt")
    2020?>
    2121
     
    4848<Turret position="0,10,0" pitch="90" yaw="0" roll="0">
    4949    <templates>
    50         <Template link=spaceshipturret />
     50        <Template link=spaceshipturrettest />
    5151    </templates>
    5252    <controller>
  • code/branches/turretFS14/src/modules/objects/Turret.cc

    r9945 r10004  
    3737    RegisterClass(Turret);
    3838
     39
     40
    3941    /**
    4042     * @brief Constructor
     
    4446        RegisterObject(Turret);
    4547        this->controller_ = new WaypointPatrolController(this->getContext());
     48        gotOrient_ = false;
    4649    }
    4750
     
    5760    void Turret::rotatePitch(const Vector2& value)
    5861    {
    59         orxout()<< "Turret rotate Pitch"<< endl;
    60 
    61         const Quaternion& orient = this->getOrientation();
    62         Radian pitch = orient.getPitch();
    63 
    64         if((value.x > 0 && pitch < Radian(180)) || (value.x < 0 && pitch > Radian(0)))
    65             SpaceShip::rotatePitch(value);
     62        Radian currentPitch = this->getOrientation().getPitch();
     63        Radian startPitch = startOrient_.getPitch();
     64        Radian limit = Radian((Degree)45);
     65        Radian upperBoundary = startPitch+limit;
     66        if(upperBoundary > Radian(Degree(360)))
     67        {
     68            upperBoundary -= Radian(Degree(360));
     69        }
     70        Radian lowerBoundary = startPitch-limit;
     71        if(lowerBoundary < Radian(Degree(0)))
     72        {
     73            lowerBoundary += Radian(Degree(360));
     74        }
     75        //orxout() << "Pitch:\t" << currentPitch << "\t" << startPitch << endl;
     76       
     77        if(currentPitch > upperBoundary && value.x > 0 ||
     78           currentPitch < lowerBoundary && value.x < 0)
     79        {
     80            return;
     81        }
     82       
     83        //SpaceShip::rotatePitch(value);
    6684    }
    6785
     86    void Turret::rotateYaw(const Vector2& value)
     87    {
     88
     89        Radian currentYaw = this->getOrientation().getYaw();
     90        Radian startYaw = startOrient_.getYaw();
     91        Radian limit = Radian(Degree(45));
     92        Radian upperBoundary = startYaw + limit;
     93        Radian lowerBoundary = startYaw - limit;
     94        orxout() << currentYaw << " " << this->getOrientation().getRoll() << endl;
     95        /*if(upperBoundary >= Radian(Degree(180)));
     96        {
     97            upperBoundary -= Radian(Degree(180));
     98            lowerBoundary -= Radian(Degree(180));
     99            currentYaw -= Radian(Degree(180));
     100        }
     101        if(lowerBoundary <= Radian(Degree(-180)))
     102        {
     103            lowerBoundary += Radian(Degree(180));
     104            upperBoundary += Radian(Degree(180));
     105            currentYaw += Radian(Degree(180));
     106        }*/
     107        //orxout() << "Yaw:\t" << (Degree)currentYaw << "\t" << (Degree)upperBoundary << "\t" << (Degree)lowerBoundary << endl;
     108        //if((currentYaw > upperBoundary && value.x > 0) ||
     109        //   (currentYaw < lowerBoundary && value.x < 0))
     110        if((currentYaw < Radian(1) && value.x < 0) || (currentYaw > Radian(3) && value.x>0))
     111        {
     112            //return;
     113        }
     114        SpaceShip::rotateYaw(value);
     115    }
     116
     117    void Turret::rotateRoll(const Vector2& value)
     118    {
     119        return;
     120    }
    68121
    69122    void Turret::setAlertnessRadius(float value)
     
    82135    }
    83136
     137    void Turret::tick(float dt)
     138    {
     139        if(!gotOrient_)
     140        {
     141            startOrient_ = this->getOrientation();
     142            gotOrient_ = true;
     143        }
     144        SUPER(Turret, tick, dt);
     145    }
    84146
    85147}
  • code/branches/turretFS14/src/modules/objects/Turret.h

    r9667 r10004  
    3737
    3838#include "objects/ObjectsPrereqs.h"
     39#include "OgreQuaternion.h"
    3940
    4041#include "worldentities/pawns/SpaceShip.h"
     
    4849            virtual ~Turret();
    4950
    50             //virtual void tick(float dt);
    51 
    5251            virtual void rotatePitch(const Vector2& value);
     52            virtual void rotateYaw(const Vector2& value);
     53            virtual void rotateRoll(const Vector2& value);
    5354
    5455            void setAlertnessRadius(float value);
     
    5657
    5758            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     59            virtual void tick(float dt);
    5860
    5961
     
    6163            WaypointPatrolController* controller_;
    6264        private:
    63 
     65            bool gotOrient_;
     66            Quaternion startOrient_;
     67            Quaternion firstOrient_;
    6468    };
    6569}
Note: See TracChangeset for help on using the changeset viewer.