[Orxonox-commit 3505] r8191 - code/branches/gameimmersion/src/orxonox/worldentities/pawns

dboehi at orxonox.net dboehi at orxonox.net
Mon Apr 4 16:19:58 CEST 2011


Author: dboehi
Date: 2011-04-04 16:19:57 +0200 (Mon, 04 Apr 2011)
New Revision: 8191

Modified:
   code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc
   code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h
Log:
Update version of the boost effect,
the camera is rotating up and down if the 
boost is active.


Modified: code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc
===================================================================
--- code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc	2011-04-04 14:07:54 UTC (rev 8190)
+++ code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc	2011-04-04 14:19:57 UTC (rev 8191)
@@ -81,6 +81,10 @@
 	Camera* c = CameraManager::getInstance().getActiveCamera();
 	this->cameraOriginalPosition = c->getPosition();
 	this->cameraOriginalOrientation = c->getOrientation();
+
+	this->shakeFrequency_ = 100;
+	this->shakeAmplitude_ = 40;
+	this->shakeDeltaTime_ = 0;
     }
 
     SpaceShip::~SpaceShip()
@@ -155,9 +159,10 @@
             {
                 this->boostPower_ += this->boostPowerRate_*dt;
             }
+
+	Camera* c = CameraManager::getInstance().getActiveCamera();
             if(this->bBoost_)
             {
-		Camera* c = CameraManager::getInstance().getActiveCamera();
                 this->boostPower_ -=this->boostRate_*dt;
                 if(this->boostPower_ <= 0.0f)
                 {
@@ -165,20 +170,47 @@
                     this->bBoostCooldown_ = true;
                     this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
 		    
-		    c->setVelocity(0,0,0);
-		    c->setPosition(this->cameraOriginalPosition);
-		    c->setOrientation(this->cameraOriginalOrientation);
                 }
 		else
 		{
-			//Kamera schuettelt
-			COUT(1) << "Afterburner effect\n";
+			this->shakeDeltaTime_ += dt;
+
+			//Shaking Camera effect
 			if (c != 0)
 			{
-				c->setVelocity(0.1, 2.0, 0.3);
+
+				if (c->getAngularVelocity() == Vector3(0,0,0))
+				{
+					c->setAngularVelocity(Vector3(2,0,0));
+					this->shakeDeltaTime_ = 0;
+				}
+
+
+				//toggle the rotation
+				if (1/(this->shakeFrequency_) <= shakeDeltaTime_)
+				{
+					c->setAngularVelocity(-c->getAngularVelocity());
+					shakeDeltaTime_ = 0;
+				}
+
+				
+				/*
+				COUT(1) << "Time since change: " << shakeDeltaTime_ << std::endl;
+				COUT(1) << "Rotation Rate: " << c->getRotationRate() << std::endl;
+				COUT(1) << "Angular Velocity: " << c->getAngularVelocity().length();
+				COUT(1) << std::endl;
+				*/
 			}
 		}
             }
+	    else
+	    {
+		    //reset the camera, if the boost is not active
+		    //TODO: don't call this every tick
+		    c->setAngularVelocity(Vector3(0,0,0));
+		    c->setPosition(this->cameraOriginalPosition);
+		    c->setOrientation(this->cameraOriginalOrientation);
+	    }
         }
     }
 

Modified: code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h
===================================================================
--- code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h	2011-04-04 14:07:54 UTC (rev 8190)
+++ code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h	2011-04-04 14:19:57 UTC (rev 8191)
@@ -102,6 +102,11 @@
             btVector3 localLinearAcceleration_;
             btVector3 localAngularAcceleration_;
 
+
+	    float shakeFrequency_;
+	    float shakeAmplitude_;
+	    float shakeDeltaTime_;
+
         private:
             void registerVariables();
             virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;




More information about the Orxonox-commit mailing list