Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2011, 9:41:29 PM (13 years ago)
Author:
dafrick
Message:

Merging game immersion branch into presentation branch.

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

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

    r8579 r8580  
    3636#include "core/XMLPort.h"
    3737#include "items/Engine.h"
     38#include "graphics/Camera.h"
     39#include "CameraManager.h"
     40#include "util/Math.h"
    3841
    3942namespace orxonox
     
    5356        this->localAngularAcceleration_.setValue(0, 0, 0);
    5457        this->bBoost_ = false;
    55         this->bPermanentBoost_ = false;
    5658        this->steering_ = Vector3::ZERO;
    5759        this->engine_ = 0;
     
    7678        this->setConfigValues();
    7779        this->registerVariables();
     80       
     81        Camera* camera = CameraManager::getInstance().getActiveCamera();
     82        this->cameraOriginalPosition_ = camera->getPosition();
     83        this->cameraOriginalOrientation_ = camera->getOrientation();
     84
     85        this->shakeFrequency_ = 15;
     86        this->shakeAmplitude_ = 5;
     87        this->shakeDt_ = 0;
    7888    }
    7989
     
    96106        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    97107        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
     108        XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
     109        XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
    98110    }
    99111
     
    103115        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    104116        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
     117        // TODO: Synchronization of boost needed?
     118        registerVariable(this->boostPower_, VariableDirection::ToClient);
     119        registerVariable(this->boostPowerRate_, VariableDirection::ToClient);
     120        registerVariable(this->boostRate_, VariableDirection::ToClient);
     121        registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient);
     122        registerVariable(this->shakeFrequency_, VariableDirection::ToClient);
     123        registerVariable(this->shakeAmplitude_, VariableDirection::ToClient);
    105124    }
    106125
     
    128147        if (this->hasLocalController())
    129148        {
     149
    130150/*
    131151            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     
    150170                this->boostPower_ += this->boostPowerRate_*dt;
    151171            }
     172
    152173            if(this->bBoost_)
    153174            {
     
    155176                if(this->boostPower_ <= 0.0f)
    156177                {
    157                     this->bBoost_ = false;
     178                    this->boost(false);
    158179                    this->bBoostCooldown_ = true;
    159180                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
     181
    160182                }
    161             }
    162         }
    163     }
    164 
    165     void SpaceShip::boostCooledDown(void)
    166     {
    167         this->bBoostCooldown_ = false;
     183
     184                shakeCamera(dt);
     185            }
     186        }
    168187    }
    169188
     
    207226    }
    208227
    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_)
     228    void SpaceShip::fire()
     229    {
     230    }
     231
     232    /**
     233    @brief
     234        Starts or stops boosting.
     235    @param bBoost
     236        Whether to start or stop boosting.
     237    */
     238    void SpaceShip::boost(bool bBoost)
     239    {
     240        if(bBoost && !this->bBoostCooldown_)
     241        {
     242            //COUT(0) << "Boost startet!\n";
     243            this->bBoost_ = true;
     244        }
     245        if(!bBoost)
     246        {
     247            //COUT(0) << "Boost stoppt\n";
     248            this->resetCamera();
     249            this->bBoost_ = false;
     250        }
     251    }
     252   
     253    void SpaceShip::boostCooledDown(void)
     254    {
     255        this->bBoostCooldown_ = false;
     256    }
     257   
     258    void SpaceShip::shakeCamera(float dt)
     259    {
     260        //make sure the ship is only shaking if it's moving
     261        if (this->getVelocity().squaredLength() > 80)
     262        {
     263            this->shakeDt_ += dt;
     264   
     265            int frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength());
     266   
     267            if (this->shakeDt_ >= 1 /(frequency))
     268            {
     269                this->shakeDt_ -= 1/(frequency);
     270            }
     271   
     272            Degree angle = Degree(sin(this->shakeDt_ * 2* math::pi * frequency) * this->shakeAmplitude_);
     273   
     274            //COUT(0) << "Angle: " << angle << std::endl;
     275            Camera* c = this->getCamera();
     276
     277            //Shaking Camera effect
     278            if (c != 0)
     279            {
     280                c->setOrientation(Vector3::UNIT_X, angle);
     281            }
     282        }
     283    }
     284   
     285    void SpaceShip::resetCamera()
     286    {
     287   
     288        //COUT(0) << "Resetting camera\n";
     289        Camera *c = this->getCamera();
     290   
     291        if (c == 0)
     292        {
     293            COUT(2) << "Failed to reset camera!";
    213294            return;
    214 
    215         if(bBoost)
    216             this->boost();
    217         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;
     295        }
     296   
     297        shakeDt_ = 0;
     298        //
     299        c->setPosition(this->cameraOriginalPosition_);
     300        c->setOrientation(this->cameraOriginalOrientation_);
    231301    }
    232302
     
    273343        return list;
    274344    }
     345   
     346
    275347}
Note: See TracChangeset for help on using the changeset viewer.