Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 17, 2014, 4:05:06 PM (11 years ago)
Author:
muemart
Message:

Move logic into controller, don't use bullet for rotations, and use WorldPosition in FormationController+ (good idea?)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/turretFS14/src/modules/objects/Turret.cc

    r10031 r10039  
    4444    {
    4545        RegisterObject(Turret);
    46         this->startOrient_ = Quaternion::IDENTITY;
    47         this->startDir_ = Vector3::ZERO;
    48         this->localZ_ = Vector3::UNIT_Z;
    49         this->localY_ = Vector3::UNIT_Y;
    50         this->localX_ = Vector3::UNIT_X;
    51         this->maxPitch_ = 0;
    52         this->maxYaw_ = 0;
    53         this->attackRadius_ = 200;
    54         this->gotOrient_ = false;
    5546        this->rotationThrust_ = 50;
    5647
     
    110101    }
    111102
    112     bool Turret::isInRange(Vector3 position)
    113     {
    114         Vector3 distance = position - this->getPosition();
    115         if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
    116         {
    117             return false;
    118         }
    119 
    120         Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
    121         Vector3 dirProjected = dir;
    122         dirProjected.x = 0;
    123         Vector3 startDirProjected = this->startDir_;
    124         startDirProjected.x = 0;
    125         Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
    126         if(angle > this->maxPitch_)
    127         {
    128             return false;
    129         }
    130 
    131         dirProjected = dir;
    132         dirProjected.y = 0;
    133         startDirProjected = this->startDir_;
    134         startDirProjected.y = 0;
    135         angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
    136         if(angle > this->maxYaw_)
    137         {
    138             return false;
    139         }
    140         return true;
    141     }
    142 
    143103    void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    144104    {
    145         XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
    146         XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
    147         XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
    148105        SUPER(Turret, XMLPort, xmlelement, mode);
    149106    }
     
    153110        SUPER(Turret, tick, dt);
    154111
    155         if(!gotOrient_)
    156         {
    157             this->startOrient_ = this->getOrientation();
    158             this->localX_ = this->startOrient_ * this->localX_;
    159             this->localX_.normalise();
    160             this->localY_ = this->startOrient_ * this->localY_;
    161             this->localY_.normalise();
    162             this->localZ_ = this->startOrient_ * this->localZ_;
    163             this->localZ_.normalise();
     112        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     113        this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
    164114
    165             //startDir should always be (0,0,-1)
    166             this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
    167115
    168             this->gotOrient_ = true;
    169         }
     116        pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
     117        yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
     118        roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
    170119
    171         this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    172         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    173120        this->localAngularAcceleration_.setValue(0, 0, 0);
    174121    }
    175 
    176122}
Note: See TracChangeset for help on using the changeset viewer.