Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 15, 2008, 12:53:05 AM (16 years ago)
Author:
rgrieder
Message:

Merged physics_merge back to presentation branch.

Location:
code/branches/presentation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2371 r2459  
    3030#include "SpaceShip.h"
    3131
     32#include "BulletDynamics/Dynamics/btRigidBody.h"
     33
     34#include "util/Math.h"
     35#include "util/Exception.h"
    3236#include "core/CoreIncludes.h"
    3337#include "core/ConfigValueIncludes.h"
    3438#include "core/XMLPort.h"
    35 #include "util/Math.h"
    3639
    3740namespace orxonox
    3841{
     42    const float orientationGain = 100;
    3943    CreateFactory(SpaceShip);
    4044
     
    4347        RegisterObject(SpaceShip);
    4448
    45         this->zeroDegree_ = 0;
     49        this->primaryThrust_  = 100;
     50        this->auxilaryThrust_ =  30;
     51        this->rotationThrust_ =  10;
    4652
    47         this->maxSpeed_ = 0;
    48         this->maxSecondarySpeed_ = 0;
    49         this->maxRotation_ = 0;
    50         this->translationAcceleration_ = 0;
    51         this->rotationAcceleration_ = 0;
    52         this->translationDamping_ = 0;
    53 
    54         this->yawRotation_ = 0;
    55         this->pitchRotation_ = 0;
    56         this->rollRotation_ = 0;
     53        this->localLinearAcceleration_.setValue(0, 0, 0);
     54        this->localAngularAcceleration_.setValue(0, 0, 0);
    5755
    5856        this->bInvertYAxis_ = false;
    5957
    6058        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);
    6163
    6264        this->setConfigValues();
     
    7274        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    7375
    74         XMLPortParam(SpaceShip, "maxspeed",          setMaxSpeed,          getMaxSpeed,          xmlelement, mode);
    75         XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode);
    76         XMLPortParam(SpaceShip, "maxrotation",       setMaxRotation,       getMaxRotation,       xmlelement, mode);
    77         XMLPortParam(SpaceShip, "transacc",          setTransAcc,          getTransAcc,          xmlelement, mode);
    78         XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
    79         XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
     76        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
     77        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     78        XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
    8079    }
    8180
    8281    void SpaceShip::registerVariables()
    8382    {
    84         registerVariable(this->maxSpeed_,                variableDirection::toclient);
    85         registerVariable(this->maxSecondarySpeed_,       variableDirection::toclient);
    86         registerVariable(this->maxRotation_,             variableDirection::toclient);
    87         registerVariable(this->translationAcceleration_, variableDirection::toclient);
    88         registerVariable(this->rotationAcceleration_,    variableDirection::toclient);
    89         registerVariable(this->translationDamping_,      variableDirection::toclient);
     83        registerVariable(this->primaryThrust_,  variableDirection::toclient);
     84        registerVariable(this->auxilaryThrust_, variableDirection::toclient);
     85        registerVariable(this->rotationThrust_, variableDirection::toclient);
    9086    }
    9187
     
    9591    }
    9692
     93    bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const
     94    {
     95        if (type != WorldEntity::Dynamic)
     96        {
     97            CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl;
     98            assert(false); // Only in debug mode
     99            return false;
     100        }
     101        else
     102            return true;
     103    }
     104
    97105    void SpaceShip::tick(float dt)
    98106    {
    99         if (this->isLocallyControlled())
    100         {
    101             // #####################################
    102             // ############# STEERING ##############
    103             // #####################################
    104 
    105             Vector3 velocity = this->getVelocity();
    106             if (velocity.x > this->maxSecondarySpeed_)
    107                 velocity.x = this->maxSecondarySpeed_;
    108             if (velocity.x < -this->maxSecondarySpeed_)
    109                 velocity.x = -this->maxSecondarySpeed_;
    110             if (velocity.y > this->maxSecondarySpeed_)
    111                 velocity.y = this->maxSecondarySpeed_;
    112             if (velocity.y < -this->maxSecondarySpeed_)
    113                 velocity.y = -this->maxSecondarySpeed_;
    114             if (velocity.z > this->maxSecondarySpeed_)
    115                 velocity.z = this->maxSecondarySpeed_;
    116             if (velocity.z < -this->maxSpeed_)
    117                 velocity.z = -this->maxSpeed_;
    118 
    119             // normalize velocity and acceleration
    120             for (size_t dimension = 0; dimension < 3; ++dimension)
    121             {
    122                 if (this->acceleration_[dimension] == 0)
    123                 {
    124                     if (velocity[dimension] > 0)
    125                     {
    126                         velocity[dimension] -= (this->translationDamping_ * dt);
    127                         if (velocity[dimension] < 0)
    128                             velocity[dimension] = 0;
    129                     }
    130                     else if (velocity[dimension] < 0)
    131                     {
    132                         velocity[dimension] += (this->translationDamping_ * dt);
    133                         if (velocity[dimension] > 0)
    134                             velocity[dimension] = 0;
    135                     }
    136                 }
    137             }
    138 
    139             this->setVelocity(velocity);
    140         }
    141 
    142 
    143107        SUPER(SpaceShip, tick, dt);
    144 
    145108
    146109        if (this->isLocallyControlled())
    147110        {
    148             this->yaw(this->yawRotation_ * dt);
    149             if (this->bInvertYAxis_)
    150                 this->pitch(Degree(-this->pitchRotation_ * dt));
     111            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     112            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
     113            if (this->localLinearAcceleration_.z() > 0)
     114                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    151115            else
    152                 this->pitch(Degree( this->pitchRotation_ * dt));
    153             this->roll(this->rollRotation_ * dt);
     116                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
     117            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
     118            this->localLinearAcceleration_.setValue(0, 0, 0);
    154119
    155             this->acceleration_.x = 0;
    156             this->acceleration_.y = 0;
    157             this->acceleration_.z = 0;
    158 
    159             this->yawRotation_   = this->zeroDegree_;
    160             this->pitchRotation_ = this->zeroDegree_;
    161             this->rollRotation_  = this->zeroDegree_;
     120            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     121            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
     122            this->localAngularAcceleration_.setValue(0, 0, 0);
    162123        }
    163124    }
     
    165126    void SpaceShip::moveFrontBack(const Vector2& value)
    166127    {
    167         this->acceleration_.z = -this->translationAcceleration_ * value.x;
     128        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    168129    }
    169130
    170131    void SpaceShip::moveRightLeft(const Vector2& value)
    171132    {
    172         this->acceleration_.x = this->translationAcceleration_ * value.x;
     133        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    173134    }
    174135
    175136    void SpaceShip::moveUpDown(const Vector2& value)
    176137    {
    177         this->acceleration_.y = this->translationAcceleration_ * value.x;
     138        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    178139    }
    179140
    180141    void SpaceShip::rotateYaw(const Vector2& value)
    181142    {
    182         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    183         if (temp > this->maxRotation_)
    184             temp = this->maxRotation_;
    185         if (temp < -this->maxRotation_)
    186             temp = -this->maxRotation_;
    187         this->yawRotation_ = Degree(temp);
     143        this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    188144    }
    189145
    190146    void SpaceShip::rotatePitch(const Vector2& value)
    191147    {
    192         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    193         if (temp > this->maxRotation_)
    194             temp = this->maxRotation_;
    195         if (temp < -this->maxRotation_)
    196             temp = -this->maxRotation_;
    197         this->pitchRotation_ = Degree(temp);
     148        this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    198149    }
    199150
    200151    void SpaceShip::rotateRoll(const Vector2& value)
    201152    {
    202         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    203         if (temp > this->maxRotation_)
    204             temp = this->maxRotation_;
    205         if (temp < -this->maxRotation_)
    206             temp = -this->maxRotation_;
    207         this->rollRotation_ = Degree(temp);
     153        this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    208154    }
    209155
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2087 r2459  
    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}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2371 r2459  
    2929#include "OrxonoxStableHeaders.h"
    3030#include "Spectator.h"
     31
     32#include <OgreBillboardSet.h>
    3133
    3234#include "core/CoreIncludes.h"
     
    5052
    5153        this->speed_ = 100;
    52         this->rotationSpeed_ = 3;
     54        this->rotationGain_ = 3;
    5355
    5456        this->yaw_ = 0;
    5557        this->pitch_ = 0;
    5658        this->roll_ = 0;
     59        this->localVelocity_ = Vector3::ZERO;
    5760        this->setHudTemplate("spectatorhud");
    5861        this->hudmode_ = 0;
     
    6366        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
    6467        if (this->greetingFlare_->getBillboardSet())
    65             this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
     68            this->attachOgreObject(this->greetingFlare_->getBillboardSet());
    6669        this->greetingFlare_->setVisible(false);
    6770        this->bGreetingFlareVisible_ = false;
     
    7881            {
    7982                if (this->greetingFlare_->getBillboardSet())
    80                     this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
     83                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
    8184                delete this->greetingFlare_;
    8285            }
     
    108111        if (this->isLocallyControlled())
    109112        {
    110             Vector3 velocity = this->getVelocity();
    111             velocity.normalise();
    112             this->setVelocity(velocity * this->speed_);
    113 
    114             this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
    115             this->pitch(Radian(this->pitch_ * this->rotationSpeed_));
    116             this->roll(Radian(this->roll_ * this->rotationSpeed_));
     113            float localSpeedSquared = this->localVelocity_.squaredLength();
     114            float localSpeed;
     115            if (localSpeedSquared > 1.0)
     116                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
     117            else
     118                localSpeed = this->speed_;
     119
     120            this->localVelocity_.x *= localSpeed;
     121            this->localVelocity_.y *= localSpeed;
     122            this->localVelocity_.z *= localSpeed;
     123            this->setVelocity(this->getOrientation() * this->localVelocity_);
     124            this->localVelocity_.x = 0;
     125            this->localVelocity_.y = 0;
     126            this->localVelocity_.z = 0;
     127
     128            this->yaw  (Radian(this->yaw_   * this->rotationGain_));
     129            this->pitch(Radian(this->pitch_ * this->rotationGain_));
     130            this->roll (Radian(this->roll_  * this->rotationGain_));
    117131
    118132            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    120134
    121135        SUPER(Spectator, tick, dt);
    122 
    123         if (this->isLocallyControlled())
    124         {
    125             this->setVelocity(Vector3::ZERO);
    126         }
    127136    }
    128137
     
    143152    void Spectator::moveFrontBack(const Vector2& value)
    144153    {
    145         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);
     154        this->localVelocity_.z -= value.x;
    146155    }
    147156
    148157    void Spectator::moveRightLeft(const Vector2& value)
    149158    {
    150         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);
     159        this->localVelocity_.x += value.x;
    151160    }
    152161
    153162    void Spectator::moveUpDown(const Vector2& value)
    154163    {
    155         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);
     164        this->localVelocity_.y += value.x;
    156165    }
    157166
    158167    void Spectator::rotateYaw(const Vector2& value)
    159168    {
    160         this->yaw_ = value.y;
     169        this->yaw_ += value.y;
    161170    }
    162171
    163172    void Spectator::rotatePitch(const Vector2& value)
    164173    {
    165         this->pitch_ = value.y;
     174        this->pitch_ += value.y;
    166175    }
    167176
    168177    void Spectator::rotateRoll(const Vector2& value)
    169178    {
    170         this->roll_ = value.y;
     179        this->roll_ += value.y;
    171180    }
    172181
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2087 r2459  
    6969
    7070            float speed_;
    71             float rotationSpeed_;
     71            float rotationGain_;
    7272
    7373            float yaw_;
    7474            float pitch_;
    7575            float roll_;
     76
     77            Vector3 localVelocity_;
    7678
    7779            int hudmode_;
Note: See TracChangeset for help on using the changeset viewer.