Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8426


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.
Location:
code/branches/bigships
Files:
22 edited

Legend:

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

    r7845 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipassffcameras
    5    engine                 = spaceshipassffengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2120   angularDamping    = 0.9999999
    2221  >
     22    <engines>
     23      <MultiStateEngine position=" 7.6, 0, 6" template=spaceshipassffengine />
     24      <MultiStateEngine position="-7.6, 0, 0" template=spaceshipassffengine />
     25    </engines>
    2326    <attached>
    2427      <Model position="0,0,0" yaw=90 pitch=-90 roll=0 scale=4 mesh="assff.mesh" />
     
    7780    </EffectContainer>
    7881    <EffectContainer condition="not idle">
    79       <FadingBillboard mainstate=activity active=false scale=0.1 position="0, 0, 9" colour="0.2, 0.65, 1.0, 1.0" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    80 <!--
    81       <Light mainstate=visibility position=" 8, 0, 8" diffuse="0.3, 0.6, 1.0" specular="0.3, 0.6, 1.0" attenuation="600, 1.0, 0.007, 0.0002" type=point />
    82       <Light mainstate=visibility position="-8, 0, 8" diffuse="0.3, 0.6, 1.0" specular="0.3, 0.6, 1.0" attenuation="600, 1.0, 0.007, 0.0002" type=point />
    83 -->
     82      <FadingBillboard mainstate=activity active=false scale=0.1 position="7.6, 0, 9" colour="0.2, 0.65, 1.0, 1.0" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
     83      <FadingBillboard mainstate=activity active=false scale=0.1 position="-7.6, 0, 9" colour="0.2, 0.65, 1.0, 1.0" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    8484    </EffectContainer>
    8585    <EffectContainer condition="normal or brake">
     
    8787    </EffectContainer>
    8888    <EffectContainer condition="normal or boost">
    89       <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" />
    90       <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" />
     89      <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" />
     90      <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" />
    9191    </EffectContainer>
    9292    <EffectContainer condition="boost">
     
    9494      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" />
    9595    </EffectContainer>
    96     <EffectContainer condition="brake">
     96<!--    <EffectContainer condition="brake">
    9797      <FadingBillboard mainstate=activity active=false scale=0.3 position=" 8, 0, 6" colour="0.5, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    9898      <FadingBillboard mainstate=activity active=false scale=0.3 position="-8, 0, 6" colour="0.5, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
     
    100100      <FadingBillboard mainstate=activity active=false scale=0.15 position="-8, 0, 6" colour="1.0, 0.0, 0.0, 1.0" material="Flares/backlightflare" turnontime=0.5 turnofftime=0.5 />
    101101    </EffectContainer>
     102-->
    102103  </MultiStateEngine>
    103104</Template>
  • code/branches/bigships/data/levels/templates/spaceshipGhost.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipghostcameras
    5    engine                 = spaceshipghostengine
     5
    66   spawnparticlesource    = "Orxonox/fairytwirl"
    77   spawnparticleduration  = 3
     
    2121   angularDamping    = 0.9999999
    2222  >
    23 
     23    <engines>
     24      <MultiStateEngine position="0,0,0" template=spaceshipghostengine/>
     25    </engines>
    2426    <attached>
    2527      <Model position="0,0,0" scale=2 yaw=90 pitch=-90 roll=0 mesh="ghost.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipH2.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipHtwocameras
    5    engine                 = spaceshipHtwoengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2524  include("includes/weaponSettingsH2.oxi")
    2625?>
     26    <engines>
     27      <MultiStateEngine position="0,0,0" template=spaceshipHtwoengine />
    2728
     29    </engines>
    2830    <attached>
    2931      <Model position="0,0,0" yaw=90 pitch=-90 roll=0 scale3D="3,0.833,0.833" mesh="h2_green.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipHXY.oxt

    r7679 r8426  
    2121   angularDamping    = 0.9999999
    2222  >
     23    <engines>
     24      <MultiStateEngine position=" 0, 0, 0" template=spaceshipHXYengine />
     25    </engines>
    2326    <attached>
    2427      <Model position="0,0,0" yaw=180 pitch=-90 roll=0 scale=4 mesh="HXY.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipHXYSL.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipHXYcameras
    5    engine                 = spaceshipHXYengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2120   angularDamping    = 0.9999999
    2221  >
     22    <engines>
     23      <MultiStateEngine position=" 0, 0, 0" template=spaceshipHXYengine />
     24    </engines>
    2325    <attached>
    2426      <Model position="0,0,0" yaw=180 pitch=-90 roll=0 scale=4 mesh="HXY.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipPirate.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshippiratecameras
    5    engine                 = spaceshippirateengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2120   angularDamping    = 0.9999999
    2221  >
     22    <engines>
     23      <MultiStateEngine position=" 0, 0, 0" template=spaceshippirateengine />
     24    </engines>
    2325    <attached>
    2426      <Model position="0,0,0" yaw=90 pitch=-90 roll=0 scale=4 mesh="pirate.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipSwallow.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipswallowcameras
    5    engine                 = spaceshipswallowengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2120   angularDamping    = 0.9999999
    2221  >
    23 
     22    <engines>
     23      <MultiStateEngine position=" 0, 0, 0" template=spaceshipswallowengine />
     24    </engines>
    2425    <attached>
    2526      <Model position="0,0,0" scale=2 yaw=90 pitch=-90 roll=0 mesh="swallow_mat.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipTransporter.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipTransportercameras
    5    engine                 = spaceshipTransporterengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2120   angularDamping    = 0.9999999
    2221  >
     22    <engines>
     23      <MultiStateEngine position=" 0, 0, 0" template=spaceshipTransporterengine />
     24    </engines>
    2325    <attached>
    2426      <Model position="0,0,0" yaw=0 pitch=0 roll=0 scale=10 mesh="Transporter.mesh" />
  • code/branches/bigships/data/levels/templates/spaceshipTransporterSL.oxt

    r7679 r8426  
    33   hudtemplate            = spaceshiphud
    44   camerapositiontemplate = spaceshipTransportercameras
    5    engine                 = spaceshipTransporterengine
    65   spawnparticlesource    = "Orxonox/fairytwirl"
    76   spawnparticleduration  = 3
     
    2120   angularDamping    = 0.9999999
    2221  >
     22    <engines>
     23      <MultiStateEngine position=" 0, 0, 0" template=spaceshipTransporterengine />
     24    </engines>
    2325    <attached>
    2426      <Model position="0,0,0" yaw=0 pitch=0 roll=0 scale=10 mesh="Transporter.mesh" />
  • code/branches/bigships/src/modules/overlays/hud/HUDSpeedBar.cc

    r5781 r8426  
    5454        SUPER(HUDSpeedBar, tick, dt);
    5555
    56         if (this->owner_ && this->owner_->getEngine())
     56        if (this->owner_)
    5757        {
    58             float value = this->owner_->getVelocity().length() / (this->owner_->getEngine()->getMaxSpeedFront() * this->owner_->getEngine()->getSpeedFactor() * this->owner_->getEngine()->getBoostFactor());
     58            float value = this->owner_->getVelocity().length() / (this->owner_->getMaxSpeedFront() * this->owner_->getSpeedFactor() * this->owner_->getBoostFactor());
    5959            this->setValue(value);
    6060        }
  • code/branches/bigships/src/orxonox/controllers/HumanController.cc

    r8079 r8426  
    4242    extern const std::string __CC_fire_name = "fire";
    4343    extern const std::string __CC_suicide_name = "suicide";
     44    const std::string __CC_boost_name = "boost";
    4445
    4546    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
     
    5152    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    5253    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
    53     SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().keybindMode(KeybindMode::OnHold);
     54    SetConsoleCommand("HumanController", __CC_boost_name,          &HumanController::toggleBoost   ).addShortcut().keybindMode(KeybindMode::OnPress);
    5455    SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();
    5556    SetConsoleCommand("HumanController", "switchCamera",           &HumanController::switchCamera  ).addShortcut();
     
    7273
    7374        controlPaused_ = false;
     75        this->boosting_ = false;
    7476
    7577        HumanController::localController_s = this;
     
    163165    }
    164166
    165     void HumanController::boost()
    166     {
    167         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    168             HumanController::localController_s->controllableEntity_->boost();
     167    /**
     168    @brief
     169        Static method,toggles boosting.
     170    */
     171    /*static*/ void HumanController::toggleBoost()
     172    {
     173        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     174            HumanController::localController_s->toggleBoosting();
     175    }
     176   
     177    /**
     178    @brief
     179        Toggles the boosting mode.
     180        Changes the keybind mode of the boost console command and tells the ControllableEntity to boost (or not boost anymore).
     181    */
     182    void HumanController::toggleBoosting(void)
     183    {
     184        this->boosting_ = !this->boosting_;
     185       
     186        // The keybind mode of the boosting console command is onRelease if in boosting mode and onPress of not in boosting mode.
     187        if(this->boosting_)
     188            ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnRelease);
     189        else
     190            ModifyConsoleCommand(__CC_boost_name).keybindMode(KeybindMode::OnPress);
     191
     192        this->controllableEntity_->boost(this->boosting_);
    169193    }
    170194
  • code/branches/bigships/src/orxonox/controllers/HumanController.h

    r8079 r8426  
    6464            static void reload();
    6565
    66             static void boost();
     66            static void toggleBoost(); // Static method,toggles boosting.
     67            /**
     68            @brief Check whether the HumanController is in boosting mode.
     69            @return Returns true if it is, false if not.
     70            */
     71            inline bool isBoosting(void)
     72                { return this->boosting_; }
     73            void toggleBoosting(void); // Toggles the boosting mode.
     74           
    6775            static void greet();
    6876            static void switchCamera();
     
    92100            static HumanController* localController_s;
    93101            bool controlPaused_;
     102       
     103        private:
     104            bool boosting_; // Whether the HumanController is in boosting mode or not.
     105
    94106    }; // tolua_export
    95107} // tolua_export
  • code/branches/bigships/src/orxonox/gametypes/Dynamicmatch.cc

    r7284 r8426  
    151151                //Give new pig boost
    152152                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
    153                 if (spaceship && spaceship->getEngine())
    154                 {
    155                     spaceship->getEngine()->setSpeedFactor(5);
    156                     WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine());
    157                     ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
    158                     executor->setDefaultValue(0, ptr);
    159                     new Timer(10, false, executor, true);
    160                 }
     153                                grantPigBoost(spaceship);
    161154            }
    162155
     
    252245                //Give new pig boost
    253246                SpaceShip* spaceship = dynamic_cast<SpaceShip*>(victim);
    254                 if (spaceship && spaceship->getEngine())
    255                 {
    256                     spaceship->getEngine()->setSpeedFactor(5);
    257                     WeakPtr<Engine>* ptr = new WeakPtr<Engine>(spaceship->getEngine());
    258                     ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
    259                     executor->setDefaultValue(0, ptr);
    260                     new Timer(10, false, executor, true);
    261                 }
    262 
     247                grantPigBoost(spaceship);
    263248            }
    264249            // killer vs piggy
     
    321306    }
    322307
     308        void Dynamicmatch::grantPigBoost(orxonox::SpaceShip* spaceship)
     309        {
     310                // Give pig boost
     311        if (spaceship)
     312        {
     313            spaceship->setSpeedFactor(5);
     314            WeakPtr<SpaceShip>* ptr = new WeakPtr<SpaceShip>(spaceship);
     315            ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this));
     316            executor->setDefaultValue(0, ptr);
     317            new Timer(10, false, executor, true);
     318        }
     319        }
     320
    323321    void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn) //set party + colouring
    324322    {
     
    597595    }
    598596
    599     void Dynamicmatch::resetSpeedFactor(WeakPtr<Engine>* ptr)// helper function
     597    void Dynamicmatch::resetSpeedFactor(WeakPtr<SpaceShip>* ptr)// helper function
    600598    {
    601599        if (*ptr)
  • code/branches/bigships/src/orxonox/gametypes/Dynamicmatch.h

    r7163 r8426  
    7373            virtual void furtherInstructions();*/
    7474            virtual void rewardPig();
    75             void resetSpeedFactor(WeakPtr<Engine>* ptr);
     75                        void grantPigBoost(SpaceShip* spaceship); // Added this, since it's used twice on different occasions.
     76            void resetSpeedFactor(WeakPtr<SpaceShip>* ptr);
    7677            void tick (float dt);// used to end the game
    7778            SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
  • code/branches/bigships/src/orxonox/items/Engine.cc

    r8079 r8426  
    3535#include "Scene.h"
    3636#include "worldentities/pawns/SpaceShip.h"
    37 #include "tools/Shader.h"
     37#include "core/Template.h"
    3838
    3939namespace orxonox
     
    4747        this->ship_ = 0;
    4848        this->shipID_ = OBJECTID_UNKNOWN;
     49                this->relativePosition_ = Vector3(0,0,0);
    4950
    5051        this->boostFactor_ = 1.5;
     
    6263        this->accelerationUpDown_ = 0.0;
    6364
    64         this->boostBlur_ = 0;
    65 
    6665        this->speedAdd_ = 0.0;
    6766        this->speedMultiply_ = 1.0;
     
    7574        if (this->isInitialized() && this->ship_)
    7675        {
    77             this->ship_->setEngine(0);
    78 
    79             if (this->boostBlur_)
    80                 this->boostBlur_->destroy();
     76            //this->ship_->setEngine(0);
     77
     78            //if (this->boostBlur_)
     79            //    this->boostBlur_->destroy();
    8180        }
    8281    }
     
    9897        XMLPortParam(Engine, "accelerationleftright", setAccelerationLeftRight, setAccelerationLeftRight, xmlelement, mode);
    9998        XMLPortParam(Engine, "accelerationupdown",    setAccelerationUpDown,    setAccelerationUpDown,    xmlelement, mode);
     99
     100                XMLPortParam(Engine, "position", setRelativePosition, getRelativePosition, xmlelement, mode);
     101                XMLPortParam(Engine, "template", setEngineTemplate, getEngineTemplate, xmlelement, mode);
    100102    }
    101103
    102104    void Engine::setConfigValues()
    103105    {
    104         SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)
    105             .description("Enable or disable the motion blur effect when moving very fast")
    106             .callback(this, &Engine::changedEnableMotionBlur);
    107         SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)
    108             .description("Defines the strength of the motion blur effect");
    109106    }
    110107
     
    202199        }
    203200
    204         this->ship_->setAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())));
    205 
    206         if (!this->ship_->getPermanentBoost())
    207             this->ship_->setBoost(false);
    208         this->ship_->setSteeringDirection(Vector3::ZERO);
    209 
    210         if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->ship_->hasLocalController() && this->ship_->hasHumanController())
    211         {
    212             this->boostBlur_ = new Shader(this->ship_->getScene()->getSceneManager());
    213             this->boostBlur_->setCompositorName("Radial Blur");
    214         }
    215 
    216         if (this->boostBlur_ && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1)
    217         {
    218             float blur = this->blurStrength_ * clamp((-velocity.z - this->maxSpeedFront_) / ((this->boostFactor_ - 1) * this->maxSpeedFront_), 0.0f, 1.0f);
    219 
    220             this->boostBlur_->setVisible(blur > 0);
    221             this->boostBlur_->setParameter(0, 0, "sampleStrength", blur);
    222         }
     201                // NOTE: Bullet always uses global coordinates.
     202        this->ship_->addAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())), this->ship_->getOrientation() * this->relativePosition_);
     203
     204
     205                // Hack to reset a temporary variable "direction"
     206                this->ship_->oneEngineTickDone();
     207                if(!this->ship_->hasEngineTicksRemaining())
     208                {
     209                        this->ship_->setSteeringDirection(Vector3::ZERO);
     210                        this->ship_->resetEngineTicks();
     211                }
    223212    }
    224213
     
    226215    {
    227216        SUPER(Engine, changedActivity);
    228 
    229         if (this->boostBlur_)
    230             this->boostBlur_->setVisible(this->isVisible());
    231217    }
    232218
     
    238224        {
    239225            this->shipID_ = ship->getObjectID();
    240             if (ship->getEngine() != this)
    241                 ship->setEngine(this);
    242 
    243             if (this->boostBlur_)
    244             {
    245                 this->boostBlur_->destroy();
    246                 this->boostBlur_ = 0;
    247             }
     226            if (!ship->hasEngine(this))
     227                ship->addEngine(this);
    248228        }
    249229    }
     
    267247    }
    268248
    269     void Engine::changedEnableMotionBlur()
    270     {
    271         if (!this->bEnableMotionBlur_)
    272         {
    273             this->boostBlur_->destroy();
    274             this->boostBlur_ = 0;
    275         }
    276     }
     249        void Engine::loadEngineTemplate()
     250        {
     251                if(!this->engineTemplate_.empty())
     252                {
     253                        COUT(4)<<"Loading an engine template: "<<this->engineTemplate_<<"\n";
     254                        Template *temp = Template::getTemplate(this->engineTemplate_);
     255                        if(temp)
     256                        {
     257                                this->addTemplate(temp);
     258                        }
     259                }
     260        }
    277261}
  • code/branches/bigships/src/orxonox/items/Engine.h

    r8079 r8426  
    5454            inline SpaceShip* getShip() const
    5555                { return this->ship_; }
     56
     57                        inline void setRelativePosition(const Vector3 &position)
     58                                { this->relativePosition_ = position; }
     59                        inline Vector3& getRelativePosition()
     60                                { return this->relativePosition_; }
    5661
    5762            inline void setBoostFactor(float factor)
     
    119124                { this->speedMultiply_=speedMultiply; }
    120125
     126                       
     127            inline void setEngineTemplate(const std::string& temp)
     128                { this->engineTemplate_ = temp; this->loadEngineTemplate(); }
     129            inline const std::string& getEngineTemplate() const
     130                { return this->engineTemplate_; }
     131
    121132        protected:
    122133            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const
    123134                { return new std::vector<PickupCarrier*>(); }
    124135            virtual PickupCarrier* getCarrierParent(void) const;
     136                       
     137            void loadEngineTemplate();
    125138
    126139        private:
    127140            void registerVariables();
    128141            void networkcallback_shipID();
    129             void changedEnableMotionBlur();
     142
     143                        std::string engineTemplate_;
    130144
    131145            SpaceShip* ship_;
    132146            unsigned int shipID_;
     147                        Vector3 relativePosition_;
    133148
    134149            float boostFactor_;
     
    148163            float accelerationLeftRight_;
    149164            float accelerationUpDown_;
    150 
    151             Shader* boostBlur_;
    152             float blurStrength_;
    153             bool bEnableMotionBlur_;
    154165    };
    155166}
  • code/branches/bigships/src/orxonox/worldentities/ControllableEntity.cc

    r7892 r8426  
    8484        this->client_angular_velocity_ = Vector3::ZERO;
    8585
    86 
    8786        this->setConfigValues();
    8887        this->setPriority( Priority::VeryHigh );
  • code/branches/bigships/src/orxonox/worldentities/ControllableEntity.h

    r7889 r8426  
    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();
  • code/branches/bigships/src/orxonox/worldentities/MobileEntity.cc

    r7163 r8426  
    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;
    148151    }
     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                }
     159        }
    149160
    150161    void MobileEntity::setAngularAcceleration(const Vector3& acceleration)
  • code/branches/bigships/src/orxonox/worldentities/MobileEntity.h

    r5781 r8426  
    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)
  • 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}
  • code/branches/bigships/src/orxonox/worldentities/pawns/SpaceShip.h

    r7801 r8426  
    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 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
    72             void setBoost(bool bBoost);
    7386            inline bool getBoost() const
    7487                { return this->bBoost_; }
    75 
    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_; }
    80 
    81             inline void setPermanentBoost(bool bPermanent)
    82                 { this->bPermanentBoost_ = bPermanent; }
    83             inline bool getPermanentBoost() const
    84                 { return this->bPermanentBoost_; }
    8588
    8689        protected:
     
    9093            bool bBoost_;
    9194            bool bBoostCooldown_;
    92             bool bPermanentBoost_;
    9395            float boostPower_;
    9496            float initialBoostPower_;
     
    106108            void registerVariables();
    107109            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    108 
    109             void loadEngineTemplate();
    110110           
     111                        //All things booster
     112                        void changedEnableMotionBlur();
    111113            void boostCooledDown(void);
    112114
    113             std::string enginetemplate_;
    114             Engine* engine_;
     115                        Shader* boostBlur_;
     116            float blurStrength_;
     117            bool bEnableMotionBlur_;
     118
     119                        std::vector<Engine*> engineList_;
     120                        int engineTicksNotDone; // Used for knowing when to reset temporary variables.
    115121            Timer timer_;
    116122    };
Note: See TracChangeset for help on using the changeset viewer.