Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2011, 2:59:07 PM (13 years ago)
Author:
decryphe
Message:
  • Moved handling of blur effect from Engine.cc to SpaceShip.cc.
  • Implemented handling of multiple engines per SpaceShip, so that in future it would be possible to turn single engines on/off individually (for example if one gets destroyed on a big ship).
  • Updated some pointers accessing the single Engine of a SpaceShip to ask the SpaceShip itself instead for data.
File:
1 edited

Legend:

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

    r7860 r8426  
    3737#include "items/Engine.h"
    3838
     39// New as of Booster integration
     40#include "Scene.h"
     41#include "tools/Shader.h"
     42
    3943namespace orxonox
    4044{
     
    5357        this->localAngularAcceleration_.setValue(0, 0, 0);
    5458        this->bBoost_ = false;
    55         this->bPermanentBoost_ = false;
    5659        this->steering_ = Vector3::ZERO;
    57         this->engine_ = 0;
     60        //this->engine_ = 0;
     61               
     62        this->boostBlur_ = 0;
    5863
    5964        this->boostPower_ = 10.0f;
     
    7479        this->enableCollisionCallback();
    7580
     81                this->engineTicksNotDone = 0;
    7682        this->setConfigValues();
    7783        this->registerVariables();
     
    8086    SpaceShip::~SpaceShip()
    8187    {
    82         if (this->isInitialized() && this->engine_)
    83             this->engine_->destroy();
     88        if (this->isInitialized())
     89            this->removeAllEngines();
     90               
     91        if (this->boostBlur_)
     92            this->boostBlur_->destroy();
    8493    }
    8594
     
    8897        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    8998
    90         XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
     99        //XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    91100        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    92101        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     
    96105        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    97106        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
     107
     108                XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode);
    98109    }
    99110
     
    103114        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    104115        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
     116        registerVariable(this->boostPower_, VariableDirection::ToClient);
     117        registerVariable(this->boostPowerRate_, VariableDirection::ToClient);
     118        registerVariable(this->boostRate_, VariableDirection::ToClient);
     119        registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient);
    105120    }
    106121
     
    108123    {
    109124        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
     125               
     126        SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
     127            .description("Enable or disable the motion blur effect when moving very fast")
     128            .callback(this, &SpaceShip::changedEnableMotionBlur);
     129        SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)
     130            .description("Defines the strength of the motion blur effect");
    110131    }
    111132
     
    128149        if (this->hasLocalController())
    129150        {
    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 */
     151                        // Handle mouse look
    140152            if (!this->isInMouseLook())
    141153            {
     
    143155                this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    144156            }
    145 
    146157            this->localAngularAcceleration_.setValue(0, 0, 0);
    147158
     159                        // Charge boostPower
    148160            if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_)
    149161            {
    150162                this->boostPower_ += this->boostPowerRate_*dt;
    151163            }
     164                        // Use boostPower
    152165            if(this->bBoost_)
    153166            {
     
    160173                }
    161174            }
     175
     176                        // Enable Blur depending on settings
     177                        if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController())
     178                        {
     179                                this->boostBlur_ = new Shader(this->getScene()->getSceneManager());
     180                                this->boostBlur_->setCompositorName("Radial Blur");
     181                        }
     182
     183                        if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1)
     184                        {
     185                                // TODO: this->maxSpeedFront_ gets fastest engine
     186                                float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f);
     187
     188                                // Show and hide blur effect depending on state of booster
     189                                if(this->bBoost_)
     190                                        this->boostBlur_->setVisible(blur > 0);
     191                                else
     192                                        this->boostBlur_->setVisible(false);
     193
     194                                this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
     195                        }
    162196        }
    163197    }
     
    207241    }
    208242
    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_)
    213             return;
    214 
    215         if(bBoost)
    216             this->boost();
    217         else
     243    void SpaceShip::fire()
     244    {
     245    }
     246
     247    /**
     248    @brief
     249        Starts or stops boosting.
     250    @param bBoost
     251        Whether to start or stop boosting.
     252    */
     253    void SpaceShip::boost(bool bBoost)
     254    {
     255        if(bBoost && !this->bBoostCooldown_)
     256            this->bBoost_ = true;
     257        if(!bBoost)
     258            this->bBoost_ = false;
     259    }
     260
     261        void SpaceShip::addEngine(orxonox::Engine* engine)
     262        {
     263                //COUT(0)<<"Adding an Engine: " << engine << endl;
     264                this->engineList_.push_back(engine);
     265                engine->addToSpaceShip(this);
     266                this->resetEngineTicks();
     267        }
     268        bool SpaceShip::hasEngine(Engine* engine)
     269        {
     270                for(unsigned int i=0; i<this->engineList_.size(); i++)
     271                {
     272                        if(this->engineList_[i]==engine)
     273                                return true;
     274                }
     275                return false;
     276        }
     277        Engine* SpaceShip::getEngine(unsigned int i)
     278        {
     279                if(this->engineList_.size()>=i)
     280                        return 0;
     281                else
     282                        return this->engineList_[i];
     283        }
     284        void SpaceShip::removeAllEngines()
     285        {
     286                for(unsigned int i=0; i<this->engineList_.size(); i++)
     287                        this->engineList_[i]->~Engine();
     288        }
     289
     290        void SpaceShip::setSpeedFactor(float factor)
     291        {
     292                for(unsigned int i=0; i<this->engineList_.size(); i++)
     293                        this->engineList_[i]->setSpeedFactor(factor);
     294        }
     295        float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor.
     296        {
     297                float ret = 0; unsigned int i = 0;
     298                for(; i<this->engineList_.size(); i++)
     299                        ret += this->engineList_[i]->getSpeedFactor();
     300                ret /= (float)i;
     301                return ret;
     302        }
     303        float SpaceShip::getMaxSpeedFront()
     304        {
     305                float ret=0;
     306                for(unsigned int i=0; i<this->engineList_.size(); i++)
     307                {
     308                        if(this->engineList_[i]->getMaxSpeedFront() > ret)
     309                                ret = this->engineList_[i]->getMaxSpeedFront();
     310                }
     311                return ret;
     312        }
     313        float SpaceShip::getBoostFactor()
     314        {
     315                float ret = 0; unsigned int i=0;
     316                for(; i<this->engineList_.size(); i++)
     317                        ret += this->engineList_[i]->getBoostFactor();
     318                ret /= (float)i;
     319                return ret;
     320        }
     321
     322    std::vector<PickupCarrier*>* SpaceShip::getCarrierChildren(void) const
     323    {
     324        std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
     325                for(unsigned int i=0; i<this->engineList_.size(); i++)
     326                        list->push_back(this->engineList_[i]);
     327        return list;
     328    }
     329       
     330        void SpaceShip::changedEnableMotionBlur()
     331    {
     332        if (!this->bEnableMotionBlur_)
    218333        {
    219             this->bBoost_ = false;
     334            this->boostBlur_->destroy();
     335            this->boostBlur_ = 0;
    220336        }
    221337    }
    222338
    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);
    267     }
    268 
    269     std::vector<PickupCarrier*>* SpaceShip::getCarrierChildren(void) const
    270     {
    271         std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();
    272         list->push_back(this->engine_);
    273         return list;
    274     }
    275339}
Note: See TracChangeset for help on using the changeset viewer.