Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2453


Ignore:
Timestamp:
Dec 14, 2008, 10:55:04 PM (16 years ago)
Author:
rgrieder
Message:

SpaceShip is now harmonising with Bullet as well. The attributes of the steering can be configured in the XML file. I recommend a very high angularDamping or otherwise it will get very tricky to steer the ship (however more realistic).

Location:
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns
Files:
2 edited

Legend:

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

    r2442 r2453  
    4747        RegisterObject(SpaceShip);
    4848
    49         this->zeroDegree_ = 0;
     49        this->primaryThrust_  = 100;
     50        this->auxilaryThrust_ =  30;
     51        this->rotationThrust_ =  10;
    5052
    51         this->maxSpeed_ = 0;
    52         this->maxSecondarySpeed_ = 0;
    53         this->maxRotation_ = 0;
    54         this->translationAcceleration_ = 0;
    55         this->rotationAcceleration_ = 0;
    56         this->translationDamping_ = 0;
    57 
    58         this->yawRotation_ = 0;
    59         this->pitchRotation_ = 0;
    60         this->rollRotation_ = 0;
     53        this->localLinearAcceleration_.setValue(0, 0, 0);
     54        this->localAngularAcceleration_.setValue(0, 0, 0);
    6155
    6256        this->bInvertYAxis_ = false;
    6357
    6458        this->setDestroyWhenPlayerLeft(true);
     59
     60        // SpaceShip is always a physical object per default
     61        // Be aware of this call: The collision type legality check will not reach derived classes!
     62        this->setCollisionType(WorldEntity::Dynamic);
    6563
    6664        this->setConfigValues();
     
    7674        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    7775
    78         XMLPortParam(SpaceShip, "maxspeed",          setMaxSpeed,          getMaxSpeed,          xmlelement, mode);
    79         XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode);
    80         XMLPortParam(SpaceShip, "maxrotation",       setMaxRotation,       getMaxRotation,       xmlelement, mode);
    81         XMLPortParam(SpaceShip, "transacc",          setTransAcc,          getTransAcc,          xmlelement, mode);
    82         XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
    83         XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
    84 
    85         if (this->physicalBody_)
    86         {
    87             this->physicalBody_->setDamping(0.7, 0.3);
    88         }
     76        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
     77        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     78        XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
    8979    }
    9080
    9181    void SpaceShip::registerVariables()
    9282    {
    93         registerVariable(this->maxSpeed_,                variableDirection::toclient);
    94         registerVariable(this->maxSecondarySpeed_,       variableDirection::toclient);
    95         registerVariable(this->maxRotation_,             variableDirection::toclient);
    96         registerVariable(this->translationAcceleration_, variableDirection::toclient);
    97         registerVariable(this->rotationAcceleration_,    variableDirection::toclient);
    98         registerVariable(this->translationDamping_,      variableDirection::toclient);
     83        registerVariable(this->primaryThrust_,  variableDirection::toclient);
     84        registerVariable(this->auxilaryThrust_, variableDirection::toclient);
     85        registerVariable(this->rotationThrust_, variableDirection::toclient);
    9986    }
    10087
     
    10491    }
    10592
     93    bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const
     94    {
     95        if (type != WorldEntity::Dynamic)
     96        {
     97            ThrowException(PhysicsViolation, "Cannot tell a SpaceShip not to be dynamic!");
     98            return false;
     99        }
     100        else
     101            return true;
     102    }
     103
    106104    void SpaceShip::tick(float dt)
    107105    {
    108106        SUPER(SpaceShip, tick, dt);
     107
     108        if (this->isLocallyControlled())
     109        {
     110            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     111            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
     112            if (this->localLinearAcceleration_.z() > 0)
     113                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
     114            else
     115                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
     116            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
     117            this->localLinearAcceleration_.setValue(0, 0, 0);
     118
     119            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     120            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
     121            this->localAngularAcceleration_.setValue(0, 0, 0);
     122        }
    109123    }
    110124
    111125    void SpaceShip::moveFrontBack(const Vector2& value)
    112126    {
    113         assert(this->physicalBody_);
    114         this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100));
     127        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    115128    }
    116129
    117130    void SpaceShip::moveRightLeft(const Vector2& value)
    118131    {
    119         this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f));
     132        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    120133    }
    121134
    122135    void SpaceShip::moveUpDown(const Vector2& value)
    123136    {
    124         this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f));
     137        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    125138    }
    126139
    127140    void SpaceShip::rotateYaw(const Vector2& value)
    128141    {
    129         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f));
     142        this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    130143    }
    131144
    132145    void SpaceShip::rotatePitch(const Vector2& value)
    133146    {
    134         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f));
     147        this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    135148    }
    136149
    137150    void SpaceShip::rotateRoll(const Vector2& value)
    138151    {
    139         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain));
     152        this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    140153    }
    141154
  • code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2087 r2453  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include "LinearMath/btVector3.h"
     35
    3436#include "Pawn.h"
    3537
     
    5759            virtual void fire();
    5860
    59             void setMaxSpeed(float value)
    60                 { this->maxSpeed_ = value; }
    61             void setMaxSecondarySpeed(float value)
    62                 { this->maxSecondarySpeed_ = value; }
    63             void setMaxRotation(const Degree& value)
    64                 { this->maxRotation_ = value; }
    65             void setTransAcc(float value)
    66                 { this->translationAcceleration_ = value; }
    67             void setRotAcc(const Degree& value)
    68                 { this->rotationAcceleration_ = value; }
    69             void setTransDamp(float value)
    70                 { this->translationDamping_ = value; }
    71 
    72             inline float getMaxSpeed() const
    73                 { return this->maxSpeed_; }
    74             inline float getMaxSecondarySpeed() const
    75                 { return this->maxSecondarySpeed_; }
    76             inline float getMaxRotation() const
    77                 { return this->maxRotation_.valueDegrees(); }
    78             inline float getTransAcc() const
    79                 { return this->translationAcceleration_; }
    80             inline float getRotAcc() const
    81                 { return this->rotationAcceleration_.valueDegrees(); }
    82             inline float getTransDamp() const
    83                 { return this->translationDamping_; }
    84 
    8561        protected:
    8662            bool bInvertYAxis_;
    8763
    88             float maxSpeed_;
    89             float maxSecondarySpeed_;
    90             float translationAcceleration_;
    91             float translationDamping_;
     64            float primaryThrust_;
     65            float auxilaryThrust_;
     66            float rotationThrust_;
    9267
    93             Degree maxRotation_;
    94             Degree rotationAcceleration_;
     68            btVector3 localLinearAcceleration_;
     69            btVector3 localAngularAcceleration_;
    9570
    96             Degree zeroDegree_;
    97             Degree pitchRotation_;
    98             Degree yawRotation_;
    99             Degree rollRotation_;
     71        private:
     72            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    10073    };
    10174}
Note: See TracChangeset for help on using the changeset viewer.