Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 3, 2008, 1:18:14 AM (16 years ago)
Author:
rgrieder
Message:

Temporary solution to steer our SpaceShip: Unlike before (exponential damping), but you can still fly around.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2303 r2314  
    8181        XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
    8282        XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
     83
     84        if (this->physicalBody_)
     85        {
     86            this->physicalBody_->setDamping(0.8, 0.9);
     87            this->physicalBody_->setActivationState(DISABLE_DEACTIVATION);
     88        }
    8389    }
    8490
     
    106112            // #####################################
    107113
    108             Vector3 velocity = this->getVelocity();
    109             if (velocity.x > this->maxSecondarySpeed_)
    110                 velocity.x = this->maxSecondarySpeed_;
    111             if (velocity.x < -this->maxSecondarySpeed_)
    112                 velocity.x = -this->maxSecondarySpeed_;
    113             if (velocity.y > this->maxSecondarySpeed_)
    114                 velocity.y = this->maxSecondarySpeed_;
    115             if (velocity.y < -this->maxSecondarySpeed_)
    116                 velocity.y = -this->maxSecondarySpeed_;
    117             if (velocity.z > this->maxSecondarySpeed_)
    118                 velocity.z = this->maxSecondarySpeed_;
    119             if (velocity.z < -this->maxSpeed_)
    120                 velocity.z = -this->maxSpeed_;
     114            //Vector3 velocity = this->getVelocity();
     115            //if (velocity.x > this->maxSecondarySpeed_)
     116            //    velocity.x = this->maxSecondarySpeed_;
     117            //if (velocity.x < -this->maxSecondarySpeed_)
     118            //    velocity.x = -this->maxSecondarySpeed_;
     119            //if (velocity.y > this->maxSecondarySpeed_)
     120            //    velocity.y = this->maxSecondarySpeed_;
     121            //if (velocity.y < -this->maxSecondarySpeed_)
     122            //    velocity.y = -this->maxSecondarySpeed_;
     123            //if (velocity.z > this->maxSecondarySpeed_)
     124            //    velocity.z = this->maxSecondarySpeed_;
     125            //if (velocity.z < -this->maxSpeed_)
     126            //    velocity.z = -this->maxSpeed_;
    121127
    122128            // normalize velocity and acceleration
    123             for (size_t dimension = 0; dimension < 3; ++dimension)
    124             {
    125                 if (this->acceleration_[dimension] == 0)
    126                 {
    127                     if (velocity[dimension] > 0)
    128                     {
    129                         velocity[dimension] -= (this->translationDamping_ * dt);
    130                         if (velocity[dimension] < 0)
    131                             velocity[dimension] = 0;
    132                     }
    133                     else if (velocity[dimension] < 0)
    134                     {
    135                         velocity[dimension] += (this->translationDamping_ * dt);
    136                         if (velocity[dimension] > 0)
    137                             velocity[dimension] = 0;
    138                     }
    139                 }
    140             }
    141 
    142             this->setVelocity(velocity);
     129            //for (size_t dimension = 0; dimension < 3; ++dimension)
     130            //{
     131            //    if (this->acceleration_[dimension] == 0)
     132            //    {
     133            //        if (velocity[dimension] > 0)
     134            //        {
     135            //            velocity[dimension] -= (this->translationDamping_ * dt);
     136            //            if (velocity[dimension] < 0)
     137            //                velocity[dimension] = 0;
     138            //        }
     139            //        else if (velocity[dimension] < 0)
     140            //        {
     141            //            velocity[dimension] += (this->translationDamping_ * dt);
     142            //            if (velocity[dimension] > 0)
     143            //                velocity[dimension] = 0;
     144            //        }
     145            //    }
     146            //}
     147
     148            //this->setVelocity(velocity);
    143149        }
    144150
     
    147153
    148154
    149         if (this->isLocallyControlled())
    150         {
    151             this->yaw(this->yawRotation_ * dt);
    152             if (this->bInvertYAxis_)
    153                 this->pitch(Degree(-this->pitchRotation_ * dt));
    154             else
    155                 this->pitch(Degree( this->pitchRotation_ * dt));
    156             this->roll(this->rollRotation_ * dt);
    157 
    158             this->acceleration_.x = 0;
    159             this->acceleration_.y = 0;
    160             this->acceleration_.z = 0;
    161 
    162             this->yawRotation_   = this->zeroDegree_;
    163             this->pitchRotation_ = this->zeroDegree_;
    164             this->rollRotation_  = this->zeroDegree_;
    165         }
     155        //if (this->isLocallyControlled())
     156        //{
     157        //    this->yaw(this->yawRotation_ * dt);
     158        //    if (this->bInvertYAxis_)
     159        //        this->pitch(Degree(-this->pitchRotation_ * dt));
     160        //    else
     161        //        this->pitch(Degree( this->pitchRotation_ * dt));
     162        //    this->roll(this->rollRotation_ * dt);
     163
     164        //    this->acceleration_.x = 0;
     165        //    this->acceleration_.y = 0;
     166        //    this->acceleration_.z = 0;
     167
     168        //    this->yawRotation_   = this->zeroDegree_;
     169        //    this->pitchRotation_ = this->zeroDegree_;
     170        //    this->rollRotation_  = this->zeroDegree_;
     171        //}
    166172    }
    167173
     
    169175    {
    170176        assert(this->physicalBody_);
    171         this->physicalBody_->applyCentralForce(btVector3(0.0f, 0.0f, -1.0f/this->physicalBody_->getInvMass() * value.x));
     177        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100));
    172178//        this->acceleration_.z = -this->translationAcceleration_ * value.x;
    173179    }
     
    175181    void SpaceShip::moveRightLeft(const Vector2& value)
    176182    {
    177         this->physicalBody_->applyCentralForce(btVector3(1.0f/this->physicalBody_->getInvMass() * value.x, 0.0f, 0.0f));
     183        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f));
    178184//        this->acceleration_.x = this->translationAcceleration_ * value.x;
    179185    }
     
    181187    void SpaceShip::moveUpDown(const Vector2& value)
    182188    {
    183         this->physicalBody_->applyCentralForce(btVector3(0.0f, 1.0f/this->physicalBody_->getInvMass() * value.x, 0.0f));
     189        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f));
    184190//        this->acceleration_.y = this->translationAcceleration_ * value.x;
    185191    }
     
    187193    void SpaceShip::rotateYaw(const Vector2& value)
    188194    {
    189         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    190         if (temp > this->maxRotation_)
    191             temp = this->maxRotation_;
    192         if (temp < -this->maxRotation_)
    193             temp = -this->maxRotation_;
    194         this->yawRotation_ = Degree(temp);
     195        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 10000, 0.0f));
     196        //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
     197        //if (temp > this->maxRotation_)
     198        //    temp = this->maxRotation_;
     199        //if (temp < -this->maxRotation_)
     200        //    temp = -this->maxRotation_;
     201        //this->yawRotation_ = Degree(temp);
    195202    }
    196203
    197204    void SpaceShip::rotatePitch(const Vector2& value)
    198205    {
    199         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    200         if (temp > this->maxRotation_)
    201             temp = this->maxRotation_;
    202         if (temp < -this->maxRotation_)
    203             temp = -this->maxRotation_;
    204         this->pitchRotation_ = Degree(temp);
     206        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 10000, 0.0f, 0.0f));
     207        //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
     208        //if (temp > this->maxRotation_)
     209        //    temp = this->maxRotation_;
     210        //if (temp < -this->maxRotation_)
     211        //    temp = -this->maxRotation_;
     212        //this->pitchRotation_ = Degree(temp);
    205213    }
    206214
    207215    void SpaceShip::rotateRoll(const Vector2& value)
    208216    {
    209         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    210         if (temp > this->maxRotation_)
    211             temp = this->maxRotation_;
    212         if (temp < -this->maxRotation_)
    213             temp = -this->maxRotation_;
    214         this->rollRotation_ = Degree(temp);
     217        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 10000));
     218        //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
     219        //if (temp > this->maxRotation_)
     220        //    temp = this->maxRotation_;
     221        //if (temp < -this->maxRotation_)
     222        //    temp = -this->maxRotation_;
     223        //this->rollRotation_ = Degree(temp);
    215224    }
    216225
Note: See TracChangeset for help on using the changeset viewer.