Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Reverse merge to revert last, failed, merge. Apparently you can't partially commit a merge.

File:
1 edited

Legend:

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

    r8578 r8579  
    3636#include "core/XMLPort.h"
    3737#include "items/Engine.h"
    38 #include "graphics/Camera.h"
    39 #include "CameraManager.h"
    40 #include "util/Math.h"
    4138
    4239namespace orxonox
     
    5653        this->localAngularAcceleration_.setValue(0, 0, 0);
    5754        this->bBoost_ = false;
     55        this->bPermanentBoost_ = false;
    5856        this->steering_ = Vector3::ZERO;
    5957        this->engine_ = 0;
     
    7876        this->setConfigValues();
    7977        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;
    8878    }
    8979
     
    10696        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    10797        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
    108         XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
    109         XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
    11098    }
    11199
     
    115103        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    116104        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);
    124105    }
    125106
     
    147128        if (this->hasLocalController())
    148129        {
    149 
    150130/*
    151131            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     
    170150                this->boostPower_ += this->boostPowerRate_*dt;
    171151            }
    172 
    173152            if(this->bBoost_)
    174153            {
     
    176155                if(this->boostPower_ <= 0.0f)
    177156                {
    178                     this->boost(false);
     157                    this->bBoost_ = false;
    179158                    this->bBoostCooldown_ = true;
    180159                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
    181 
    182160                }
    183 
    184                 shakeCamera(dt);
    185             }
    186         }
     161            }
     162        }
     163    }
     164
     165    void SpaceShip::boostCooledDown(void)
     166    {
     167        this->bBoostCooldown_ = false;
    187168    }
    188169
     
    226207    }
    227208
     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
     218        {
     219            this->bBoost_ = false;
     220        }
     221    }
     222
    228223    void SpaceShip::fire()
    229224    {
    230225    }
    231226
    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";
     227    void SpaceShip::boost()
     228    {
     229        if(!this->bBoostCooldown_)
    243230            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!";
    294             return;
    295         }
    296    
    297         shakeDt_ = 0;
    298         //
    299         c->setPosition(this->cameraOriginalPosition_);
    300         c->setOrientation(this->cameraOriginalOrientation_);
    301231    }
    302232
     
    343273        return list;
    344274    }
    345    
    346 
    347275}
Note: See TracChangeset for help on using the changeset viewer.