[Orxonox-commit 3568] r8254 - code/branches/gameimmersion/src/orxonox/worldentities/pawns

dboehi at orxonox.net dboehi at orxonox.net
Mon Apr 18 16:04:40 CEST 2011


Author: dboehi
Date: 2011-04-18 16:04:40 +0200 (Mon, 18 Apr 2011)
New Revision: 8254

Modified:
   code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc
   code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h
Log:
Added possibibility to change the frequency of the shaking camera in the
space ship configuration file.



Modified: code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc
===================================================================
--- code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc	2011-04-18 13:38:20 UTC (rev 8253)
+++ code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.cc	2011-04-18 14:04:40 UTC (rev 8254)
@@ -82,9 +82,9 @@
 	this->cameraOriginalPosition = c->getPosition();
 	this->cameraOriginalOrientation = c->getOrientation();
 
-	this->shakeFrequency_ = 100;
+	this->shakeFrequency_ = 20;
 	this->shakeAmplitude_ = 40;
-	this->shakeDeltaTime_ = 0;
+	this->shakeDt_ = 0;
     }
 
     SpaceShip::~SpaceShip()
@@ -105,6 +105,7 @@
         XMLPortParamVariable(SpaceShip, "boostPowerRate", boostPowerRate_, xmlelement, mode);
         XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
         XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
+	XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
     }
 
     void SpaceShip::registerVariables()
@@ -160,7 +161,8 @@
                 this->boostPower_ += this->boostPowerRate_*dt;
             }
 
-	Camera* c = CameraManager::getInstance().getActiveCamera();
+
+	Camera* c = this->getCamera();
             if(this->bBoost_)
             {
                 this->boostPower_ -=this->boostRate_*dt;
@@ -173,7 +175,7 @@
                 }
 		else
 		{
-			this->shakeDeltaTime_ += dt;
+			this->shakeDt_ += dt;
 
 			//Shaking Camera effect
 			if (c != 0)
@@ -182,24 +184,19 @@
 				if (c->getAngularVelocity() == Vector3(0,0,0))
 				{
 					c->setAngularVelocity(Vector3(2,0,0));
-					this->shakeDeltaTime_ = 0;
+
+					//set the delta to half the period time,
+					//so the camera shakes up and down.
+					this->shakeDt_ = 1/(2 * this->shakeFrequency_);
 				}
 
 
 				//toggle the rotation
-				if (1/(this->shakeFrequency_) <= shakeDeltaTime_)
+				if (1/(this->shakeFrequency_) <= shakeDt_)
 				{
 					c->setAngularVelocity(-c->getAngularVelocity());
-					shakeDeltaTime_ = 0;
+					shakeDt_ = 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;
-				*/
 			}
 		}
             }
@@ -207,9 +204,7 @@
 	    {
 		    //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);
+		    this->resetCamera();
 	    }
         }
     }
@@ -324,4 +319,15 @@
         list->push_back(this->engine_);
         return list;
     }
+    
+    void SpaceShip::resetCamera()
+    {
+	    Camera *c = this->getCamera();
+	    
+	    assert(c != 0);
+	    
+	    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-18 13:38:20 UTC (rev 8253)
+++ code/branches/gameimmersion/src/orxonox/worldentities/pawns/SpaceShip.h	2011-04-18 14:04:40 UTC (rev 8254)
@@ -105,7 +105,6 @@
 
 	    float shakeFrequency_;
 	    float shakeAmplitude_;
-	    float shakeDeltaTime_;
 
         private:
             void registerVariables();
@@ -114,12 +113,16 @@
             void loadEngineTemplate();
             
             void boostCooledDown(void);
+	    
+	    void resetCamera();
 
             std::string enginetemplate_;
             Engine* engine_;
             Timer timer_;
 	    Vector3 cameraOriginalPosition;
 	    Quaternion cameraOriginalOrientation;
+	    
+	    float shakeDt_;
     };
 }
 




More information about the Orxonox-commit mailing list