Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8727


Ignore:
Timestamp:
Jul 3, 2011, 5:42:19 PM (13 years ago)
Author:
dafrick
Message:

Cleaning up in SpaceShip and Engine. Fixed several bugs.
Kicked localLinearAcceleration, primaryThrust and auxiliaryThrust out of the SpaceShip, since it wasn't used anymore.
Moved the trail lights back a bit.
Added some documentation to SpaceShip and Engine.
SpeedPickup is working again, will need some further tuning.

Location:
code/trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/levels/templates/spaceshipAssff.oxt

    r8706 r8727  
    105105    </EffectContainer>
    106106    <EffectContainer condition="normal or boost">
    107       <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 0" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    108       <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 0" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
     107      <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
     108      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    109109    </EffectContainer>
    110110    <EffectContainer condition="boost">
  • code/trunk/data/levels/templates/spaceshipAssff2.oxt

    r8706 r8727  
    105105    </EffectContainer>
    106106    <EffectContainer condition="normal or boost">
    107       <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 0" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    108       <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 0" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
     107      <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
     108      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    109109    </EffectContainer>
    110110    <EffectContainer condition="boost">
  • code/trunk/src/modules/pickup/items/SpeedPickup.cc

    r7548 r8727  
    3838#include "core/XMLPort.h"
    3939
    40 #include "items/Engine.h"
    4140#include "pickup/PickupIdentifier.h"
    4241#include "worldentities/pawns/SpaceShip.h"
     
    7675        this->speedMultiply_ = 1.0f;
    7776
    78         this->addTarget(ClassIdentifier<Engine>::getIdentifier());
     77        this->addTarget(ClassIdentifier<SpaceShip>::getIdentifier());
    7978    }
    8079
     
    127126        SUPER(SpeedPickup, changedUsed);
    128127
    129         Engine* engine = this->carrierToEngineHelper();
    130         if(engine == NULL) // If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.
     128        SpaceShip* ship = this->carrierToSpaceShipHelper();
     129        if(ship == NULL) // If the PickupCarrier is no SpaceShip, then this pickup is useless and therefore is destroyed.
    131130            this->Pickupable::destroy();
    132131
     
    147146            }
    148147
    149             engine->setSpeedAdd(this->getSpeedAdd());
    150             engine->setSpeedMultiply(this->getSpeedMultiply());
    151         }
    152         else
    153         {
    154             engine->setSpeedAdd(0.0f);
    155             engine->setSpeedMultiply(1.0f);
     148            ship->addSpeed(this->getSpeedAdd());
     149            ship->addSpeedFactor(this->getSpeedMultiply());
     150        }
     151        else
     152        {
     153            ship->addSpeed(-this->getSpeedAdd());
     154            ship->addSpeedFactor(1.0f/this->getSpeedMultiply());
    156155
    157156            // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded.
     
    170169    /**
    171170    @brief
    172         Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     171        Helper to transform the PickupCarrier to a SpaceShip, and throw an error message if the conversion fails.
    173172    @return
    174         A pointer to the Pawn, or NULL if the conversion failed.
    175     */
    176     Engine* SpeedPickup::carrierToEngineHelper(void)
     173        A pointer to the SpaceShip, or NULL if the conversion failed.
     174    */
     175    SpaceShip* SpeedPickup::carrierToSpaceShipHelper(void)
    177176    {
    178177        PickupCarrier* carrier = this->getCarrier();
    179         Engine* engine = dynamic_cast<Engine*>(carrier);
    180 
    181         if(engine == NULL)
     178        SpaceShip* ship = dynamic_cast<SpaceShip*>(carrier);
     179
     180        if(ship == NULL)
    182181        {
    183182            COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl;
    184183        }
    185184
    186         return engine;
     185        return ship;
    187186    }
    188187
  • code/trunk/src/modules/pickup/items/SpeedPickup.h

    r7547 r8727  
    112112        private:
    113113            void initialize(void); //!< Initializes the member variables.
    114             Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     114            SpaceShip* carrierToSpaceShipHelper(void); //!< Helper to transform the PickupCarrier to a SpaceSHip, and throw an error message if the conversion fails.
    115115
    116116            Timer durationTimer_; //!< Timer.
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.cc

    r8706 r8727  
    151151                //Give new pig boost
    152152                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
    153                 grantPigBoost(spaceship);
     153                this->grantPigBoost(spaceship);
    154154            }
    155155
     
    245245                //Give new pig boost
    246246                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
    247                 grantPigBoost(spaceship);
     247                this->grantPigBoost(spaceship);
    248248            }
    249249            // killer vs piggy
     
    306306    }
    307307
    308     void Dynamicmatch::grantPigBoost(orxonox::SpaceShip* spaceship)
     308    /**
     309    @brief
     310        Grant the piggy a boost.
     311    @param spaceship
     312        The SpaceShip to give the boost.
     313    */
     314    void Dynamicmatch::grantPigBoost(SpaceShip* spaceship)
    309315    {
    310316        // Give pig boost
    311317        if (spaceship)
    312318        {
    313             spaceship->setSpeedFactor(5);
     319            spaceship->addSpeedFactor(5);
    314320            WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship);
    315321            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
     
    599605        if (*ptr)
    600606        {
    601             (*ptr)->setSpeedFactor(1.0f);
     607            (*ptr)->addSpeedFactor(1.0f/5.0f);
    602608        }
    603609        delete ptr;
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.h

    r8706 r8727  
    3030#define _Dynamicmatch_H__
    3131
     32#include "OrxonoxPrereqs.h"
     33
    3234#include <map>
    3335#include <vector>
    34 #include "OrxonoxPrereqs.h"
     36
     37#include "tools/Timer.h"
     38
    3539#include "Gametype.h"
    36 #include "tools/Timer.h"
    3740
    3841namespace orxonox
     
    7376            virtual void furtherInstructions();*/
    7477            virtual void rewardPig();
    75             void grantPigBoost(SpaceShip* spaceship); // Added this, since it's used twice on different occasions.
     78            void grantPigBoost(SpaceShip* spaceship); // Grant the piggy a boost.
    7679            void resetSpeedFactor(WeakPtr<SpaceShip>* ptr);
    7780            void tick (float dt);// used to end the game
  • code/trunk/src/orxonox/items/Engine.cc

    r8706 r8727  
    2929#include "Engine.h"
    3030
    31 #include "util/Math.h"
    3231#include "core/CoreIncludes.h"
    3332#include "core/ConfigValueIncludes.h"
     33#include "core/Template.h"
    3434#include "core/XMLPort.h"
     35#include "util/Math.h"
     36
    3537#include "Scene.h"
    3638#include "worldentities/pawns/SpaceShip.h"
    37 #include "core/Template.h"
    3839
    3940namespace orxonox
     
    4142    CreateFactory(Engine);
    4243
     44    /**
     45    @brief
     46        Constructor. Registers and initializes the object.
     47    */
    4348    Engine::Engine(BaseObject* creator) : Item(creator)
    4449    {
     
    4752        this->ship_ = 0;
    4853        this->shipID_ = OBJECTID_UNKNOWN;
    49         this->relativePosition_ = Vector3(0,0,0);
    50 
    51         this->boostFactor_ = 1.5;
    52         this->speedFactor_ = 1.0;
    53 
    54         this->maxSpeedFront_ = 0.0;
    55         this->maxSpeedBack_ = 0.0;
    56         this->maxSpeedLeftRight_ = 0.0;
    57         this->maxSpeedUpDown_ = 0.0;
    58 
    59         this->accelerationFront_ = 0.0;
    60         this->accelerationBrake_ = 0.0;
    61         this->accelerationBack_ = 0.0;
    62         this->accelerationLeftRight_ = 0.0;
    63         this->accelerationUpDown_ = 0.0;
    64 
    65         this->speedAdd_ = 0.0;
    66         this->speedMultiply_ = 1.0;
     54        this->relativePosition_ = Vector3::ZERO;
     55
     56        this->boostFactor_ = 1.5f;
     57
     58        this->maxSpeedFront_ = 0.0f;
     59        this->maxSpeedBack_ = 0.0f;
     60        this->maxSpeedLeftRight_ = 0.0f;
     61        this->maxSpeedUpDown_ = 0.0f;
     62
     63        this->accelerationFront_ = 0.0f;
     64        this->accelerationBrake_ = 0.0f;
     65        this->accelerationBack_ = 0.0f;
     66        this->accelerationLeftRight_ = 0.0f;
     67        this->accelerationUpDown_ = 0.0f;
     68
     69        this->speedAdd_ = 0.0f;
     70        this->speedMultiply_ = 1.0f;
    6771
    6872        this->setConfigValues();
     
    7074    }
    7175
     76    /**
     77    @brief
     78        Destructor. Destroys the object and removes it from the SpaceShip.
     79    */
    7280    Engine::~Engine()
    7381    {
    7482        if (this->isInitialized())
    7583        {
     84            // Remove the engine from the ShapeShip.
    7685            if (this->ship_ && this->ship_->hasEngine(this))
    7786                this->ship_->removeEngine(this);
     
    108117        registerVariable(this->shipID_, VariableDirection::ToClient, new NetworkCallback<Engine>(this, &Engine::networkcallback_shipID));
    109118
    110         registerVariable(this->speedFactor_, VariableDirection::ToClient);
    111119        registerVariable(this->boostFactor_, VariableDirection::ToClient);
    112120
     
    138146    }
    139147
    140     void Engine::tick(float dt)
    141     {
    142         if (!this->ship_)
    143         {
    144             if (this->shipID_)
     148    /**
     149    @brief
     150        Run the engine for a given time interval.
     151        Is called each tick by SpaceShip.
     152    @param dt
     153        The time since last tick.
     154    */
     155    void Engine::run(float dt)
     156    {
     157        if (this->ship_ == NULL)
     158        {
     159            if (this->shipID_ != 0)
    145160            {
    146161                this->networkcallback_shipID();
    147162
    148                 if (!this->ship_)
     163                if (this->ship_ == NULL)
    149164                    return;
    150165            }
     
    156171            return;
    157172
    158         SUPER(Engine, tick, dt);
    159 
    160         Vector3 direction = this->getDirection();
    161         float directionLength = direction.length();
    162         if (directionLength > 1.0f)
    163             direction /= directionLength; // normalize
    164        
     173        // Get the desired steering direction and amount, clipped to length 1 at maximum.
     174        Vector3 steering = (this->getSteering().length() > 1.0f ? this->getSteering().normalisedCopy() : this->getSteering());
     175
     176        // Get the ships velocity.
    165177        Vector3 velocity = this->ship_->getLocalVelocity();
    166178        Vector3 acceleration = Vector3::ZERO;
    167179
    168         float factor = 1.0f / this->speedFactor_;
    169         velocity *= factor;
    170 
    171         if (direction.z < 0)
     180        // If there is forward steering action.
     181        if (steering.z < 0)
    172182        {
    173183            if (this->maxSpeedFront_ != 0)
    174184            {
    175                 float boostfactor = (this->ship_->getBoost() ? this->boostFactor_ : 1.0f);
    176                 acceleration.z = direction.z * this->accelerationFront_ * boostfactor * clamp((this->maxSpeedFront_ - -velocity.z/boostfactor) / this->maxSpeedFront_, 0.0f, 1.0f);
     185                float boostfactor = (this->ship_->isBoosting() ? this->boostFactor_ : 1.0f); // Boost factor is 1.0 if not boosting.
     186                // Boosting can lead to velocities larger the maximal forward velocity.
     187                acceleration.z = steering.z * this->accelerationFront_ * boostfactor * clamp((this->maxSpeedFront_ - -velocity.z/boostfactor) / this->maxSpeedFront_, 0.0f, 1.0f);
    177188            }
    178189        }
    179         else if (direction.z > 0)
    180         {
     190        // If there is backward steering action.
     191        else if (steering.z > 0)
     192        {
     193            // Either breaking
    181194            if (velocity.z < 0)
    182                 acceleration.z = direction.z * this->accelerationBrake_;
     195                acceleration.z = steering.z * this->accelerationBrake_;
     196            // or backward flight.
    183197            else if (this->maxSpeedBack_ != 0)
    184                 acceleration.z = direction.z * this->accelerationBack_ * clamp((this->maxSpeedBack_ - velocity.z) / this->maxSpeedBack_, 0.0f, 1.0f);
    185         }
    186 
     198                acceleration.z = steering.z * this->accelerationBack_ * clamp((this->maxSpeedBack_ - velocity.z) / this->maxSpeedBack_, 0.0f, 1.0f);
     199        }
     200        // If there is left-right steering action.
    187201        if (this->maxSpeedLeftRight_ != 0)
    188202        {
    189             if (direction.x < 0)
    190                 acceleration.x = direction.x * this->accelerationLeftRight_ * clamp((this->maxSpeedLeftRight_ - -velocity.x) / this->maxSpeedLeftRight_, 0.0f, 1.0f);
    191             else if (direction.x > 0)
    192                 acceleration.x = direction.x * this->accelerationLeftRight_ * clamp((this->maxSpeedLeftRight_ - velocity.x) / this->maxSpeedLeftRight_, 0.0f, 1.0f);
    193         }
    194 
     203            if (steering.x < 0)
     204                acceleration.x = steering.x * this->accelerationLeftRight_ * clamp((this->maxSpeedLeftRight_ - -velocity.x) / this->maxSpeedLeftRight_, 0.0f, 1.0f);
     205            else if (steering.x > 0)
     206                acceleration.x = steering.x * this->accelerationLeftRight_ * clamp((this->maxSpeedLeftRight_ - velocity.x) / this->maxSpeedLeftRight_, 0.0f, 1.0f);
     207        }
     208        // If there is up-down steering action.
    195209        if (this->maxSpeedUpDown_ != 0)
    196210        {
    197             if (direction.y < 0)
    198                 acceleration.y = direction.y * this->accelerationUpDown_ * clamp((this->maxSpeedUpDown_ - -velocity.y) / this->maxSpeedUpDown_, 0.0f, 1.0f);
    199             else if (direction.y > 0)
    200                 acceleration.y = direction.y * this->accelerationUpDown_ * clamp((this->maxSpeedUpDown_ - velocity.y) / this->maxSpeedUpDown_, 0.0f, 1.0f);
     211            if (steering.y < 0)
     212                acceleration.y = steering.y * this->accelerationUpDown_ * clamp((this->maxSpeedUpDown_ - -velocity.y) / this->maxSpeedUpDown_, 0.0f, 1.0f);
     213            else if (steering.y > 0)
     214                acceleration.y = steering.y * this->accelerationUpDown_ * clamp((this->maxSpeedUpDown_ - velocity.y) / this->maxSpeedUpDown_, 0.0f, 1.0f);
    201215        }
    202216
    203217        // NOTE: Bullet always uses global coordinates.
    204218        this->ship_->addAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())), this->ship_->getOrientation() * this->relativePosition_);
    205 
    206         // Hack to reset a temporary variable "direction"
    207         this->ship_->oneEngineTickDone();
    208         if(!this->ship_->hasEngineTicksRemaining())
    209         {
    210             this->ship_->setSteeringDirection(Vector3::ZERO);
    211             this->ship_->resetEngineTicks();
    212         }
    213     }
    214 
    215     void Engine::changedActivity()
    216     {
    217         SUPER(Engine, changedActivity);
    218     }
    219 
     219    }
     220
     221    /**
     222    @brief
     223        Adds the Engine to the input SpaceShip.
     224    @param ship
     225        A pointer to the SpaceShip to which the engine is added.
     226    */
    220227    void Engine::addToSpaceShip(SpaceShip* ship)
    221228    {
     
    230237    }
    231238
    232     const Vector3& Engine::getDirection() const
     239    /**
     240    @brief
     241        Get the direction and magnitude of the steering imposed upon the Engine.
     242    @return
     243        Returns the direction and magnitude of the steering imposed upon the Engine.
     244        Is the zero vector if the Engine doesn't belong to a ship.
     245    */
     246    const Vector3& Engine::getSteering() const
    233247    {
    234248        if (this->ship_)
     
    238252    }
    239253
    240     PickupCarrier* Engine::getCarrierParent(void) const
    241     {
    242         return this->ship_;
    243     }
    244 
    245     const Vector3& Engine::getCarrierPosition(void) const
    246     {
    247         return this->ship_->getWorldPosition();
    248     }
    249 
     254    /**
     255    @brief
     256        Load the engine template.
     257        Causes all parameters specified by the template to be applied to the Engine.
     258    */
    250259    void Engine::loadEngineTemplate()
    251260    {
     
    260269        }
    261270    }
     271
    262272}
  • code/trunk/src/orxonox/items/Engine.h

    r8706 r8727  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "tools/interfaces/Tickable.h"
     34#include "util/OrxAssert.h"
     35
    3536#include "Item.h"
    36 
    37 #include "interfaces/PickupCarrier.h"
    3837
    3938namespace orxonox
    4039{
    41     class _OrxonoxExport Engine : public Item, public Tickable, public PickupCarrier
     40
     41    /**
     42    @brief
     43        The Engine class provides propulsion to the SpaceShip.
     44       
     45        There are many parameters that can be specified:
     46        - The <b>relativePosition</b>, specifies the position relative to the center of the SpaceShip the Engine is mounted on.
     47        - The <b>maximal speed</b>, there are four maximal speeds that can be specified: The <b>speedfront</b>, the maximal forward speed. The <b>speedback>, the maximal backward speed. The <b>speedleftright</b>, the maximal speed in y-direction of the SpaceShip coordinate frame. The <b>speedupdown</b>, the maximal speed in z-direction of the SpaceShip coordinate frame. All maximal speeds (naturally) have to be non-negative.
     48        - The <b>acceleration</b>, there are five types of acceleration that can be specified: The <b>accelerationfront</b>, the forward acceleration. The <b>accelerationbrake</b>, the braking acceleration. The <b>accelerationback</b>, the backward acceleration. The <b>accelerationleftright</b>, the acceleration in y-direction. The <b>accelerationupdown</b>, the acceleration in z-direction. All accelerations have to be non-negative.
     49        - The <b>boostfactor</b>, specifies the factor by which boosting increases the speed. This has to be non-negative, as well. Beware that maximal speeds can be overcome through boosting.
     50        - The <b>template</b>, the name of the engine template. Allows for parameters of the Engine be set trough a template.
     51       
     52    @author
     53        Fabian 'x3n' Landau
     54    */
     55    class _OrxonoxExport Engine : public Item
    4256    {
    4357        public:
     
    4862            void setConfigValues();
    4963
    50             virtual void tick(float dt);
    51             virtual void changedActivity();
    52 
    53             virtual void addToSpaceShip(SpaceShip* ship);
     64            virtual void run(float dt); // Run the engine for a given time interval.
     65
     66            virtual void addToSpaceShip(SpaceShip* ship); // Adds the Engine to the input SpaceShip.
     67            /**
     68            @brief Get the SpaceShip this Engine is mounted on.
     69            @return Returns a pointer to the SpaceShip. NULL if it isn't mounted on any ship.
     70            */
    5471            inline SpaceShip* getShip() const
    5572                { return this->ship_; }
    5673
     74            /**
     75            @brief Set the relative position of the Engine.
     76            @param position The relative position with respect to the SpaceShip it is mounted on.
     77            */
    5778            inline void setRelativePosition(const Vector3 &position)
    5879                { this->relativePosition_ = position; }
    59             inline Vector3& getRelativePosition()
     80            /**
     81            @brief Get the relative position of the Engine.
     82            @return Returns the relative position with respect to the SpaceShip it is mounted on.
     83            */
     84            inline const Vector3& getRelativePosition() const
    6085                { return this->relativePosition_; }
    6186
     87            /**
     88            @brief Set the maximal forward speed of the Engine.
     89            @param speed The speed to be set. Must be non-negative.
     90            */
     91            //TODO: Better OrxVerify()?
     92            inline void setMaxSpeedFront(float speed)
     93                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedFront_ = speed; }
     94            /**
     95            @brief Set the maximal backward speed of the Engine.
     96            @param speed The speed to be set. Must be non-negative.
     97            */
     98            inline void setMaxSpeedBack(float speed)
     99                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedBack_ = speed; }
     100            /**
     101            @brief Set the maximal left-right speed of the Engine.
     102            @param speed The speed to be set. Must be non-negative.
     103            */
     104            inline void setMaxSpeedLeftRight(float speed)
     105                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedLeftRight_ = speed; }
     106            /**
     107            @brief Set the maximal up-down speed of the Engine.
     108            @param speed The speed to be set. Must be non-negative.
     109            */
     110            inline void setMaxSpeedUpDown(float speed)
     111                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedUpDown_ = speed; }
     112
     113            /**
     114            @brief Get the maximal forward speed of the Engine.
     115            @return Returns the maximal forward speed of the Engine. Is non-negative.
     116            */
     117            inline float getMaxSpeedFront() const
     118                { return this->maxSpeedFront_; }
     119            /**
     120            @brief Get the maximal backward speed of the Engine.
     121            @return Returns the maximal backward speed of the Engine. Is non-negative.
     122            */
     123            inline float getMaxSpeedBack() const
     124                { return this->maxSpeedBack_; }
     125            /**
     126            @brief Get the maximal left-right speed of the Engine.
     127            @return Returns the maximal left-right speed of the Engine. Is non-negative.
     128            */
     129            inline float getMaxSpeedLeftRight() const
     130                { return this->maxSpeedLeftRight_; }
     131            /**
     132            @brief Get the maximal up-down speed of the Engine.
     133            @return Returns the maximal up-down speed of the Engine. Is non-negative.
     134            */
     135            inline float getMaxSpeedUpDown() const
     136                { return this->maxSpeedUpDown_; }
     137
     138            /**
     139            @brief Set the forward acceleration produced by the Engine.
     140            @param acceleration The forward acceleration produced by the Engine. Must be non-negative.
     141            */
     142            inline void setAccelerationFront(float acceleration)
     143                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationFront_ = acceleration; }
     144            /**
     145            @brief Set the breaking acceleration produced by the Engine.
     146            @param acceleration The breaking acceleration produced by the engine. Must be non-negative.
     147            */
     148            inline void setAccelerationBrake(float acceleration)
     149                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationBrake_ = acceleration; }
     150            /**
     151            @brief Set the backward acceleration produced by the Engine.
     152            @param acceleration The backward acceleration produced by the Engine.
     153            */
     154            inline void setAccelerationBack(float acceleration)
     155                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationBack_ = acceleration; }
     156            /**
     157            @brief Set the left-right acceleration produced by the Engine.
     158            @param acceleration The left-right acceleration produced by the Engine.
     159            */
     160            inline void setAccelerationLeftRight(float acceleration)
     161                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationLeftRight_ = acceleration; }
     162            /**
     163            @brief Set the up-down acceleration produced by the Engine.
     164            @param acceleration The
     165            */
     166            inline void setAccelerationUpDown(float acceleration)
     167                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationUpDown_ = acceleration; }
     168
     169            /**
     170            @brief Get the forward acceleration produced by the Engine.
     171            @return Returns the forward acceleration produced by the Engine. Is non-negative.
     172            */
     173            inline float getAccelerationFront() const
     174                { return this->accelerationFront_; }
     175            /**
     176            @brief Get the breaking acceleration produced by the Engine.
     177            @return Returns the breaking acceleration produced by the Engine. Is non-negative.
     178            */
     179            inline float getAccelerationBrake() const
     180                { return this->accelerationBrake_; }
     181            /**
     182            @brief Get the backward acceleration produced by the Engine.
     183            @return Returns the backward acceleration produced by the Engine. Is non-negative.
     184            */
     185            inline float getAccelerationBack() const
     186                { return this->accelerationBack_; }
     187            /**
     188            @brief Get the left-right acceleration produced by the Engine.
     189            @return Returns the left-right acceleration produced by the Engine. Is non-negative.
     190            */
     191            inline float getAccelerationLeftRight() const
     192                { return this->accelerationLeftRight_; }
     193            /**
     194            @brief Get the up-down acceleration produced by the Engine.
     195            @return Returns the up-down acceleration produced by the Engine. Is non-negative.
     196            */
     197            inline float getAccelerationUpDown() const
     198                { return this->accelerationUpDown_; }
     199
     200            /**
     201            @brief Set the factor by which boosting increases the forward acceleration of the Engine.
     202            @param factor The boost factor. Needs to be positive.
     203            */
    62204            inline void setBoostFactor(float factor)
    63                 { this->boostFactor_ = factor; }
     205                { OrxAssert(factor > 0.0f, "The input factor must be positive."); this->boostFactor_ = factor; }
     206            /**
     207            @brief Get the boost factor of the Engine.
     208            @return Returns the factor by which boosting increases the forward acceleration of the Engine. Is positive.
     209            */
    64210            inline float getBoostFactor() const
    65211                { return this->boostFactor_; }
    66212
    67             inline void setSpeedFactor(float factor)
    68                 { this->speedFactor_ = factor; }
    69             inline float getSpeedFactor() const
    70                 { return this->speedFactor_; }
    71 
    72             inline void setMaxSpeedFront(float speed)
    73                 { this->maxSpeedFront_ = speed; }
    74             inline void setMaxSpeedBack(float speed)
    75                 { this->maxSpeedBack_ = speed; }
    76             inline void setMaxSpeedLeftRight(float speed)
    77                 { this->maxSpeedLeftRight_ = speed; }
    78             inline void setMaxSpeedUpDown(float speed)
    79                 { this->maxSpeedUpDown_ = speed; }
    80 
    81             inline float getMaxSpeedFront() const
    82                 { return this->maxSpeedFront_; }
    83             inline float getMaxSpeedBack() const
    84                 { return this->maxSpeedBack_; }
    85             inline float getMaxSpeedLeftRight() const
    86                 { return this->maxSpeedLeftRight_; }
    87             inline float getMaxSpeedUpDown() const
    88                 { return this->maxSpeedUpDown_; }
    89 
    90             inline void setAccelerationFront(float acceleration)
    91                 { this->accelerationFront_ = acceleration; }
    92             inline void setAccelerationBrake(float acceleration)
    93                 { this->accelerationBrake_ = acceleration; }
    94             inline void setAccelerationBack(float acceleration)
    95                 { this->accelerationBack_ = acceleration; }
    96             inline void setAccelerationLeftRight(float acceleration)
    97                 { this->accelerationLeftRight_ = acceleration; }
    98             inline void setAccelerationUpDown(float acceleration)
    99                 { this->accelerationUpDown_ = acceleration; }
    100 
    101             inline float getAccelerationFront() const
    102                 { return this->accelerationFront_; }
    103             inline float getAccelerationBrake() const
    104                 { return this->accelerationBrake_; }
    105             inline float getAccelerationBack() const
    106                 { return this->accelerationBack_; }
    107             inline float getAccelerationLeftRight() const
    108                 { return this->accelerationLeftRight_; }
    109             inline float getAccelerationUpDown() const
    110                 { return this->accelerationUpDown_; }
    111 
     213            /**
     214            @brief Add to the additional forward speed factor.
     215            @param factor The speed that is added to the additional forward speed. Must be non-negative.
     216            */
     217            inline void addSpeedAdd(float speed)
     218                { this->speedAdd_ += speed; }
     219            /**
     220            @brief Add to the forward speed multiplication factor.
     221            @param factor The factor by which the forward speed multiplication factor is multiplied. Must be non-negative.
     222            */
     223            inline void addSpeedMultiply(float factor)
     224                { OrxAssert(factor >= 0.0f, "The factor must be non-negative."); this->speedMultiply_ *= factor; }
     225
     226            /**
     227            @brief Get the additional forward speed.
     228            @return Returns the additional forward speed.
     229            */
    112230            inline float getSpeedAdd(void)
    113231                { return this->speedAdd_; }
     232            /**
     233            @brief Get the forward speed multiplication factor.
     234            @return Returns the forward speed multiplication factor.
     235            */
    114236            inline float getSpeedMultiply(void)
    115237                { return this->speedMultiply_; }
    116238
    117             virtual const Vector3& getDirection() const;
    118 
    119             virtual const Vector3& getCarrierPosition(void) const;
    120 
    121             inline void setSpeedAdd(float speedAdd)
    122                 { this->speedAdd_=speedAdd; }
    123             inline void setSpeedMultiply(float speedMultiply)
    124                 { this->speedMultiply_=speedMultiply; }
    125 
    126            
     239            /**
     240            @brief Set the engine template, that specifies the parameters for the Engine.
     241            @param temp The name of the engine template.
     242            */
    127243            inline void setEngineTemplate(const std::string& temp)
    128244                { this->engineTemplate_ = temp; this->loadEngineTemplate(); }
     245            /**
     246            @brief Get the engine template, that specifies the parameters for the Engine.
     247            @return Returns the name of the engine template.
     248            */
    129249            inline const std::string& getEngineTemplate() const
    130250                { return this->engineTemplate_; }
    131251
    132252        protected:
    133             virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const
    134                 { return new std::vector<PickupCarrier*>(); }
    135             virtual PickupCarrier* getCarrierParent(void) const;
    136            
    137             void loadEngineTemplate();
     253            void loadEngineTemplate(); // Load the engine template.
     254
     255            virtual const Vector3& getSteering() const; // Get the steering direction imposed upon the Engine.
    138256
    139257        private:
     
    141259            void networkcallback_shipID();
    142260
    143             std::string engineTemplate_;
    144 
    145             SpaceShip* ship_;
    146             unsigned int shipID_;
    147             Vector3 relativePosition_;
    148 
    149             float boostFactor_;
    150             float speedFactor_;
    151 
    152             float speedAdd_;
    153             float speedMultiply_;
    154 
    155             float maxSpeedFront_;
    156             float maxSpeedBack_;
    157             float maxSpeedLeftRight_;
    158             float maxSpeedUpDown_;
    159 
    160             float accelerationFront_;
    161             float accelerationBrake_;
    162             float accelerationBack_;
    163             float accelerationLeftRight_;
    164             float accelerationUpDown_;
     261            std::string engineTemplate_; //!< The template that specifies the Engine's parameters.
     262
     263            SpaceShip* ship_; //!< A pointer to the SpaceShip the Engine is mounted on.
     264            unsigned int shipID_; //!< Object ID of the SpaceShip the Engine is mounted on.
     265            Vector3 relativePosition_; //!< The relative position of the Engine with respect to the SpaceShip it is mounted on.
     266
     267            float boostFactor_; //!< The factor by which boosting increases the forward acceleration.
     268
     269            float speedAdd_; //!< Additional forward speed. Is not bounded by the maximal forward speed.
     270            float speedMultiply_; //!< Forward speed multiplication factor. Is not bounded by the maximal forward speed.
     271
     272            float maxSpeedFront_; //!< The maximal forward speed.
     273            float maxSpeedBack_; //!< The maximal backward speed.
     274            float maxSpeedLeftRight_; //!< The maximal left-right speed.
     275            float maxSpeedUpDown_; //!< The maximal up-down speed.
     276
     277            float accelerationFront_; //!< Forward acceleration produced by the Engine.
     278            float accelerationBrake_; //!< Breaking acceleration produced by the Engine.
     279            float accelerationBack_; //!< Backward acceleration produced by the Engine.
     280            float accelerationLeftRight_; //!< Left-right acceleration produced by the Engine.
     281            float accelerationUpDown_; //!< Up-down acceleration produced by the Engine.
     282
    165283    };
    166284}
  • code/trunk/src/orxonox/items/MultiStateEngine.cc

    r6709 r8727  
    109109    }
    110110
    111     void MultiStateEngine::tick(float dt)
     111    void MultiStateEngine::run(float dt)
    112112    {
    113113        if (this->getShip())
     
    117117            if (this->getShip()->hasLocalController())
    118118            {
    119                 const Vector3& direction = this->getDirection();
     119                const Vector3& direction = this->getSteering();
    120120                bool forward = (direction.z < 0.0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
    121121
    122122                this->state_ = 0;
    123                 if (this->getShip()->getBoost() && forward)
     123                if (this->getShip()->isBoosting() && forward)
    124124                    this->state_ = Boost;
    125125                else if (forward && !this->state_) // this->state_ == Boost
     
    181181        }
    182182
    183         SUPER(MultiStateEngine, tick, dt);
     183        Engine::run(dt);
    184184    }
    185185
  • code/trunk/src/orxonox/items/MultiStateEngine.h

    r7163 r8727  
    5454            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5555
    56             virtual void tick(float dt);
     56            virtual void run(float dt);
    5757
    5858            virtual void addToSpaceShip(SpaceShip* ship);
  • code/trunk/src/orxonox/worldentities/MobileEntity.cc

    r8706 r8727  
    3434#include "core/CoreIncludes.h"
    3535#include "core/XMLPort.h"
     36
    3637#include "Scene.h"
    3738
     
    147148        }
    148149
    149         // If not bullet-managed (deprecated? SpaceShip doesn't use this anymore for movement)
     150        // If not bullet-managed (deprecated? SpaceShip doesn't use this anymore for movement) TODO: Find out!
    150151        this->linearAcceleration_ = acceleration;
    151152    }
    152153
     154    /**
     155    @brief
     156        Adds the input acceleration at the input position to the MobileEntity.
     157    @param acceleration
     158        The acceleration to be additionally applied to the MobileEntity.
     159    @param relativePosition
     160        The position relative to the MobileEntity at which the acceleration is applied.
     161    */
    153162    void MobileEntity::addAcceleration(const Vector3 &acceleration, const Vector3 &relativePosition)
    154163    {
  • code/trunk/src/orxonox/worldentities/MobileEntity.h

    r8706 r8727  
    5555            inline const Vector3& getVelocity() const
    5656                { return this->linearVelocity_; }
     57            /**
     58            @brief Get the velocity in the coordinate-system of the MoblieEntity.
     59            @return Returns the velocity of the MobileEntity in its coordinate-system.
     60            */
    5761            inline Vector3 getLocalVelocity() const
    5862                { return (this->getOrientation().Inverse() * this->getVelocity()); }
     
    6973            inline const Vector3& getAcceleration() const
    7074                { return this->linearAcceleration_; }
    71 
    72             // Added for making N engines work with spaceships
    73             void addAcceleration(const Vector3& acceleration, const Vector3 &relativePosition);
    74             inline void addAcceleration(float x, float y, float z)
    75                 { this->addAcceleration(Vector3(x, y, z), Vector3(0,0,0)); }
    76             // Getter function above
     75            void addAcceleration(const Vector3& acceleration, const Vector3 &relativePosition = Vector3::ZERO); // Adds the input acceleration at the input position to the MobileEntity.
    7776
    7877            void setAngularAcceleration(const Vector3& acceleration);
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r8706 r8727  
    3636#include "core/XMLPort.h"
    3737#include "tools/Shader.h"
    38 #include "util/Debug.h" // TODO: Needed?
    3938#include "util/Math.h"
    4039
     
    4746namespace orxonox
    4847{
    49     const float orientationGain = 100;
    5048    CreateFactory(SpaceShip);
    5149
     
    5452        RegisterObject(SpaceShip);
    5553
    56         this->primaryThrust_  = 100;
    57         this->auxilaryThrust_ =  30;
     54        this->bInvertYAxis_ = false;
     55
     56        this->steering_ = Vector3::ZERO;
     57
    5858        this->rotationThrust_ =  10;
    59 
    60         this->localLinearAcceleration_.setValue(0, 0, 0);
    6159        this->localAngularAcceleration_.setValue(0, 0, 0);
     60
    6261        this->bBoost_ = false;
    63         this->steering_ = Vector3::ZERO;
    64 
     62        this->bBoostCooldown_ = false;
     63        this->initialBoostPower_ = 10.0f;
    6564        this->boostPower_ = 10.0f;
    66         this->initialBoostPower_ = 10.0f;
    67         this->boostRate_ = 5.0;
    68         this->boostPowerRate_ = 1.0;
    69         this->boostCooldownDuration_ = 5.0;
    70         this->bBoostCooldown_ = false;
    71 
    72         this->lift_ = 1.0f;                         // factor of the lift, standard is 1
    73         this->stallSpeed_ = 220.0f;                 // max speed where lift is added
    74 
    75         this->bInvertYAxis_ = false;
     65        this->boostPowerRate_ = 1.0f;
     66        this->boostRate_ = 5.0f;
     67        this->boostCooldownDuration_ = 5.0f;
     68
     69        this->shakeFrequency_ = 15.0f;
     70        this->shakeAmplitude_ = 5.0f;
     71        this->shakeDt_ = 0.0f;
     72        this->cameraOriginalPosition_ = Vector3::UNIT_SCALE;
     73        this->cameraOriginalOrientation_ = Quaternion::IDENTITY;
     74
     75        this->lift_ = 1.0f;
     76        this->stallSpeed_ = 220.0f;
    7677
    7778        this->setDestroyWhenPlayerLeft(true);
     
    8384        this->enableCollisionCallback();
    8485
    85         this->engineTicksNotDone = 0;
    8686        this->setConfigValues();
    8787        this->registerVariables();
    88        
    89         this->cameraOriginalPosition_ = Vector3::UNIT_SCALE;
    90         this->cameraOriginalOrientation_ = Quaternion::IDENTITY;
    91 
    92         this->shakeFrequency_ = 15;
    93         this->shakeAmplitude_ = 5;
    94         this->shakeDt_ = 0;
     88
    9589    }
    9690
     
    10094        {
    10195            this->removeAllEngines();
    102        
     96
    10397            if (this->boostBlur_)
    10498                this->boostBlur_->destroy();
     
    110104        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    111105
    112         //XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    113         XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    114         XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
    115106        XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
    116         XMLPortParamVariable(SpaceShip, "boostPower", initialBoostPower_, xmlelement, mode);
    117         XMLPortParamVariable(SpaceShip, "boostPowerRate", boostPowerRate_, xmlelement, mode);
    118         XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    119         XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
    120         XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
    121         XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
     107        XMLPortParam(SpaceShip, "boostPower", setInitialBoostPower, getInitialBoostPower, xmlelement, mode);
     108        XMLPortParam(SpaceShip, "boostPowerRate", setBoostPowerRate, getBoostPowerRate, xmlelement, mode);
     109        XMLPortParam(SpaceShip, "boostRate", setBoostRate, getBoostRate, xmlelement, mode);
     110        XMLPortParam(SpaceShip, "boostCooldownDuration", setBoostCooldownDuration, getBoostCooldownDuration, xmlelement, mode);
     111        XMLPortParam(SpaceShip, "shakeFrequency", setShakeFrequency, getShakeFrequency, xmlelement, mode);
     112        XMLPortParam(SpaceShip, "shakeAmplitude", setShakeAmplitude, getShakeAmplitude, xmlelement, mode);
    122113        XMLPortParamVariable(SpaceShip, "lift", lift_, xmlelement, mode);
    123114        XMLPortParamVariable(SpaceShip, "stallSpeed", stallSpeed_, xmlelement, mode);
     
    128119    void SpaceShip::registerVariables()
    129120    {
    130         registerVariable(this->primaryThrust_,  VariableDirection::ToClient);
    131         registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    132121        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
    133         // TODO: Synchronization of boost needed?
    134122        registerVariable(this->boostPower_, VariableDirection::ToClient);
    135123        registerVariable(this->boostPowerRate_, VariableDirection::ToClient);
     
    169157        SUPER(SpaceShip, tick, dt);
    170158
     159        // Run the engines
     160        for(std::vector<Engine*>::iterator it = this->engineList_.begin(); it != this->engineList_.end(); it++)
     161            (*it)->run(dt);
     162
    171163        if (this->hasLocalController())
    172164        {
    173             // Handle mouse look
     165            // If not in mouse look apply the angular movement to the ship.
    174166            if (!this->isInMouseLook())
    175167            {
     
    179171            this->localAngularAcceleration_.setValue(0, 0, 0);
    180172
    181             // Charge boostPower
    182             if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_)
     173            // If not in boost cooldown, the boost power is recharged up to the initial boost power.
     174            if(!this->isBoostCoolingDown() && this->boostPower_ < this->initialBoostPower_)
    183175            {
    184176                this->boostPower_ += this->boostPowerRate_*dt;
    185177            }
    186             // Use boostPower
    187             if(this->bBoost_)
     178            // If boosting
     179            if(this->isBoosting())
    188180            {
    189                 this->boostPower_ -=this->boostRate_*dt;
     181                // Discount the used power
     182                this->boostPower_ -= this->boostRate_*dt;
     183                // If the power has been used up boosting is stopped and boost cooldown is initiated.
    190184                if(this->boostPower_ <= 0.0f)
    191185                {
     
    195189                }
    196190
     191                // Shake the camera because of the boosting.
    197192                this->shakeCamera(dt);
    198193            }
    199194
    200195            // Enable Blur depending on settings
    201             if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController())
     196            if(this->bEnableMotionBlur_)
    202197            {
    203                 this->boostBlur_ = new Shader(this->getScene()->getSceneManager());
    204                 this->boostBlur_->setCompositorName("Radial Blur");
     198                if (this->boostBlur_ == NULL && this->hasLocalController() && this->hasHumanController())
     199                {
     200                    this->boostBlur_ = new Shader(this->getScene()->getSceneManager());
     201                    this->boostBlur_->setCompositorName("Radial Blur");
     202                }
     203                if (this->boostBlur_)
     204                {
     205                    float blur = this->blurStrength_ * clamp(-this->getLocalVelocity().z/(this->getMaxSpeedFront()*this->getBoostFactor()), 0.0f, 1.0f);
     206
     207                    // Show and hide blur effect depending on state of booster
     208                    if(this->isBoosting())
     209                        this->boostBlur_->setVisible(blur > 0.0f);
     210                    else
     211                        this->boostBlur_->setVisible(false);
     212
     213                    this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
     214                }
    205215            }
    206 
    207             if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1)
    208             {
    209                 // TODO: this->maxSpeedFront_ gets fastest engine
    210                 float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f);
    211 
    212                 // Show and hide blur effect depending on state of booster
    213                 if(this->bBoost_)
    214                     this->boostBlur_->setVisible(blur > 0);
    215                 else
    216                     this->boostBlur_->setVisible(false);
    217 
    218                 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
    219             }
    220         }
    221     }
    222 
    223     void SpaceShip::moveFrontBack(const Vector2& value)
    224     {
    225         this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    226         this->steering_.z -= value.x;
    227     }
    228 
    229     void SpaceShip::moveRightLeft(const Vector2& value)
    230     {
    231         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    232         this->steering_.x += value.x;
    233     }
    234 
    235     void SpaceShip::moveUpDown(const Vector2& value)
    236     {
    237         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    238         this->steering_.y += value.x;
    239     }
    240 
     216        }
     217
     218        this->steering_ = Vector3::ZERO;
     219    }
     220
     221    /**
     222    @brief
     223        Rotate in yaw direction.
     224        Due to added lift, can also lead to an additional right-left motion.
     225    @param value
     226        A vector whose first component specifies the magnitude of the rotation. Positive means yaw left, negative means yaw right.
     227    */
    241228    void SpaceShip::rotateYaw(const Vector2& value)
    242229    {
     
    245232        Pawn::rotateYaw(value);
    246233
    247         //This function call adds a lift to the ship when it is rotating to make it's movement more "realistic" and enhance the feeling.
    248         if (abs(this-> getLocalVelocity().z) < stallSpeed_)  {this->moveRightLeft(-lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));}
    249     }
    250 
     234        // This function call adds a lift to the ship when it is rotating to make it's movement more "realistic" and enhance the feeling.
     235        if (this->getLocalVelocity().z < 0 && abs(this->getLocalVelocity().z) < stallSpeed_)
     236            this->moveRightLeft(-lift_ / 5.0f * value * sqrt(abs(this->getLocalVelocity().z)));
     237    }
     238
     239    /**
     240    @brief
     241        Rotate in pitch direction.
     242        Due to added left, can also lead to an additional up-down motion.
     243    @param value
     244        A vector whose first component specifies the magnitude of the rotation. Positive means pitch up, negative means pitch down.
     245    */
    251246    void SpaceShip::rotatePitch(const Vector2& value)
    252247    {
    253         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
    254 
    255         Pawn::rotatePitch(value);
    256 
    257         //This function call adds a lift to the ship when it is pitching to make it's movement more "realistic" and enhance the feeling.
    258         if (abs(this-> getLocalVelocity().z) < stallSpeed_)  {this->moveUpDown(lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));}
    259     }
    260 
     248        Vector2 pitch = value;
     249        if(this->bInvertYAxis_)
     250            pitch.x = -pitch.x;
     251
     252        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + pitch.x*0.8f);
     253
     254        Pawn::rotatePitch(pitch);
     255
     256        // This function call adds a lift to the ship when it is pitching to make it's movement more "realistic" and enhance the feeling.
     257        if (this->getLocalVelocity().z < 0 && abs(this->getLocalVelocity().z) < stallSpeed_)
     258            this->moveUpDown(lift_ / 5.0f * pitch * sqrt(abs(this->getLocalVelocity().z)));
     259    }
     260
     261    /**
     262    @brief
     263        Rotate in roll direction.
     264    @param value
     265        A vector whose first component specifies the magnitude of the rotation. Positive means roll left, negative means roll right.
     266    */
    261267    void SpaceShip::rotateRoll(const Vector2& value)
    262268    {
     
    278284    void SpaceShip::boost(bool bBoost)
    279285    {
    280         if(bBoost && !this->bBoostCooldown_)
     286        // Can only boost if not cooling down.
     287        if(bBoost && !this->isBoostCoolingDown())
    281288        {
    282289            this->bBoost_ = true;
    283             Camera* camera = CameraManager::getInstance().getActiveCamera();
    284             this->cameraOriginalPosition_ = camera->getPosition();
    285             this->cameraOriginalOrientation_ = camera->getOrientation();
    286         }
     290            this->backupCamera();
     291        }
     292        // Stop boosting.
    287293        if(!bBoost)
    288294        {
     
    292298    }
    293299
    294     void SpaceShip::boostCooledDown(void)
    295     {
    296         this->bBoostCooldown_ = false;
    297     }
    298    
    299     void SpaceShip::shakeCamera(float dt)
    300     {
    301         //make sure the ship is only shaking if it's moving
    302         if (this->getVelocity().squaredLength() > 80.0f)
    303         {
    304             this->shakeDt_ += dt;
    305    
    306             float frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength());
    307    
    308             if (this->shakeDt_ >= 1.0f/frequency)
    309             {
    310                 this->shakeDt_ -= 1.0f/frequency;
    311             }
    312    
    313             Degree angle = Degree(sin(this->shakeDt_ *2.0f* math::pi * frequency) * this->shakeAmplitude_);
    314    
    315             //COUT(0) << "Angle: " << angle << std::endl;
    316             Camera* camera = this->getCamera();
    317 
    318             //Shaking Camera effect
    319             if (camera != 0)
    320             {
    321                 camera->setOrientation(Vector3::UNIT_X, angle);
    322             }
    323         }
    324     }
    325 
    326     void SpaceShip::resetCamera()
    327     {
    328         Camera *camera = this->getCamera();
    329 
    330         if (camera == 0)
    331         {
    332             COUT(2) << "Failed to reset camera!";
    333             return;
    334         }
    335    
    336         this->shakeDt_ = 0;
    337         camera->setPosition(this->cameraOriginalPosition_);
    338         camera->setOrientation(this->cameraOriginalOrientation_);
    339     }
    340 
    341     void SpaceShip::backupCamera()
    342     {
    343         Camera* camera = CameraManager::getInstance().getActiveCamera();
    344         if(camera != NULL)
    345         {
    346             this->cameraOriginalPosition_ = camera->getPosition();
    347             this->cameraOriginalOrientation_ = camera->getOrientation();
    348         }
    349     }
    350 
     300        /**
     301    @brief
     302        Add an Engine to the SpaceShip.
     303    @param engine
     304        A pointer to the Engine to be added.
     305    */
    351306    void SpaceShip::addEngine(orxonox::Engine* engine)
    352307    {
    353         //COUT(0)<<"Adding an Engine: " << engine << endl;
     308        OrxAssert(engine != NULL, "The engine cannot be NULL.");
    354309        this->engineList_.push_back(engine);
    355310        engine->addToSpaceShip(this);
    356         this->resetEngineTicks();
    357     }
    358 
    359     bool SpaceShip::hasEngine(Engine* engine)
    360     {
    361         for(unsigned int i=0; i<this->engineList_.size(); i++)
    362         {
    363             if(this->engineList_[i]==engine)
     311    }
     312
     313    /**
     314    @brief
     315        Check whether the SpaceShip has a particular Engine.
     316    @param engine
     317        A pointer to the Engine to be checked.
     318    */
     319    bool SpaceShip::hasEngine(Engine* engine) const
     320    {
     321        for(unsigned int i = 0; i < this->engineList_.size(); i++)
     322        {
     323            if(this->engineList_[i] == engine)
    364324                return true;
    365325        }
     
    367327    }
    368328
     329    /**
     330    @brief
     331        Get the i-th Engine of the SpaceShip.
     332    @return
     333        Returns a pointer to the i-the Engine. NULL if there is no Engine with that index.
     334    */
    369335    Engine* SpaceShip::getEngine(unsigned int i)
    370336    {
    371         if(this->engineList_.size()>=i)
    372             return 0;
     337        if(this->engineList_.size() >= i)
     338            return NULL;
    373339        else
    374340            return this->engineList_[i];
    375341    }
    376342
     343    /**
     344    @brief
     345        Remove and destroy all Engines of the SpaceShip.
     346    */
    377347    void SpaceShip::removeAllEngines()
    378348    {
     
    380350            this->engineList_.back()->destroy();
    381351    }
    382    
     352
     353    /**
     354    @brief
     355        Remove a particular Engine from the SpaceShip.
     356    @param engine
     357        A pointer to the Engine to be removed.
     358    */
    383359    void SpaceShip::removeEngine(Engine* engine)
    384360    {
    385         for(std::vector<Engine*>::iterator it=this->engineList_.begin(); it!=this->engineList_.end(); ++it)
    386         {
    387             if(*it==engine)
     361        for(std::vector<Engine*>::iterator it = this->engineList_.begin(); it != this->engineList_.end(); ++it)
     362        {
     363            if(*it == engine)
    388364            {
    389365                this->engineList_.erase(it);
     
    393369    }
    394370
    395     void SpaceShip::setSpeedFactor(float factor)
     371    /**
     372    @brief
     373        Add to the speed factor for all engines of the SpaceShip.
     374    @param factor
     375        The factor to be added.
     376    */
     377    void SpaceShip::addSpeedFactor(float factor)
    396378    {
    397379        for(unsigned int i=0; i<this->engineList_.size(); i++)
    398             this->engineList_[i]->setSpeedFactor(factor);
    399     }
    400     float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor.
    401     {
    402         float ret = 0; unsigned int i = 0;
     380            this->engineList_[i]->addSpeedMultiply(factor);
     381    }
     382
     383    /**
     384    @brief
     385        Add to the speed factor for all engines of the SpaceShip.
     386    @param speed
     387        The speed to be added.
     388    */
     389    void SpaceShip::addSpeed(float speed)
     390    {
     391        for(unsigned int i=0; i<this->engineList_.size(); i++)
     392            this->engineList_[i]->addSpeedAdd(speed);
     393    }
     394
     395    /**
     396    @brief
     397        Get the mean speed factor over all engines of the SpaceShip.
     398    @return
     399        Returns the mean speed factor over all engines of the SpaceShip.
     400    */
     401    float SpaceShip::getSpeedFactor() const
     402    {
     403        float sum = 0;
     404        unsigned int i = 0;
    403405        for(; i<this->engineList_.size(); i++)
    404             ret += this->engineList_[i]->getSpeedFactor();
    405         ret /= (float)i;
    406         return ret;
    407     }
    408     float SpaceShip::getMaxSpeedFront()
    409     {
    410         float ret=0;
     406            sum += this->engineList_[i]->getSpeedMultiply();
     407        return sum/float(i);
     408    }
     409
     410    /**
     411    @brief
     412        Get the largest maximal forward speed over all engines of the SpaceShip.
     413    @return
     414        Returns the largest forward speed over all engines of the SpaceShip.
     415    */
     416    float SpaceShip::getMaxSpeedFront() const
     417    {
     418        float speed=0;
    411419        for(unsigned int i=0; i<this->engineList_.size(); i++)
    412420        {
    413             if(this->engineList_[i]->getMaxSpeedFront() > ret)
    414                 ret = this->engineList_[i]->getMaxSpeedFront();
    415         }
    416         return ret;
    417     }
    418 
    419     float SpaceShip::getBoostFactor()
    420     {
    421         float ret = 0; unsigned int i=0;
     421            if(this->engineList_[i]->getMaxSpeedFront() > speed)
     422                speed = this->engineList_[i]->getMaxSpeedFront();
     423        }
     424        return speed;
     425    }
     426
     427    /**
     428    @brief
     429        Get the mean boost factor over all engines of the SpaceShip.
     430    @return
     431        Returns the mean boost factor over all engines of the SpaceShip.
     432    */
     433    float SpaceShip::getBoostFactor() const
     434    {
     435        float sum = 0;
     436        unsigned int i=0;
    422437        for(; i<this->engineList_.size(); i++)
    423             ret += this->engineList_[i]->getBoostFactor();
    424         ret /= (float)i;
    425         return ret;
    426     }
    427 
    428     std::vector<PickupCarrier*>* SpaceShip::getCarrierChildren(void) const
    429     {
    430         std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
    431         for(unsigned int i=0; i<this->engineList_.size(); i++)
    432             list->push_back(this->engineList_[i]);
    433         return list;
    434     }
    435    
     438            sum += this->engineList_[i]->getBoostFactor();
     439        return sum/float(i);
     440    }
     441
     442    /**
     443    @brief
     444        Is called when the enableMotionBlur config value has changed.
     445    */
    436446    void SpaceShip::changedEnableMotionBlur()
    437447    {
    438         if (!this->bEnableMotionBlur_)
     448        if (!this->bEnableMotionBlur_ && this->boostBlur_ != NULL)
    439449        {
    440450            this->boostBlur_->destroy();
    441             this->boostBlur_ = 0;
    442         }
     451            this->boostBlur_ = NULL;
     452        }
     453    }
     454
     455    /**
     456    @brief
     457        Shake the camera for a given time interval.
     458    @param dt
     459        The time interval in seconds.
     460    */
     461    void SpaceShip::shakeCamera(float dt)
     462    {
     463        // Make sure the ship is only shaking if it's moving forward and above the maximal forward speed.
     464        if (-this->getLocalVelocity().z > this->getMaxSpeedFront())
     465        {
     466            this->shakeDt_ += dt;
     467
     468            float frequency = this->shakeFrequency_ * (square(abs(this->getLocalVelocity().z)));
     469
     470            if (this->shakeDt_ >= 1.0f/frequency)
     471                this->shakeDt_ -= 1.0f/frequency;
     472
     473            Degree angle = Degree(sin(this->shakeDt_ * math::twoPi * frequency) * this->shakeAmplitude_);
     474
     475            Camera* camera = this->getCamera();
     476            //Shaking Camera effect
     477            if (camera != 0)
     478                camera->setOrientation(Vector3::UNIT_X, angle);
     479
     480        }
     481        // If the camera is no shaking, reset it.
     482        else
     483            this->resetCamera();
     484    }
     485
     486    /**
     487    @brief
     488        Save the original position and orientation of the camera.
     489    */
     490    void SpaceShip::backupCamera()
     491    {
     492        Camera* camera = CameraManager::getInstance().getActiveCamera();
     493        if(camera != NULL)
     494        {
     495            this->cameraOriginalPosition_ = camera->getPosition();
     496            this->cameraOriginalOrientation_ = camera->getOrientation();
     497        }
     498    }
     499
     500    /**
     501    @brief
     502        Reset the camera to its original position.
     503    */
     504    void SpaceShip::resetCamera()
     505    {
     506        Camera *camera = this->getCamera();
     507        if (camera == 0)
     508        {
     509            COUT(2) << "Failed to reset camera!";
     510            return;
     511        }
     512
     513        this->shakeDt_ = 0.0f;
     514        camera->setPosition(this->cameraOriginalPosition_);
     515        camera->setOrientation(this->cameraOriginalOrientation_);
    443516    }
    444517
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

    r8706 r8727  
    3434#include <string>
    3535#include <LinearMath/btVector3.h>
     36
    3637#include "tools/Timer.h"
    3738#include "util/Math.h"
     39#include "util/OrxAssert.h"
     40
    3841#include "Pawn.h"
    3942
    4043namespace orxonox
    4144{
     45
     46    /**
     47    @brief
     48        The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
     49
     50        There are several parameters that define the behavior of the SpaceShip>
     51        - The <b>rotationThrust</b>, specifies the force with which the SpaceShip rotates.
     52        - The <b>boost</b>, there are quite some parameters pertaining to boosting. The boost is a special move of the SpaceShip, where, for a limited amount of time, it can fly considerably faster than usual. The <b>boostPower</b> is the amount of power available for boosting. The <b>boostPowerRate</b> is the rate at which the boost power is replenished. The <b>boostRate</b> is the rate at which boosting uses power. And the <b>boostCooldownDuration</b> is the time the SpaceShip cannot boost, once all the boost power has been used up. Naturally all of these parameters must be non-negative.
     53        - The <b>boost shaking</b>, when the SpaceShip boosts, the camera shakes to create a more immersive effect. Two parameters can be used to adjust the effect. The <b>shakeFrequency</b> is the frequency with which the camera shakes. And the <b>shakeAmplitude</b> is the amount with which the camera shakes. Again these parameters must bee non-negative.
     54        - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated.
     55
     56        As mentioned @ref orxonox::Engine Engines can be mounted on the SpaceShip. Here is a (primitive) example of a SpaceShip defined in XML:
     57        @code
     58        <SpaceShip
     59            rotationThrust    = 50
     60
     61            lift = 1;
     62            stallSpeed = 220;
     63
     64            boostPower            = 15
     65            boostPowerRate        = 1
     66            boostRate             = 5
     67            boostCooldownDuration = 10
     68
     69            shakeFrequency = 15
     70            shakeAmplitude = 9
     71
     72            collisionType     = "dynamic"
     73            mass              = 100
     74            linearDamping     = 0.7
     75            angularDamping    = 0.9999999
     76            >
     77                <engines>
     78                    <Engine />
     79                    <Engine />
     80                </engines>
     81            </SpaceShip>
     82        @endcode
     83
     84    @author
     85        Fabian 'x3n' Landau
     86    */
    4287    class _OrxonoxExport SpaceShip : public Pawn
    4388    {
     
    5095            void setConfigValues();
    5196
    52             virtual void moveFrontBack(const Vector2& value);
    53             virtual void moveRightLeft(const Vector2& value);
    54             virtual void moveUpDown(const Vector2& value);
    55 
    56             virtual void rotateYaw(const Vector2& value);
    57             virtual void rotatePitch(const Vector2& value);
    58             virtual void rotateRoll(const Vector2& value);
     97            /**
     98            @brief Move forward or backward,
     99            @param value A vector whose first component specifies the amount of movement. Positive means forward, negative means backward.
     100            */
     101            virtual void moveFrontBack(const Vector2& value)
     102                { this->steering_.z -= value.x; }
     103            /**
     104            @brief Move right or left.
     105            @param value A vector whose first component specifies the amount of movement. Positive means right, negative means left.
     106            */
     107            virtual void moveRightLeft(const Vector2& value)
     108                { this->steering_.x += value.x; }
     109            /**
     110            @brief Move up or down.
     111            @param value A vector whose first component specifies the amount of movement. Positive means up, negative means down.
     112            */
     113            virtual void moveUpDown(const Vector2& value)
     114                { this->steering_.y += value.x; }
     115
     116            virtual void rotateYaw(const Vector2& value); // Rotate in yaw direction.
     117            virtual void rotatePitch(const Vector2& value); // Rotate in pitch direction.
     118            virtual void rotateRoll(const Vector2& value); // Rotate in roll direction.
    59119
    60120            virtual void fire();
    61121            virtual void boost(bool bBoost); // Starts or stops boosting.
    62122
    63             void addEngine(Engine* engine);
    64             bool hasEngine(Engine* engine);
    65             Engine* getEngine(unsigned int i); // This one's for XMLPort
    66             inline const std::vector<Engine*>& getEngineList()
     123            void addEngine(Engine* engine); // Add an Engine to the SpaceShip.
     124            bool hasEngine(Engine* engine) const; // Check whether the SpaceShip has a particular Engine.
     125            Engine* getEngine(unsigned int i); // Get the i-th Engine of the SpaceShip.
     126            /**
     127            @brief Get the list of all Engines that are mounted on the SpaceShip.
     128            @return Returns a vector of all Engines of the SpaceShip.
     129            */
     130            inline const std::vector<Engine*>& getEngineList() const
    67131                { return this->engineList_; }
    68             void removeEngine(Engine* engine);
    69             void removeAllEngines();
    70 
    71             void setSpeedFactor(float factor);
    72             float getSpeedFactor(); // Gets mean speed factor
    73             float getMaxSpeedFront(); // gets largest speed forward
    74             float getBoostFactor(); // gets mean boost factor
    75 
     132            void removeEngine(Engine* engine); // Remove and destroy all Engines of the SpaceShip.
     133            void removeAllEngines(); // Remove a particular Engine from the SpaceShip.
     134
     135            void addSpeedFactor(float factor); // Add to the speed factor for all engines of the SpaceShip.
     136            void addSpeed(float speed); // Add to the speed of all engines of the SpaceShip.
     137            float getSpeedFactor() const; // Get the mean speed factor over all engines of the SpaceShip.
     138   
     139            float getMaxSpeedFront() const; // Get the largest maximal forward speed over all engines of the SpaceShip.
     140            float getBoostFactor() const; // Get the mean boost factor over all engines of the SpaceShip.
     141
     142            /**
     143            @brief Set the steering direction of the SpaceShip.
     144                   This is set through the user input.
     145            @param direction The direction the SpaceShip should steer in.
     146            */
    76147            inline void setSteeringDirection(const Vector3& direction)
    77148                { this->steering_ = direction; }
     149            /**
     150            @brief Get the steering direction of the SpaceShip.
     151            @return Returns the steering direction of the SpaceShip. The length of the vector is the amount of steering needed.
     152            */
    78153            inline const Vector3& getSteeringDirection() const
    79154                { return this->steering_; }
    80             inline void resetEngineTicks()
    81                 { this->engineTicksNotDone = this->engineList_.size(); }
    82             inline void oneEngineTickDone()
    83                 { this->engineTicksNotDone--; }
    84             inline bool hasEngineTicksRemaining()
    85                 { return (this->engineTicksNotDone>0); }
    86 
    87             inline bool getBoost() const
     155
     156            /**
     157            @brief Check whether the SpaceShip is currently boosting.
     158            @return Returns true if the SpaceShip is boosting, false if not.
     159            */
     160            inline bool isBoosting() const
    88161                { return this->bBoost_; }
    89 
     162            /**
     163            @brief Check whether the SpaceShip boost is cooling down.
     164            @return Returns true if the SpaceShip is cooling down from boosting.
     165            */
     166            inline bool isBoostCoolingDown() const
     167                { return bBoostCooldown_; }
     168
     169            /**
     170            @brief Set the initial power available for boosting to the input value.
     171                   The current boost power is set to the input value as well.
     172            @param power The initial boost power. Must be non-negative.
     173            */
     174            inline void setInitialBoostPower(float power)
     175                { OrxAssert(power >= 0.0f, "The boost power must be non-negative."); this->initialBoostPower_ = power; this->boostPower_ = power; }
     176            /**
     177            @brief Set the rate, at which boost power is recharged, to the input value.
     178            @param rate The boost power rate in units per second. Must be non-negative.
     179            */
     180            inline void setBoostPowerRate(float rate)
     181                { OrxAssert(rate >= 0.0f, "The boost power rate must be non-negative."); this->boostPowerRate_ = rate; }
     182            /**
     183            @brief Set the rate, at which boost power us used up, to the input value.
     184            @param rate The boost rate in units per second. Must be non-negative.
     185            */
     186            inline void setBoostRate(float rate)
     187                { OrxAssert(rate >= 0.0f, "The boost rate must be non-negative."); this->boostRate_ = rate; }
     188            /**
     189            @brief Set the duration for which boosting, if in cooldown, is not possible.
     190                   Cooldown is reached if all boost power is depleted.
     191            @param duration The cooldown duration in seconds. Must be non-negative.
     192            */
     193            inline void setBoostCooldownDuration(float duration)
     194                { OrxAssert(duration >= 0.0f, "The boost cooldown duration must be non-negative."); this->boostCooldownDuration_ = duration; }
     195            /**
     196            @brief Set the frequency with which the camera shakes during boosting.
     197            @param frequency The frequency in times per second. Must be non-negative.
     198            */
     199            inline void setShakeFrequency(float frequency)
     200                { OrxAssert(frequency >= 0.0f, "The shake frequency must be non-negative."); this->shakeFrequency_ = frequency; }
     201            /**
     202            @brief Set the amplitude with which the camera shakes during boosting.
     203            @param amplitude The amplitude. Must be non-negative.
     204            */
     205            inline void setShakeAmplitude(float amplitude)
     206                { OrxAssert(amplitude >= 0.0f, "The shake amplitude must be non-negative."); this->shakeAmplitude_ = amplitude; }
     207
     208            /**
     209            @brief Get the initial boost power. Is non-negative.
     210            @return Returns the initial boost power.
     211            */
     212            inline float getInitialBoostPower() const
     213                { return this->initialBoostPower_; }
     214            /**
     215            @brief Get the current boost power. Is non-negative.
     216            @return Returns the current boost power.
     217            */
    90218            inline float getBoostPower() const
    91219                { return this->boostPower_; }
    92             inline float getInitialBoostPower() const
    93                 { return this->initialBoostPower_; }
    94 
    95             inline bool isBoostCoolingDown() const
    96                 { return bBoostCooldown_; }
     220            /**
     221            @brief Get the boost power rate.
     222            @return Returns the boost power rate in units per second. Is non-negative.
     223            */
     224            inline float getBoostPowerRate() const
     225                { return this->boostPowerRate_; }
     226            /**
     227            @brief Get the boost rate.
     228            @return Returns the boost rate in units per second. Is non-negative.
     229            */
     230            inline float getBoostRate() const
     231                { return this->boostRate_; }
     232            /**
     233            @brief Get the cooldown duration.
     234            @return Returns the cooldown duration in seconds. Is non-negative.
     235            */
     236            inline float getBoostCooldownDuration() const
     237                { return this->boostCooldownDuration_; }
     238            /**
     239            @brief Get the shake frequency.
     240            @return Returns the shake frequency in times per seconds. Is non-negative.
     241            */
     242            inline float getShakeFrequency() const
     243                { return this->shakeFrequency_; }
     244            /**
     245            @brief Get the shake amplitude.
     246            @return Returns the shake amplitude. Is non-negative.
     247            */
     248            inline float getShakeAmplitude() const
     249                { return this->shakeAmplitude_; }
    97250
    98251        protected:
    99             virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const;
    100252            bool bInvertYAxis_;
    101253
    102             bool bBoost_;
    103             bool bBoostCooldown_;
    104             float boostPower_;
    105             float initialBoostPower_;
    106             float boostRate_;
    107             float boostPowerRate_;
    108             float boostCooldownDuration_;
    109             float lift_;
    110             float stallSpeed_;
    111             Vector3 steering_;
    112             float primaryThrust_;
    113             float auxilaryThrust_;
    114             float rotationThrust_;
    115             btVector3 localLinearAcceleration_;
    116             btVector3 localAngularAcceleration_;
    117 
    118             float shakeFrequency_;
    119             float shakeAmplitude_;
     254            Vector3 steering_; //!< The direction and magnitude of the steering action given through user input.
     255
     256            float rotationThrust_;               //!< Force with which the SpaceShip rotates.
     257            btVector3 localAngularAcceleration_; //!< The acceleration that accounts for angular movement and is used internally.
     258
     259            bool bBoost_;                 //!< Whether the SpaceShip is currently boosting.
     260            bool bBoostCooldown_;         //!< Whether the SpaceShip is currently in boost cooldown, during which boosting is impossible.
     261            float initialBoostPower_;     //!< The initial (and maximal) boost power.
     262            float boostPower_;            //!< The current boost power.
     263            float boostPowerRate_;        //!< The rate at which the boost power is recharged.
     264            float boostRate_;             //!< The rate at which boost power is used up.
     265            float boostCooldownDuration_; //!< The duration for which boost cooldown is in effect.
     266            float shakeFrequency_;        //!< The frequency of the shaking of the camera due to boosting.
     267            float shakeAmplitude_;        //!< The amplitude of the shaking of the camera due to boosting.
     268
     269            float lift_;       //!< The amount of lift that is added.
     270            float stallSpeed_; //!< The forward speed where no more lift is added.
    120271
    121272        private:
    122273            void registerVariables();
    123274            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    124            
    125             //All things booster
    126             void changedEnableMotionBlur();
    127             void boostCooledDown(void);
     275
     276            void changedEnableMotionBlur(); // Is called when the enableMotionBlur config value has changed.
     277            /**
     278            @brief Callback function. Is called when the boost has cooled down.
     279            */
     280            void boostCooledDown(void)
     281                { this->bBoostCooldown_ = false; }
     282
     283            void shakeCamera(float dt); // Shake the camera for a given time interval.
     284            void backupCamera(); // Save the original position and orientation of the camera.
     285            void resetCamera(); // Reset the camera to its original position.
     286
     287            std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip.
     288
     289            Timer timer_;                          //!< Timer for the cooldown duration.
     290            float shakeDt_;                        //!< Temporary variable for the shaking of the camera.
     291            Vector3 cameraOriginalPosition_;       //!< The original position of the camera before shaking it.
     292            Quaternion cameraOriginalOrientation_; //!< The original orientation of the camera before shaking it.
     293
     294            Shader* boostBlur_;      //!< A radial blur shader, applied when boosting according to the amount of boosting.
     295            float blurStrength_;     //!< The strength of the applied blur.
     296            bool bEnableMotionBlur_; //!< Whether motion blur is enabled or not.
    128297       
    129             void resetCamera();
    130             void backupCamera();
    131             void shakeCamera(float dt);
    132 
    133             Shader* boostBlur_;
    134             float blurStrength_;
    135             bool bEnableMotionBlur_;
    136 
    137             std::vector<Engine*> engineList_;
    138             int engineTicksNotDone; // Used for knowing when to reset temporary variables.
    139             Timer timer_;
    140             Vector3 cameraOriginalPosition_;
    141             Quaternion cameraOriginalOrientation_;
    142        
    143             float shakeDt_;
    144298    };
    145299}
Note: See TracChangeset for help on using the changeset viewer.