Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 2, 2009, 4:52:42 PM (14 years ago)
Author:
youngk
Message:

Implemented speed dependent audio pitch. BUG pitching doesn't currently work.

Location:
code/branches/presentation2/src/orxonox/items
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc

    r6187 r6202  
    4141#include "worldentities/EffectContainer.h"
    4242#include "worldentities/pawns/SpaceShip.h"
     43#include "sound/WorldSound.h"
    4344
    4445namespace orxonox
    4546{
    4647    static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20;
     48    static const float MAX_VELOCITY_NORMAL = 111;
     49    static const float MAX_VELOCITY_BOOST = 221;
    4750
    4851    CreateFactory(MultiStateEngine);
     
    5154    {
    5255        RegisterObject(MultiStateEngine);
     56
     57        defEngineSndNormal_ = new WorldSound(this);
     58        defEngineSndNormal_->setLooping(true);
    5359
    5460        this->lua_ = new LuaState();
     
    6672                for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2)
    6773                    (*it2)->destroy();
     74            delete this->defEngineSndNormal_;
    6875            delete this->lua_;
    6976        }
     
    7481        SUPER(MultiStateEngine, XMLPort, xmlelement, mode);
    7582        XMLPortObject(MultiStateEngine, EffectContainer, "",  addEffectContainer,  getEffectContainer,  xmlelement, mode);
     83        XMLPortParam(MultiStateEngine, "defEngineSndNormal",  setDefEngSndNormal,  getDefEngSndNormal,  xmlelement, mode);
    7684    }
    7785
     
    92100                const Vector3& velocity = this->getShip()->getLocalVelocity();
    93101
     102                float pitch = velocity.length();
    94103                bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
    95104
    96105                int newState = 0;
    97106                if (this->getShip()->getBoost() && forward)
     107                {
    98108                    newState = Boost;
     109                    pitch = pitch/MAX_VELOCITY_BOOST + 1;
     110                    pitch = pitch > 2 ? 2 : pitch;
     111                    pitch = pitch < 0.5 ? 0.5 : pitch;
     112                    defEngineSndNormal_->setPitch(pitch);
     113                }
    99114                else if (forward && !newState) // newState == Boost
     115                {
    100116                    newState = Normal;
     117                    pitch = pitch/MAX_VELOCITY_NORMAL + 1;
     118                    pitch = pitch > 2 ? 2 : pitch;
     119                    pitch = pitch < 0.5 ? 0.5 : pitch;
     120                    defEngineSndNormal_->setPitch(pitch);
     121                }
    101122                else if (direction.z > 0 && velocity.z < 0)
    102123                    newState = Brake;
     
    116137                        lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal);
    117138                        lua_setglobal(this->lua_->getInternalLuaState(), "normal");
     139                        if(newState & Normal)
     140                        {
     141                            defEngineSndNormal_->play();
     142                        }
     143                        else
     144                        {
     145                            defEngineSndNormal_->stop();
     146                        }
    118147                    }
    119148                    if (changes & Brake)
     
    150179        if (!ship)
    151180            return;
     181
     182        this->getShip()->attach(defEngineSndNormal_);
    152183
    153184        for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     
    179210        return NULL;
    180211    }
     212
     213    void MultiStateEngine::setDefEngSndNormal(const std::string &engineSound)
     214    {
     215        defEngineSndNormal_->setSource(engineSound);
     216    }
     217
     218    const std::string& MultiStateEngine::getDefEngSndNormal()
     219    {
     220        return defEngineSndNormal_->getSource();
     221    }
    181222}
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.h

    r6187 r6202  
    6464            void addEffectContainer(EffectContainer* effect);
    6565            EffectContainer* getEffectContainer(unsigned int index) const;
     66            void setDefEngSndNormal(const std::string& engineSound);
     67            const std::string& getDefEngSndNormal();
    6668
    6769        private:
     
    6971            LuaState* lua_;
    7072            std::vector<EffectContainer*> effectContainers_;
     73            WorldSound* defEngineSndNormal_;
    7174    };
    7275}
Note: See TracChangeset for help on using the changeset viewer.