Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2011, 12:58:09 AM (13 years ago)
Author:
dafrick
Message:

Merging bigships branch into presentation branch.

Location:
code/branches/presentation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

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

    r8587 r8589  
    3535#include "core/Template.h"
    3636#include "core/XMLPort.h"
     37#include "tools/Shader.h"
     38#include "util/Math.h"
     39
     40#include "graphics/Camera.h"
    3741#include "items/Engine.h"
    38 #include "graphics/Camera.h"
     42
    3943#include "CameraManager.h"
    40 #include "util/Math.h"
     44#include "Scene.h"
    4145
    4246namespace orxonox
     
    4549    CreateFactory(SpaceShip);
    4650
    47     SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
     51    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator), boostBlur_(NULL)
    4852    {
    4953        RegisterObject(SpaceShip);
     
    5761        this->bBoost_ = false;
    5862        this->steering_ = Vector3::ZERO;
    59         this->engine_ = 0;
    6063
    6164        this->boostPower_ = 10.0f;
     
    7679        this->enableCollisionCallback();
    7780
     81        this->engineTicksNotDone = 0;
    7882        this->setConfigValues();
    7983        this->registerVariables();
     
    8993    SpaceShip::~SpaceShip()
    9094    {
    91         if (this->isInitialized() && this->engine_)
    92             this->engine_->destroy();
     95        if (this->isInitialized())
     96        {
     97            this->removeAllEngines();
     98       
     99            if (this->boostBlur_)
     100                this->boostBlur_->destroy();
     101        }
    93102    }
    94103
     
    97106        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    98107
    99         XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
     108        //XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    100109        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    101110        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     
    105114        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    106115        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
    107         XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
     116                XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
    108117        XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
     118
     119        XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode);
    109120    }
    110121
     
    126137    {
    127138        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
     139       
     140        SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
     141            .description("Enable or disable the motion blur effect when moving very fast")
     142            .callback(this, &SpaceShip::changedEnableMotionBlur);
     143        SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)
     144            .description("Defines the strength of the motion blur effect");
    128145    }
    129146
     
    146163        if (this->hasLocalController())
    147164        {
    148 
    149 /*
    150             this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
    151             this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
    152             if (this->localLinearAcceleration_.z() > 0)
    153                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    154             else
    155                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    156             this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    157             this->localLinearAcceleration_.setValue(0, 0, 0);
    158 */
     165            // Handle mouse look
    159166            if (!this->isInMouseLook())
    160167            {
     
    162169                this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    163170            }
    164 
    165171            this->localAngularAcceleration_.setValue(0, 0, 0);
    166172
     173            // Charge boostPower
    167174            if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_)
    168175            {
    169176                this->boostPower_ += this->boostPowerRate_*dt;
    170177            }
    171 
     178            // Use boostPower
    172179            if(this->bBoost_)
    173180            {
     
    178185                    this->bBoostCooldown_ = true;
    179186                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
    180 
    181187                }
    182188
    183189                this->shakeCamera(dt);
     190            }
     191
     192            // Enable Blur depending on settings
     193            if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController())
     194            {
     195                this->boostBlur_ = new Shader(this->getScene()->getSceneManager());
     196                this->boostBlur_->setCompositorName("Radial Blur");
     197            }
     198
     199            if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1)
     200            {
     201                // TODO: this->maxSpeedFront_ gets fastest engine
     202                float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f);
     203
     204                // Show and hide blur effect depending on state of booster
     205                if(this->bBoost_)
     206                    this->boostBlur_->setVisible(blur > 0);
     207                else
     208                    this->boostBlur_->setVisible(false);
     209
     210                this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
    184211            }
    185212        }
     
    239266        if(bBoost && !this->bBoostCooldown_)
    240267        {
    241             //COUT(0) << "Boost startet!\n";
    242268            this->bBoost_ = true;
    243269            Camera* camera = CameraManager::getInstance().getActiveCamera();
     
    247273        if(!bBoost)
    248274        {
    249             //COUT(0) << "Boost stoppt\n";
     275            this->bBoost_ = false;
    250276            this->resetCamera();
    251             this->bBoost_ = false;
    252         }
    253     }
    254    
     277        }
     278    }
     279
    255280    void SpaceShip::boostCooledDown(void)
    256281    {
     
    310335    }
    311336
    312     void SpaceShip::loadEngineTemplate()
    313     {
    314         if (!this->enginetemplate_.empty())
    315         {
    316             Template* temp = Template::getTemplate(this->enginetemplate_);
    317 
    318             if (temp)
    319             {
    320                 Identifier* identifier = temp->getBaseclassIdentifier();
    321 
    322                 if (identifier)
    323                 {
    324                     BaseObject* object = identifier->fabricate(this);
    325                     this->engine_ = orxonox_cast<Engine*>(object);
    326 
    327                     if (this->engine_)
    328                     {
    329                         this->engine_->addTemplate(temp);
    330                         this->engine_->addToSpaceShip(this);
    331                     }
    332                     else
    333                     {
    334                         object->destroy();
    335                     }
    336                 }
    337             }
    338         }
    339     }
    340 
    341     void SpaceShip::setEngine(Engine* engine)
    342     {
    343         this->engine_ = engine;
    344         if (engine && engine->getShip() != this)
    345             engine->addToSpaceShip(this);
     337    void SpaceShip::addEngine(orxonox::Engine* engine)
     338    {
     339        //COUT(0)<<"Adding an Engine: " << engine << endl;
     340        this->engineList_.push_back(engine);
     341        engine->addToSpaceShip(this);
     342        this->resetEngineTicks();
     343    }
     344
     345    bool SpaceShip::hasEngine(Engine* engine)
     346    {
     347        for(unsigned int i=0; i<this->engineList_.size(); i++)
     348        {
     349            if(this->engineList_[i]==engine)
     350                return true;
     351        }
     352        return false;
     353    }
     354
     355    Engine* SpaceShip::getEngine(unsigned int i)
     356    {
     357        if(this->engineList_.size()>=i)
     358            return 0;
     359        else
     360            return this->engineList_[i];
     361    }
     362
     363    void SpaceShip::removeAllEngines()
     364    {
     365        for(unsigned int i=0; i<this->engineList_.size(); i++)
     366            this->engineList_[i]->~Engine();
     367    }
     368
     369    void SpaceShip::setSpeedFactor(float factor)
     370    {
     371        for(unsigned int i=0; i<this->engineList_.size(); i++)
     372            this->engineList_[i]->setSpeedFactor(factor);
     373    }
     374    float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor.
     375    {
     376        float ret = 0; unsigned int i = 0;
     377        for(; i<this->engineList_.size(); i++)
     378            ret += this->engineList_[i]->getSpeedFactor();
     379        ret /= (float)i;
     380        return ret;
     381    }
     382    float SpaceShip::getMaxSpeedFront()
     383    {
     384        float ret=0;
     385        for(unsigned int i=0; i<this->engineList_.size(); i++)
     386        {
     387            if(this->engineList_[i]->getMaxSpeedFront() > ret)
     388                ret = this->engineList_[i]->getMaxSpeedFront();
     389        }
     390        return ret;
     391    }
     392
     393    float SpaceShip::getBoostFactor()
     394    {
     395        float ret = 0; unsigned int i=0;
     396        for(; i<this->engineList_.size(); i++)
     397            ret += this->engineList_[i]->getBoostFactor();
     398        ret /= (float)i;
     399        return ret;
    346400    }
    347401
     
    349403    {
    350404        std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
    351         list->push_back(this->engine_);
     405        for(unsigned int i=0; i<this->engineList_.size(); i++)
     406            list->push_back(this->engineList_[i]);
    352407        return list;
    353408    }
    354409   
     410    void SpaceShip::changedEnableMotionBlur()
     411    {
     412        if (!this->bEnableMotionBlur_)
     413        {
     414            this->boostBlur_->destroy();
     415            this->boostBlur_ = 0;
     416        }
     417    }
    355418
    356419}
  • code/branches/presentation/src/orxonox/worldentities/pawns/SpaceShip.h

    r8582 r8589  
    6161            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 removeAllEngines();
     69
     70            void setSpeedFactor(float factor);
     71            float getSpeedFactor(); // Gets mean speed factor
     72            float getMaxSpeedFront(); // gets largest speed forward
     73            float getBoostFactor(); // gets mean boost factor
    6674
    6775            inline void setSteeringDirection(const Vector3& direction)
     
    6977            inline const Vector3& getSteeringDirection() const
    7078                { return this->steering_; }
     79            inline void resetEngineTicks()
     80                { this->engineTicksNotDone = this->engineList_.size(); }
     81            inline void oneEngineTickDone()
     82                { this->engineTicksNotDone--; }
     83            inline const bool hasEngineTicksRemaining()
     84                { return (this->engineTicksNotDone>0); }
    7185
    7286            inline bool getBoost() const
    7387                { return this->bBoost_; }
    74 
    75             inline void setEngineTemplate(const std::string& temp)
    76                 { this->enginetemplate_ = temp; this->loadEngineTemplate(); }
    77             inline const std::string& getEngineTemplate() const
    78                 { return this->enginetemplate_; }
    7988
    8089        protected:
     
    102111            void registerVariables();
    103112            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    104 
    105             void loadEngineTemplate();
    106113           
     114            //All things booster
     115            void changedEnableMotionBlur();
    107116            void boostCooledDown(void);
    108117       
     
    111120            void shakeCamera(float dt);
    112121
    113             std::string enginetemplate_;
    114             Engine* engine_;
     122            Shader* boostBlur_;
     123            float blurStrength_;
     124            bool bEnableMotionBlur_;
     125
     126            std::vector<Engine*> engineList_;
     127            int engineTicksNotDone; // Used for knowing when to reset temporary variables.
    115128            Timer timer_;
    116129            Vector3 cameraOriginalPosition_;
Note: See TracChangeset for help on using the changeset viewer.