Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10044


Ignore:
Timestamp:
May 6, 2014, 11:07:07 AM (10 years ago)
Author:
muemart
Message:

Move everything back to the Turret class, set the correct team, and (re)arm the turret. Also, hide it from the radar.

Location:
code/branches/turretFS14
Files:
8 edited

Legend:

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

    r10004 r10044  
    1414            <Model mesh="sphere.mesh" position="3,3,-2.2" scale=0.6 />
    1515          </attached>
    16           <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 3, 3,-2.2" />
    17           <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 3,-3,-2.2" />
    18           <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-3, 3,-2.2" />
    19           <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-3,-3,-2.2" />
     16          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 30, 3,-2.2" />
     17          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 30,-3,-2.2" />
     18          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-30, 3,-2.2" />
     19          <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-30,-3,-2.2" />
    2020        </Weapon>
    2121      </WeaponPack>
  • code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt

    r10039 r10044  
    4848      <BlinkingBillboard position="17,-1.5,0" material="Examples/Flare" colour="1.0, 0.5, 0.3" amplitude=0.1 frequency=0.5 quadratic=1 />
    4949      <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 />
    50 
    51                <!-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
    52             <templates>
    53               <Template link=spaceshipturrettest />
    54             </templates>
    55             <controller>
    56               <TurretController team=10 />
    57             </controller>
    58         </Turret> -->
    59 
    6050    </attached>
    6151    <collisionShapes>
  • code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt

    r10031 r10044  
    77        <SphereCollisionShape radius="10"   position = "0,0,0"/>
    88    </collisionShapes>
    9   </Turret>
    109<?lua
    1110  include("../includes/weaponSettingsTurretTest.oxi")
    1211?>
     12  </Turret>
    1313</Template>
    1414
  • code/branches/turretFS14/data/levels/turretTest.oxw

    r10042 r10044  
    5959    </attached>
    6060</SpaceShip> -->
     61
     62
    6163<StaticEntity position="100,0,0">
    6264  <attached>
     
    6769    <Model mesh="sphere.mesh" position="0,0,30" scale=2/>
    6870  </attached>
     71 
    6972</StaticEntity>
    7073<SpaceShip position="100,0,0" yaw=0 pitch=90>
  • code/branches/turretFS14/src/modules/objects/Turret.cc

    r10042 r10044  
    2121 *
    2222 *   Author:
    23  *      Marian Runo
     23 *      Marian Runo, Martin Mueller
    2424 *   Co-authors:
    2525 *      ...
     
    3030#include "core/CoreIncludes.h"
    3131#include "core/XMLPort.h"
    32 #include "BulletDynamics/Dynamics/btRigidBody.h"
    3332
    3433namespace orxonox
     
    4544        RegisterObject(Turret);
    4645        this->rotationThrust_ = 50;
    47 
    48         this->localAngularAcceleration_.setValue(0, 0, 0);
     46        this->startDir_ = Vector3::ZERO;
     47        this->localZ_ = Vector3::UNIT_Z;
     48        this->localY_ = Vector3::UNIT_Y;
     49        this->localX_ = Vector3::UNIT_X;
     50        this->attackRadius_ = 200;
     51        this->maxPitch_ = 90;
     52        this->maxYaw_ = 90;
     53        this->once_ = false;
     54        this->rotation_ = Quaternion::IDENTITY;
     55
     56        this->setRadarVisibility(false);
    4957    }
    5058
     
    5765    }
    5866
     67
     68    bool Turret::isInRange(const Vector3 &position)
     69    {
     70        //Check distance
     71        Vector3 distance = position - this->getWorldPosition();
     72        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
     73        {
     74            return false;
     75        }
     76
     77        //Check pitch
     78        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
     79        Vector3 dirProjected = dir;
     80        dirProjected.x = 0;
     81        Vector3 startDirProjected = this->startDir_;
     82        startDirProjected.x = 0;
     83        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
     84        if(angle > this->maxPitch_)
     85        {
     86            return false;
     87        }
     88
     89        //Check yaw
     90        dirProjected = dir;
     91        dirProjected.y = 0;
     92        startDirProjected = this->startDir_;
     93        startDirProjected.y = 0;
     94        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
     95        if(angle > this->maxYaw_)
     96        {
     97            return false;
     98        }
     99        return true;
     100    }
     101
     102    void Turret::aimAtPosition(const Vector3& position)
     103    {
     104        Vector3 currDir = this->getWorldOrientation() * WorldEntity::FRONT;
     105        Vector3 targetDir = position - this->getWorldPosition();
     106
     107        this->rotation_ = currDir.getRotationTo(targetDir);
     108
     109    }
    59110
    60111    void Turret::rotatePitch(const Vector2& value)
     
    74125        }
    75126        */
    76         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
    77127    }
    78128
     
    93143        }
    94144        */
    95         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
    96145    }
    97146
    98147    void Turret::rotateRoll(const Vector2& value)
    99148    {
    100         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x*0.8f);
    101149    }
    102150
     
    104152    {
    105153        SUPER(Turret, XMLPort, xmlelement, mode);
     154       
     155        XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode);
     156        XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
     157        XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
     158        XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
    106159    }
    107160
     
    110163        SUPER(Turret, tick, dt);
    111164
    112         this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    113         this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
    114 
    115         //physics don't work when attached :(
    116         //this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    117 
    118         pitch(Degree(localAngularAcceleration_.x()*dt/1000), WorldEntity::World);
    119         yaw(Degree(localAngularAcceleration_.y()*dt/1000), WorldEntity::World);
    120         roll(Degree(localAngularAcceleration_.z()*dt/1000), WorldEntity::World);
    121 
    122         this->localAngularAcceleration_.setValue(0, 0, 0);
     165
     166        if(!this->once_)
     167        {
     168
     169            Quaternion startOrient = this->getOrientation();
     170            this->localXStart_ = startOrient * this->localX_;
     171            this->localXStart_.normalise();
     172            this->localX_ = this->localXStart_;
     173            this->localYStart_ = startOrient * this->localY_;
     174            this->localYStart_.normalise();
     175            this->localY_ = this->localYStart_;
     176            this->localZStart_ = startOrient * this->localZ_;
     177            this->localZStart_.normalise();
     178            this->localZ_ = this->localZStart_;
     179
     180            //startDir should always be (0,0,-1)
     181            this->startDir_ = getTransformedVector(startOrient * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
     182
     183            this->once_ = true;
     184
     185        }
     186
     187        //Adjust local axes to parent's rotation
     188        WorldEntity* parent = this->getParent();
     189        if(parent)
     190        {
     191            Quaternion parentrot = parent->getWorldOrientation();
     192            this->localX_ = parentrot * this->localXStart_;
     193            this->localY_ = parentrot * this->localYStart_;
     194            this->localZ_ = parentrot * this->localZStart_;
     195        }
     196
     197        //rotate
     198        if(this->rotation_ != Quaternion::IDENTITY)
     199        {
     200            //Don't make the rotation instantaneous
     201            Quaternion drot = Quaternion::Slerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
     202            this->rotate(drot, WorldEntity::World);
     203            this->rotation_ = Quaternion::IDENTITY;
     204        }
     205
    123206    }
    124207}
  • code/branches/turretFS14/src/modules/objects/Turret.h

    r10039 r10044  
    5050            virtual void rotateYaw(const Vector2& value);
    5151            virtual void rotateRoll(const Vector2& value);
     52            virtual bool isInRange(const Vector3 &position);
     53            virtual void aimAtPosition(const Vector3 &position);
    5254
    5355            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5456            virtual void tick(float dt);
    5557
     58            inline void setAttackRadius(float radius)
     59                { this->attackRadius_ = radius; }
     60
     61            inline void setMaxPitch(float pitch)
     62                { this->maxPitch_ = pitch; }
     63
     64            inline void setMaxYaw(float yaw)
     65                { this->maxYaw_ = yaw; }
     66
     67            inline float getAttackRadius() const
     68                { return this->attackRadius_; }               
     69
     70            inline float getMaxPitch() const
     71                { return this->maxPitch_; }
     72
     73            inline float getMaxYaw() const
     74                { return this->maxYaw_; }
     75
     76        protected:
     77            Vector3 startDir_;
     78            Vector3 localZ_;
     79            Vector3 localZStart_;
     80            Vector3 localY_;
     81            Vector3 localYStart_;
     82            Vector3 localX_;
     83            Vector3 localXStart_;           
    5684
    5785        private:
     86            bool once_;
     87
     88            float attackRadius_;
     89            Ogre::Real maxPitch_;
     90            Ogre::Real maxYaw_;
    5891            float rotationThrust_;
    5992
    60             btVector3 localAngularAcceleration_;
     93            Quaternion rotation_;
    6194    };
    6295}
  • code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc

    r10042 r10044  
    3838        {
    3939                RegisterObject(TurretController);
    40                 this->startOrient_ = Quaternion::IDENTITY;
    41         this->startDir_ = Vector3::ZERO;
    42         this->localZ_ = Vector3::UNIT_Z;
    43         this->localY_ = Vector3::UNIT_Y;
    44         this->localX_ = Vector3::UNIT_X;
    45         this->attackRadius_ = 200;
    46         this->maxPitch_ = 90;
    47         this->maxYaw_ = 90;
    48         this->gotOrient_ = false;
     40
     41                this->once_ = false;
     42
    4943        }
    5044
     
    5751        {
    5852        Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
    59         if(target_ && this->isInRange(target_->getWorldPosition()))
     53        if(target_ && turret->isInRange(target_->getWorldPosition()))
    6054        {
    6155                return;
     
    6458        {
    6559                this->forgetTarget();
     60                turret->setTarget(0);
    6661        }
    6762
     
    7166        {
    7267                Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
    73                 if(parenttarget && this->isInRange(parenttarget->getWorldPosition()))
     68                if(parenttarget && turret->isInRange(parenttarget->getWorldPosition()))
    7469                {
    7570                        this->setTarget(parenttarget);
     
    8277        {
    8378                Pawn* entity = orxonox_cast<Pawn*>(*it);
    84             if (ArtificialController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
     79            if (this->FormationController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
    8580                continue;
    8681
    87             if(this->isInRange(entity->getWorldPosition()))
     82            if(turret->isInRange(entity->getWorldPosition()))
    8883            {
    8984                this->setTarget(entity);
     
    9489        }
    9590
    96         bool TurretController::isInRange(const Vector3 &position)
    97     {
    98         //Check distance
    99         Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
    100         if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
    101         {
    102             return false;
    103         }
    104 
    105         //Check pitch
    106         Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
    107         Vector3 dirProjected = dir;
    108         dirProjected.x = 0;
    109         Vector3 startDirProjected = this->startDir_;
    110         startDirProjected.x = 0;
    111         Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
    112         if(angle > this->maxPitch_)
    113         {
    114             return false;
    115         }
    116 
    117         //Check yaw
    118         dirProjected = dir;
    119         dirProjected.y = 0;
    120         startDirProjected = this->startDir_;
    121         startDirProjected.y = 0;
    122         angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
    123         if(angle > this->maxYaw_)
    124         {
    125             return false;
    126         }
    127         return true;
    128     }
    129 
    130     void TurretController::aimAtPositionRot(const Vector3 &position)
    131     {
    132 
    133         Vector3 currDir = this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT;
    134         Vector3 targetDir = position - this->getControllableEntity()->getWorldPosition();
    135 
    136         Quaternion rot = currDir.getRotationTo(targetDir);
    137 
    138         //Don't make the rotation instantaneous
    139         rot = Quaternion::Slerp(0.1, Quaternion::IDENTITY, rot);
    140 
    141         this->getControllableEntity()->rotate(rot, WorldEntity::World);
    142     }
    143    
    144 
    145     void TurretController::aimAtTargetRot()
    146     {
    147         this->aimAtPositionRot(this->target_->getWorldPosition());
    148     }
    149 
    15091    bool TurretController::isLookingAtTargetNew(float angle) const
    15192    {
     
    15596        void TurretController::tick(float dt)
    15697        {
    157                         if(!gotOrient_)
    158                 {
    159                     this->startOrient_ = this->getControllableEntity()->getOrientation();
    160                     this->localXStart_ = this->startOrient_ * this->localX_;
    161                     this->localXStart_.normalise();
    162                     this->localX_ = this->localXStart_;
    163                     this->localYStart_ = this->startOrient_ * this->localY_;
    164                     this->localYStart_.normalise();
    165                     this->localY_ = this->localYStart_;
    166                     this->localZStart_ = this->startOrient_ * this->localZ_;
    167                     this->localZStart_.normalise();
    168                     this->localZ_ = this->localZStart_;
    169 
    170                     //startDir should always be (0,0,-1)
    171                     this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
    172 
    173                     this->gotOrient_ = true;
    174 
    175                 }
    176 
    177                 WorldEntity* parent = this->getControllableEntity()->getParent();
    178                 if(parent)
    179                 {
    180                     Quaternion parentrot = parent->getOrientation();
    181                     this->localX_ = parentrot * this->localXStart_;
    182                     this->localY_ = parentrot * this->localYStart_;
    183                     this->localZ_ = parentrot * this->localZStart_;
    184                 }
     98            if (!this->isActive() || !this->getControllableEntity())
     99                return;
    185100
    186101
     102                if(!this->once_)
     103                {
     104                        if(this->getTeam() != -1)
     105                        {
     106                                orxout(internal_warning) << "Turret: Team already set, may result in undesired behaviour" << endl;
     107                        }
     108                        else
     109                        {
     110                    //Make sure the turret is in the same team as the parent
     111                    ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent());
     112                    if(parent)
     113                    {
     114                        Controller* parentcontroller = parent->getController();
     115                        if(parentcontroller)
     116                        {
     117                            this->setTeam(parentcontroller->getTeam());
     118                        }
     119                        else
     120                        {
     121                            this->setTeam(parent->getTeam());
     122                        }
     123                        this->getControllableEntity()->setTeam(parent->getTeam());
     124                    }
     125                }
     126            this->once_ = true;
     127        }
    187128
    188                 if (!this->isActive() || !this->getControllableEntity())
    189                     return;
    190 
    191                         this->searchTarget();
    192                         if(target_)
    193                         {
    194                                 this->aimAtTarget();
    195                                 //this->getControllableEntity()->lookAt(this->targetPosition_);
    196                                 //It says move, but really it only turns
    197                                 this->aimAtTargetRot();
    198                                 if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
    199                                 {
    200                                         orxout() << 42 << endl;
    201                                 }
    202                         }
     129                this->searchTarget();
     130                if(target_)
     131                {
     132                        Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity());
     133                        this->aimAtTarget();
     134                        turret->aimAtPosition(target_->getWorldPosition());
     135                        if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
     136                        {
     137                                this->getControllableEntity()->fire(0);
     138                                orxout() << 42 << endl;
     139                        }
     140                }
    203141        }
    204142 }
  • code/branches/turretFS14/src/modules/objects/controllers/TurretController.h

    r10042 r10044  
    4444
    4545                private:
    46             bool gotOrient_;
    47             float attackRadius_;
    48             Ogre::Real maxPitch_;
    49             Ogre::Real maxYaw_;
    50             Quaternion startOrient_;
    51             Vector3 startDir_;
    52             Vector3 localZ_;
    53             Vector3 localZStart_;
    54             Vector3 localY_;
    55             Vector3 localYStart_;
    56             Vector3 localX_;
    57             Vector3 localXStart_;
    5846
    59             void aimAtPositionRot(const Vector3 &position);
    60             void aimAtTargetRot();
    6147                        void searchTarget();
    62                         bool isInRange(const Vector3 &position);
    6348                        bool isLookingAtTargetNew(float angle) const;
     49
     50                        bool once_;
    6451        };
    6552 }
Note: See TracChangeset for help on using the changeset viewer.