- Timestamp:
- May 25, 2011, 9:28:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/worldentities/pawns/SpaceShip.cc
r8578 r8579 36 36 #include "core/XMLPort.h" 37 37 #include "items/Engine.h" 38 #include "graphics/Camera.h"39 #include "CameraManager.h"40 #include "util/Math.h"41 38 42 39 namespace orxonox … … 56 53 this->localAngularAcceleration_.setValue(0, 0, 0); 57 54 this->bBoost_ = false; 55 this->bPermanentBoost_ = false; 58 56 this->steering_ = Vector3::ZERO; 59 57 this->engine_ = 0; … … 78 76 this->setConfigValues(); 79 77 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;88 78 } 89 79 … … 106 96 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 107 97 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 108 XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);109 XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);110 98 } 111 99 … … 115 103 registerVariable(this->auxilaryThrust_, VariableDirection::ToClient); 116 104 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);124 105 } 125 106 … … 147 128 if (this->hasLocalController()) 148 129 { 149 150 130 /* 151 131 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); … … 170 150 this->boostPower_ += this->boostPowerRate_*dt; 171 151 } 172 173 152 if(this->bBoost_) 174 153 { … … 176 155 if(this->boostPower_ <= 0.0f) 177 156 { 178 this->b oost(false);157 this->bBoost_ = false; 179 158 this->bBoostCooldown_ = true; 180 159 this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this))); 181 182 160 } 183 184 shakeCamera(dt); 185 } 186 } 161 } 162 } 163 } 164 165 void SpaceShip::boostCooledDown(void) 166 { 167 this->bBoostCooldown_ = false; 187 168 } 188 169 … … 226 207 } 227 208 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 228 223 void SpaceShip::fire() 229 224 { 230 225 } 231 226 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_) 243 230 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 moving261 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 effect278 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_);301 231 } 302 232 … … 343 273 return list; 344 274 } 345 346 347 275 }
Note: See TracChangeset
for help on using the changeset viewer.