Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 14, 2011, 8:53:28 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

Location:
code/trunk
Files:
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/worldentities/CMakeLists.txt

    r8458 r8706  
    1212  SpawnPoint.cc
    1313  TeamSpawnPoint.cc
    14   SpaceBoundaries.cc
    1514)
    1615
  • code/trunk/src/orxonox/worldentities/CameraPosition.cc

    r5929 r8706  
    4646        this->bRenderCamera_ = false;
    4747
    48         this->setSyncMode(0x0);
     48        this->setSyncMode(ObjectDirection::None);
    4949    }
    5050
  • code/trunk/src/orxonox/worldentities/ControllableEntity.cc

    r7892 r8706  
    8484        this->client_angular_velocity_ = Vector3::ZERO;
    8585
    86 
    8786        this->setConfigValues();
    8887        this->setPriority( Priority::VeryHigh );
     
    121120
    122121        XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode);
    123         XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
     122        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemplate, xmlelement, mode);
    124123
    125124        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     
    171170        }
    172171        return 0;
     172    }
     173
     174    unsigned int ControllableEntity::getCurrentCameraIndex() const
     175    {
     176        if (this->cameraPositions_.size() <= 0)
     177            return 0;
     178
     179        unsigned int counter = 0;
     180        for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     181        {
     182            if ((*it) == this->currentCameraPosition_)
     183                break;
     184            counter++;
     185        }
     186        if (counter >= this->cameraPositions_.size())
     187            return 0;
     188
     189        return counter;
     190    }
     191   
     192    bool ControllableEntity::setCameraPosition(unsigned int index)
     193    {
     194        if(this->camera_ != NULL && this->cameraPositions_.size() > 0)
     195        {
     196            if(index >= this->cameraPositions_.size())
     197                index = 0;
     198
     199            CameraPosition* position = this->getCameraPosition(index);
     200            position->attachCamera(this->camera_);
     201            this->currentCameraPosition_ = position;
     202            return true;
     203        }
     204
     205        return false;
    173206    }
    174207
     
    373406        }
    374407
     408        this->createHud();
     409    }
     410
     411    // HACK-ish
     412    void ControllableEntity::createHud(void)
     413    {
    375414        if (!this->hud_ && GameMode::showsGraphics())
    376415        {
     
    381420                this->hud_->setOwner(this);
    382421            }
     422        }
     423    }
     424
     425    void ControllableEntity::destroyHud(void)
     426    {
     427        if (this->hud_ != NULL)
     428        {
     429            this->hud_->destroy();
     430            this->hud_ = NULL;
    383431        }
    384432    }
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r7889 r8706  
    9393            virtual void reload() {}
    9494
    95             virtual void boost() {}
     95            /**
     96            @brief Tells the ControllableEntity to either start or stop boosting.
     97                   This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will.
     98            @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop.
     99            */
     100            virtual void boost(bool bBoost) {}
     101           
    96102            virtual void greet() {}
    97103            virtual void switchCamera();
     
    110116            inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const
    111117                { return this->cameraPositions_; }
     118            unsigned int getCurrentCameraIndex() const;
     119            bool setCameraPosition(unsigned int index);
    112120
    113121            inline void setCameraPositionTemplate(const std::string& name)
    114122                { this->cameraPositionTemplate_ = name; }
    115             inline const std::string& getCameraPositionTemkplate() const
     123            inline const std::string& getCameraPositionTemplate() const
    116124                { return this->cameraPositionTemplate_; }
    117125
     
    168176            inline void setHudTemplate(const std::string& name)
    169177                { this->hudtemplate_ = name; }
     178            // HACK-ish
     179            void createHud(void);
     180            void destroyHud(void);
    170181
    171182            Ogre::SceneNode* cameraPositionRootNode_;
  • code/trunk/src/orxonox/worldentities/MobileEntity.cc

    r7163 r8706  
    143143    {
    144144        if (this->isDynamic())
     145        {
    145146            this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass()));
    146 
     147        }
     148
     149        // If not bullet-managed (deprecated? SpaceShip doesn't use this anymore for movement)
    147150        this->linearAcceleration_ = acceleration;
     151    }
     152
     153    void MobileEntity::addAcceleration(const Vector3 &acceleration, const Vector3 &relativePosition)
     154    {
     155        if(this->isDynamic())
     156        {
     157            this->physicalBody_->applyForce(this->getMass() * btVector3(acceleration.x, acceleration.y, acceleration.z), btVector3(relativePosition.x, relativePosition.y, relativePosition.z));
     158        }
    148159    }
    149160
  • code/trunk/src/orxonox/worldentities/MobileEntity.h

    r5781 r8706  
    7070                { return this->linearAcceleration_; }
    7171
     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
     77
    7278            void setAngularAcceleration(const Vector3& acceleration);
    7379            inline void setAngularAcceleration(float x, float y, float z)
     
    8389                { this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); }
    8490            inline Degree getRotationRate() const
    85                 { return Degree(this->getAngularVelocity().length()); }
     91                { return Radian(this->getAngularVelocity().length()); }
    8692
    8793            inline void setRotationAxis(const Vector3& axis)
  • code/trunk/src/orxonox/worldentities/SpawnPoint.cc

    r5929 r8706  
    5050            COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl;
    5151
    52         this->setSyncMode(0x0);
     52        this->setSyncMode(ObjectDirection::None);
    5353    }
    5454
  • code/trunk/src/orxonox/worldentities/WorldEntity.cc

    r7937 r8706  
    642642    void WorldEntity::setScale3D(const Vector3& scale)
    643643    {
    644 /*
    645 HACK HACK HACK
    646         if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE)
    647         {
    648             CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl;
    649             return;
    650         }
    651 HACK HACK HACK
    652 */
     644        // If physics is enabled scale the attached CollisionShape.
     645        /*if (this->hasPhysics() && this->collisionShape_ != NULL)
     646        {
     647            this->collisionShape_->setScale3D(scale);
     648        }*/
     649
    653650        this->node_->setScale(scale);
    654651
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r8351 r8706  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Simon Miescher
    2626 *
    2727 */
     
    6464        this->maxHealth_ = 0;
    6565        this->initialHealth_ = 0;
     66
    6667        this->shieldHealth_ = 0;
     68        this->initialShieldHealth_ = 0;
     69        this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
    6770        this->shieldAbsorption_ = 0.5;
     71
     72        this->reloadRate_ = 0;
     73        this->reloadWaitTime_ = 1.0f;
     74        this->reloadWaitCountdown_ = 0;
    6875
    6976        this->lastHitOriginator_ = 0;
     
    109116
    110117        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     118        XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
     119        XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
    111120        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
    112121
     
    118127        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
    119128        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
     129
     130        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
     131        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
    120132    }
    121133
     
    124136        registerVariable(this->bAlive_,           VariableDirection::ToClient);
    125137        registerVariable(this->health_,           VariableDirection::ToClient);
    126         registerVariable(this->initialHealth_,    VariableDirection::ToClient);
     138        registerVariable(this->maxHealth_,        VariableDirection::ToClient);
    127139        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
     140        registerVariable(this->maxShieldHealth_,  VariableDirection::ToClient);
    128141        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
    129142        registerVariable(this->bReload_,          VariableDirection::ToServer);
     
    137150        this->bReload_ = false;
    138151
     152        // TODO: use the existing timer functions instead
     153        if(this->reloadWaitCountdown_ > 0)
     154        {
     155            this->decreaseReloadCountdownTime(dt);
     156        }
     157        else
     158        {
     159            this->addShieldHealth(this->getReloadRate() * dt);
     160            this->resetReloadCountdown();
     161        }
     162
    139163        if (GameMode::isMaster())
     164        {
    140165            if (this->health_ <= 0 && bAlive_)
    141166            {
    142                 this->fireEvent(); // Event to notify anyone who want's to know about the death.
     167                this->fireEvent(); // Event to notify anyone who wants to know about the death.
    143168                this->death();
    144169            }
     170        }
    145171    }
    146172
     
    168194    }
    169195
     196
    170197    void Pawn::setHealth(float health)
    171198    {
    172         this->health_ = std::min(health, this->maxHealth_);
    173     }
    174 
    175     void Pawn::damage(float damage, Pawn* originator)
     199        this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit
     200    }
     201
     202    void Pawn::setShieldHealth(float shieldHealth)
     203    {
     204        this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_);
     205    }
     206
     207    void Pawn::setMaxShieldHealth(float maxshieldhealth)
     208    {
     209        this->maxShieldHealth_ = maxshieldhealth;
     210    }
     211
     212    void Pawn::setReloadRate(float reloadrate)
     213    {
     214        this->reloadRate_ = reloadrate;
     215    }
     216
     217    void Pawn::setReloadWaitTime(float reloadwaittime)
     218    {
     219        this->reloadWaitTime_ = reloadwaittime;
     220    }
     221
     222    void Pawn::decreaseReloadCountdownTime(float dt)
     223    {
     224        this->reloadWaitCountdown_ -= dt;
     225    }
     226
     227    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    176228    {
    177229        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    178230        {
    179             //share the dealt damage to the shield and the Pawn.
    180             float shielddamage = damage*this->shieldAbsorption_;
    181             float healthdamage = damage*(1-this->shieldAbsorption_);
    182 
    183             // In case the shield can not take all the shield damage.
    184             if (shielddamage > this->getShieldHealth())
     231            if (shielddamage >= this->getShieldHealth())
    185232            {
    186                 healthdamage += shielddamage-this->getShieldHealth();
    187233                this->setShieldHealth(0);
     234                this->setHealth(this->health_ - (healthdamage + damage));
    188235            }
    189 
    190             this->setHealth(this->health_ - healthdamage);
    191 
    192             if (this->getShieldHealth() > 0)
     236            else
    193237            {
    194238                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     239
     240                // remove remaining shieldAbsorpton-Part of damage from shield
     241                shielddamage = damage * this->shieldAbsorption_;
     242                shielddamage = std::min(this->getShieldHealth(),shielddamage);
     243                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     244
     245                // set remaining damage to health
     246                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    195247            }
    196248
    197249            this->lastHitOriginator_ = originator;
    198 
    199             // play damage effect
    200         }
    201     }
    202 
    203     void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
     250        }
     251    }
     252
     253// TODO: Still valid?
     254/* HIT-Funktionen
     255    Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
     256
     257*/
     258
     259    void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage)
    204260    {
    205261        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    206262        {
    207             this->damage(damage, originator);
     263            this->damage(damage, healthdamage, shielddamage, originator);
    208264            this->setVelocity(this->getVelocity() + force);
    209 
    210             // play hit effect
    211         }
    212     }
    213 
    214     void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     265        }
     266    }
     267
     268
     269    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
    215270    {
    216271        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    217272        {
    218             this->damage(damage, originator);
     273            this->damage(damage, healthdamage, shielddamage, originator);
    219274
    220275            if ( this->getController() )
    221                 this->getController()->hit(originator, contactpoint, damage);
    222 
    223             // play hit effect
    224         }
    225     }
     276                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
     277        }
     278    }
     279
    226280
    227281    void Pawn::kill()
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r7889 r8706  
    7272                { return this->initialHealth_; }
    7373
    74             inline void setShieldHealth(float shieldHealth)
    75             { this->shieldHealth_ = shieldHealth; }
     74            virtual void setShieldHealth(float shieldHealth);
     75
    7676            inline float getShieldHealth()
    7777            { return this->shieldHealth_; }
     78
     79            inline void addShieldHealth(float amount)
     80            { this->setShieldHealth(this->shieldHealth_ + amount); }
     81
     82            inline bool hasShield()
     83            { return (this->getShieldHealth() > 0); }
     84
     85            virtual void setMaxShieldHealth(float maxshieldhealth);
     86            inline float getMaxShieldHealth() const
     87                { return this->maxShieldHealth_; }
     88
     89            inline void setInitialShieldHealth(float initialshieldhealth)
     90                { this->initialShieldHealth_ = initialshieldhealth; this->setShieldHealth(initialshieldhealth); }
     91            inline float getInitialShieldHealth() const
     92                { return this->initialShieldHealth_; }
     93
     94            inline void restoreInitialShieldHealth()
     95                { this->setShieldHealth(this->initialShieldHealth_); }
     96            inline void restoreMaxShieldHealth()
     97                { this->setShieldHealth(this->maxShieldHealth_); }
    7898
    7999            inline void setShieldAbsorption(float shieldAbsorption)
     
    82102            { return this->shieldAbsorption_; }
    83103
     104            // TODO: Rename to shieldRechargeRate
     105            virtual void setReloadRate(float reloadrate);
     106            inline float getReloadRate() const
     107                { return this->reloadRate_; }
     108
     109            virtual void setReloadWaitTime(float reloadwaittime);
     110            inline float getReloadWaitTime() const
     111                { return this->reloadWaitTime_; }
     112
     113            inline void resetReloadCountdown()
     114            { this->reloadWaitCountdown_ = 0; }
     115
     116            inline void startReloadCountdown()
     117            { this->reloadWaitCountdown_ = this->getReloadWaitTime(); } // TODO: Implement in Projectile.cc
     118
     119            virtual void decreaseReloadCountdownTime(float dt);
     120
    84121            inline ControllableEntity* getLastHitOriginator() const
    85122                { return this->lastHitOriginator_; }
    86123
    87             virtual void hit(Pawn* originator, const Vector3& force, float damage);
    88             virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     124            //virtual void hit(Pawn* originator, const Vector3& force, float damage);
     125            //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     126            virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     127            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     128
    89129            virtual void kill();
    90130
     
    142182            virtual void spawneffect();
    143183
    144             virtual void damage(float damage, Pawn* originator = 0);
     184            //virtual void damage(float damage, Pawn* originator = 0);
     185            virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL);
    145186
    146187            bool bAlive_;
     
    154195            float maxHealth_;
    155196            float initialHealth_;
     197           
    156198            float shieldHealth_;
     199            float maxShieldHealth_;
     200            float initialShieldHealth_;
    157201            float shieldAbsorption_; // Has to be between 0 and 1
     202            float reloadRate_;
     203            float reloadWaitTime_;
     204            float reloadWaitCountdown_;
    158205
    159206            WeakPtr<Pawn> lastHitOriginator_;
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc

    r7860 r8706  
    3535#include "core/Template.h"
    3636#include "core/XMLPort.h"
     37#include "tools/Shader.h"
     38#include "util/Debug.h" // TODO: Needed?
     39#include "util/Math.h"
     40
     41#include "graphics/Camera.h"
    3742#include "items/Engine.h"
     43
     44#include "CameraManager.h"
     45#include "Scene.h"
    3846
    3947namespace orxonox
     
    4250    CreateFactory(SpaceShip);
    4351
    44     SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
     52    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator), boostBlur_(NULL)
    4553    {
    4654        RegisterObject(SpaceShip);
     
    5361        this->localAngularAcceleration_.setValue(0, 0, 0);
    5462        this->bBoost_ = false;
    55         this->bPermanentBoost_ = false;
    5663        this->steering_ = Vector3::ZERO;
    57         this->engine_ = 0;
    5864
    5965        this->boostPower_ = 10.0f;
     
    6470        this->bBoostCooldown_ = false;
    6571
     72        this->lift_ = 1.0f;                         // factor of the lift, standard is 1
     73        this->stallSpeed_ = 220.0f;                 // max speed where lift is added
     74
    6675        this->bInvertYAxis_ = false;
    6776
     
    7483        this->enableCollisionCallback();
    7584
     85        this->engineTicksNotDone = 0;
    7686        this->setConfigValues();
    7787        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;
    7895    }
    7996
    8097    SpaceShip::~SpaceShip()
    8198    {
    82         if (this->isInitialized() && this->engine_)
    83             this->engine_->destroy();
     99        if (this->isInitialized())
     100        {
     101            this->removeAllEngines();
     102       
     103            if (this->boostBlur_)
     104                this->boostBlur_->destroy();
     105        }
    84106    }
    85107
     
    88110        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    89111
    90         XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
     112        //XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    91113        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    92114        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     
    96118        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    97119        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
     120        XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
     121        XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
     122        XMLPortParamVariable(SpaceShip, "lift", lift_, xmlelement, mode);
     123        XMLPortParamVariable(SpaceShip, "stallSpeed", stallSpeed_, xmlelement, mode);
     124
     125        XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode);
    98126    }
    99127
     
    103131        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    104132        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
     133        // TODO: Synchronization of boost needed?
     134        registerVariable(this->boostPower_, VariableDirection::ToClient);
     135        registerVariable(this->boostPowerRate_, VariableDirection::ToClient);
     136        registerVariable(this->boostRate_, VariableDirection::ToClient);
     137        registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient);
     138        registerVariable(this->shakeFrequency_, VariableDirection::ToClient);
     139        registerVariable(this->shakeAmplitude_, VariableDirection::ToClient);
     140        registerVariable(this->lift_, VariableDirection::ToClient);
     141        registerVariable(this->stallSpeed_, VariableDirection::ToClient);
    105142    }
    106143
     
    108145    {
    109146        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
     147       
     148        SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
     149            .description("Enable or disable the motion blur effect when moving very fast")
     150            .callback(this, &SpaceShip::changedEnableMotionBlur);
     151        SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)
     152            .description("Defines the strength of the motion blur effect");
    110153    }
    111154
     
    128171        if (this->hasLocalController())
    129172        {
    130 /*
    131             this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
    132             this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
    133             if (this->localLinearAcceleration_.z() > 0)
    134                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    135             else
    136                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    137             this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    138             this->localLinearAcceleration_.setValue(0, 0, 0);
    139 */
     173            // Handle mouse look
    140174            if (!this->isInMouseLook())
    141175            {
     
    143177                this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    144178            }
    145 
    146179            this->localAngularAcceleration_.setValue(0, 0, 0);
    147180
     181            // Charge boostPower
    148182            if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_)
    149183            {
    150184                this->boostPower_ += this->boostPowerRate_*dt;
    151185            }
     186            // Use boostPower
    152187            if(this->bBoost_)
    153188            {
     
    155190                if(this->boostPower_ <= 0.0f)
    156191                {
    157                     this->bBoost_ = false;
     192                    this->boost(false);
    158193                    this->bBoostCooldown_ = true;
    159194                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
    160195                }
    161             }
     196
     197                this->shakeCamera(dt);
     198            }
     199
     200            // Enable Blur depending on settings
     201            if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController())
     202            {
     203                this->boostBlur_ = new Shader(this->getScene()->getSceneManager());
     204                this->boostBlur_->setCompositorName("Radial Blur");
     205            }
     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
     241    void SpaceShip::rotateYaw(const Vector2& value)
     242    {
     243        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
     244
     245        Pawn::rotateYaw(value);
     246
     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
     251    void SpaceShip::rotatePitch(const Vector2& value)
     252    {
     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
     261    void SpaceShip::rotateRoll(const Vector2& value)
     262    {
     263        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
     264
     265        Pawn::rotateRoll(value);
     266    }
     267
     268    void SpaceShip::fire()
     269    {
     270    }
     271
     272    /**
     273    @brief
     274        Starts or stops boosting.
     275    @param bBoost
     276        Whether to start or stop boosting.
     277    */
     278    void SpaceShip::boost(bool bBoost)
     279    {
     280        if(bBoost && !this->bBoostCooldown_)
     281        {
     282            this->bBoost_ = true;
     283            Camera* camera = CameraManager::getInstance().getActiveCamera();
     284            this->cameraOriginalPosition_ = camera->getPosition();
     285            this->cameraOriginalOrientation_ = camera->getOrientation();
     286        }
     287        if(!bBoost)
     288        {
     289            this->bBoost_ = false;
     290            this->resetCamera();
    162291        }
    163292    }
     
    167296        this->bBoostCooldown_ = false;
    168297    }
    169 
    170     void SpaceShip::moveFrontBack(const Vector2& value)
    171     {
    172         this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    173         this->steering_.z = -value.x;
    174     }
    175 
    176     void SpaceShip::moveRightLeft(const Vector2& value)
    177     {
    178         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    179         this->steering_.x = value.x;
    180     }
    181 
    182     void SpaceShip::moveUpDown(const Vector2& value)
    183     {
    184         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    185         this->steering_.y = value.x;
    186     }
    187 
    188     void SpaceShip::rotateYaw(const Vector2& value)
    189     {
    190         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
    191 
    192         Pawn::rotateYaw(value);
    193     }
    194 
    195     void SpaceShip::rotatePitch(const Vector2& value)
    196     {
    197         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
    198 
    199         Pawn::rotatePitch(value);
    200     }
    201 
    202     void SpaceShip::rotateRoll(const Vector2& value)
    203     {
    204         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
    205 
    206         Pawn::rotateRoll(value);
    207     }
    208 
    209     // TODO: something seems to call this function every tick, could probably handled a little more efficiently!
    210     void SpaceShip::setBoost(bool bBoost)
    211     {
    212         if(bBoost == this->bBoost_)
     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!";
    213333            return;
    214 
    215         if(bBoost)
    216             this->boost();
     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
     351    void SpaceShip::addEngine(orxonox::Engine* engine)
     352    {
     353        //COUT(0)<<"Adding an Engine: " << engine << endl;
     354        this->engineList_.push_back(engine);
     355        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)
     364                return true;
     365        }
     366        return false;
     367    }
     368
     369    Engine* SpaceShip::getEngine(unsigned int i)
     370    {
     371        if(this->engineList_.size()>=i)
     372            return 0;
    217373        else
    218         {
    219             this->bBoost_ = false;
    220         }
    221     }
    222 
    223     void SpaceShip::fire()
    224     {
    225     }
    226 
    227     void SpaceShip::boost()
    228     {
    229         if(!this->bBoostCooldown_)
    230             this->bBoost_ = true;
    231     }
    232 
    233     void SpaceShip::loadEngineTemplate()
    234     {
    235         if (!this->enginetemplate_.empty())
    236         {
    237             Template* temp = Template::getTemplate(this->enginetemplate_);
    238 
    239             if (temp)
    240             {
    241                 Identifier* identifier = temp->getBaseclassIdentifier();
    242 
    243                 if (identifier)
    244                 {
    245                     BaseObject* object = identifier->fabricate(this);
    246                     this->engine_ = orxonox_cast<Engine*>(object);
    247 
    248                     if (this->engine_)
    249                     {
    250                         this->engine_->addTemplate(temp);
    251                         this->engine_->addToSpaceShip(this);
    252                     }
    253                     else
    254                     {
    255                         object->destroy();
    256                     }
    257                 }
    258             }
    259         }
    260     }
    261 
    262     void SpaceShip::setEngine(Engine* engine)
    263     {
    264         this->engine_ = engine;
    265         if (engine && engine->getShip() != this)
    266             engine->addToSpaceShip(this);
     374            return this->engineList_[i];
     375    }
     376
     377    void SpaceShip::removeAllEngines()
     378    {
     379        while(this->engineList_.size())
     380            this->engineList_.back()->destroy();
     381    }
     382   
     383    void SpaceShip::removeEngine(Engine* engine)
     384    {
     385        for(std::vector<Engine*>::iterator it=this->engineList_.begin(); it!=this->engineList_.end(); ++it)
     386        {
     387            if(*it==engine)
     388            {
     389                this->engineList_.erase(it);
     390                return;
     391            }
     392        }
     393    }
     394
     395    void SpaceShip::setSpeedFactor(float factor)
     396    {
     397        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;
     403        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;
     411        for(unsigned int i=0; i<this->engineList_.size(); i++)
     412        {
     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;
     422        for(; i<this->engineList_.size(); i++)
     423            ret += this->engineList_[i]->getBoostFactor();
     424        ret /= (float)i;
     425        return ret;
    267426    }
    268427
     
    270429    {
    271430        std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
    272         list->push_back(this->engine_);
     431        for(unsigned int i=0; i<this->engineList_.size(); i++)
     432            list->push_back(this->engineList_[i]);
    273433        return list;
    274434    }
     435   
     436    void SpaceShip::changedEnableMotionBlur()
     437    {
     438        if (!this->bEnableMotionBlur_)
     439        {
     440            this->boostBlur_->destroy();
     441            this->boostBlur_ = 0;
     442        }
     443    }
     444
    275445}
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

    r7801 r8706  
    5959
    6060            virtual void fire();
    61             virtual void boost();
     61            virtual void boost(bool bBoost); // Starts or stops boosting.
    6262
    63             void setEngine(Engine* engine);
    64             inline Engine* getEngine() const
    65                 { return this->engine_; }
     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()
     67                { 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
    6675
    6776            inline void setSteeringDirection(const Vector3& direction)
     
    6978            inline const Vector3& getSteeringDirection() const
    7079                { 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); }
    7186
    72             void setBoost(bool bBoost);
    7387            inline bool getBoost() const
    7488                { return this->bBoost_; }
    7589
    76             inline void setEngineTemplate(const std::string& temp)
    77                 { this->enginetemplate_ = temp; this->loadEngineTemplate(); }
    78             inline const std::string& getEngineTemplate() const
    79                 { return this->enginetemplate_; }
     90            inline float getBoostPower() const
     91                { return this->boostPower_; }
     92            inline float getInitialBoostPower() const
     93                { return this->initialBoostPower_; }
    8094
    81             inline void setPermanentBoost(bool bPermanent)
    82                 { this->bPermanentBoost_ = bPermanent; }
    83             inline bool getPermanentBoost() const
    84                 { return this->bPermanentBoost_; }
     95            inline bool isBoostCoolingDown() const
     96                { return bBoostCooldown_; }
    8597
    8698        protected:
     
    90102            bool bBoost_;
    91103            bool bBoostCooldown_;
    92             bool bPermanentBoost_;
    93104            float boostPower_;
    94105            float initialBoostPower_;
     
    96107            float boostPowerRate_;
    97108            float boostCooldownDuration_;
     109            float lift_;
     110            float stallSpeed_;
    98111            Vector3 steering_;
    99112            float primaryThrust_;
     
    103116            btVector3 localAngularAcceleration_;
    104117
     118            float shakeFrequency_;
     119            float shakeAmplitude_;
     120
    105121        private:
    106122            void registerVariables();
    107123            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
     124           
     125            //All things booster
     126            void changedEnableMotionBlur();
     127            void boostCooledDown(void);
     128       
     129            void resetCamera();
     130            void backupCamera();
     131            void shakeCamera(float dt);
    108132
    109             void loadEngineTemplate();
    110            
    111             void boostCooledDown(void);
     133            Shader* boostBlur_;
     134            float blurStrength_;
     135            bool bEnableMotionBlur_;
    112136
    113             std::string enginetemplate_;
    114             Engine* engine_;
     137            std::vector<Engine*> engineList_;
     138            int engineTicksNotDone; // Used for knowing when to reset temporary variables.
    115139            Timer timer_;
     140            Vector3 cameraOriginalPosition_;
     141            Quaternion cameraOriginalOrientation_;
     142       
     143            float shakeDt_;
    116144    };
    117145}
Note: See TracChangeset for help on using the changeset viewer.