Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8490


Ignore:
Timestamp:
May 16, 2011, 3:52:31 PM (13 years ago)
Author:
dboehi
Message:

Updated version of the camera shake effect, now based on sin.

Location:
code/branches/gameimmersion/src/orxonox/worldentities/pawns
Files:
2 edited

Legend:

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

    r8427 r8490  
    3838#include "graphics/Camera.h"
    3939#include "CameraManager.h"
     40#include "util/Math.h"
    4041
    4142namespace orxonox
     
    8283        this->cameraOriginalOrientation = c->getOrientation();
    8384
    84         this->shakeFrequency_ = 50;
    85         this->shakeAmplitude_ = 40;
     85        this->shakeFrequency_ = 15;
     86        this->shakeAmplitude_ = 5;
    8687        this->shakeDt_ = 0;
    8788    }
     
    117118        registerVariable(this->boostRate_, VariableDirection::ToClient);
    118119        registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient);
     120        registerVariable(this->shakeFrequency_, VariableDirection::ToClient);
    119121    }
    120122
     
    179181                   
    180182                }
    181                 if (this->getVelocity().squaredLength() > 20)
    182                 {
    183                         this->shakeDt_ += dt;
    184                        
    185                         Camera* c = this->getCamera();
    186                        
    187                         this->shakeFrequency_ = this->getVelocity().squaredLength() / 10000;
    188                        
    189                         COUT(0) << "ShakeFrequency: " << this->shakeFrequency_ << std::endl;
    190 
    191                         //Shaking Camera effect
    192                         if (c != 0)
    193                         {
    194                                 c->setAngularVelocity(Vector3(shakeFrequency_,0 , 0));
    195 
    196                                 //if (c->getAngularVelocity() == Vector3(0,0,0))
    197                                 //{
    198                                 //      c->setAngularVelocity(Vector3(2,0,0));
    199 
    200                                         //set the delta to half the period time,
    201                                         //so the camera shakes up and down.
    202                                 //      this->shakeDt_ = 1/(2 * this->shakeFrequency_);
    203                                 //}
    204 
    205 
    206                                 //toggle the rotation
    207                                 if (1/(this->shakeFrequency_) <= shakeDt_)
    208                                 {
    209                                         c->setAngularVelocity(-c->getAngularVelocity());
    210                                         shakeDt_ = 0;
    211                                 }
    212                         }
    213                 }
     183               
     184                shakeCamera(dt);               
    214185            }
    215186        }
     187    }
     188   
     189    void SpaceShip::shakeCamera(float dt)
     190    {
     191            if (this->getVelocity().squaredLength() > 80)
     192            {
     193                    this->shakeDt_ += dt;
     194                   
     195                    int frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength());
     196                   
     197                    if (this->shakeDt_ >= 1 /(frequency))
     198                    {
     199                            this->shakeDt_ -= 1/(frequency);
     200                    }
     201                   
     202                    Degree angle = Degree(sin(this->shakeDt_ * 2* math::pi * frequency) * this->shakeAmplitude_);
     203                       
     204//                  COUT(0) << "Angle: " << angle << std::endl;
     205                    Camera* c = this->getCamera();
     206
     207                        //Shaking Camera effect
     208                    if (c != 0)
     209                    {
     210                        c->setOrientation(Vector3::UNIT_X, angle);
     211                    }
     212            }
    216213    }
    217214
     
    274271    {   
    275272        if(bBoost && !this->bBoostCooldown_)
     273        {
     274//          COUT(0) << "Boost startet!\n";
    276275            this->bBoost_ = true;
     276        }
    277277        if(!bBoost)
    278278        {
     279//          COUT(0) << "Boost stoppt\n";
    279280            this->resetCamera();
    280281            this->bBoost_ = false;
     
    327328    void SpaceShip::resetCamera()
    328329    {
    329             //COUT(0) << "Resetting camera\n";
     330           
     331//          COUT(0) << "Resetting camera\n";
    330332            Camera *c = this->getCamera();
    331333         
     
    337339           
    338340            shakeDt_ = 0;
    339            
    340             c->setAngularVelocity(Vector3(0,0,0));
     341//         
    341342            c->setPosition(this->cameraOriginalPosition);
    342343            c->setOrientation(this->cameraOriginalOrientation);
  • code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h

    r8379 r8490  
    109109           
    110110            void resetCamera();
     111            void shakeCamera(float dt);
    111112
    112113            std::string enginetemplate_;
Note: See TracChangeset for help on using the changeset viewer.