- Timestamp:
- May 26, 2011, 12:58:09 AM (13 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
/code/branches/bigships (added) merged: 8426,8503-8504,8588
- Property svn:mergeinfo changed
-
code/branches/presentation/src/orxonox/worldentities/pawns/SpaceShip.cc
r8587 r8589 35 35 #include "core/Template.h" 36 36 #include "core/XMLPort.h" 37 #include "tools/Shader.h" 38 #include "util/Math.h" 39 40 #include "graphics/Camera.h" 37 41 #include "items/Engine.h" 38 #include "graphics/Camera.h" 42 39 43 #include "CameraManager.h" 40 #include " util/Math.h"44 #include "Scene.h" 41 45 42 46 namespace orxonox … … 45 49 CreateFactory(SpaceShip); 46 50 47 SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator) 51 SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator), boostBlur_(NULL) 48 52 { 49 53 RegisterObject(SpaceShip); … … 57 61 this->bBoost_ = false; 58 62 this->steering_ = Vector3::ZERO; 59 this->engine_ = 0;60 63 61 64 this->boostPower_ = 10.0f; … … 76 79 this->enableCollisionCallback(); 77 80 81 this->engineTicksNotDone = 0; 78 82 this->setConfigValues(); 79 83 this->registerVariables(); … … 89 93 SpaceShip::~SpaceShip() 90 94 { 91 if (this->isInitialized() && this->engine_) 92 this->engine_->destroy(); 95 if (this->isInitialized()) 96 { 97 this->removeAllEngines(); 98 99 if (this->boostBlur_) 100 this->boostBlur_->destroy(); 101 } 93 102 } 94 103 … … 97 106 SUPER(SpaceShip, XMLPort, xmlelement, mode); 98 107 99 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode);108 //XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 100 109 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 101 110 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); … … 105 114 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 106 115 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 107 116 XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode); 108 117 XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode); 118 119 XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode); 109 120 } 110 121 … … 126 137 { 127 138 SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); 139 140 SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true) 141 .description("Enable or disable the motion blur effect when moving very fast") 142 .callback(this, &SpaceShip::changedEnableMotionBlur); 143 SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f) 144 .description("Defines the strength of the motion blur effect"); 128 145 } 129 146 … … 146 163 if (this->hasLocalController()) 147 164 { 148 149 /* 150 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 151 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 152 if (this->localLinearAcceleration_.z() > 0) 153 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 154 else 155 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 156 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 157 this->localLinearAcceleration_.setValue(0, 0, 0); 158 */ 165 // Handle mouse look 159 166 if (!this->isInMouseLook()) 160 167 { … … 162 169 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 163 170 } 164 165 171 this->localAngularAcceleration_.setValue(0, 0, 0); 166 172 173 // Charge boostPower 167 174 if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_) 168 175 { 169 176 this->boostPower_ += this->boostPowerRate_*dt; 170 177 } 171 178 // Use boostPower 172 179 if(this->bBoost_) 173 180 { … … 178 185 this->bBoostCooldown_ = true; 179 186 this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this))); 180 181 187 } 182 188 183 189 this->shakeCamera(dt); 190 } 191 192 // Enable Blur depending on settings 193 if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController()) 194 { 195 this->boostBlur_ = new Shader(this->getScene()->getSceneManager()); 196 this->boostBlur_->setCompositorName("Radial Blur"); 197 } 198 199 if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1) 200 { 201 // TODO: this->maxSpeedFront_ gets fastest engine 202 float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f); 203 204 // Show and hide blur effect depending on state of booster 205 if(this->bBoost_) 206 this->boostBlur_->setVisible(blur > 0); 207 else 208 this->boostBlur_->setVisible(false); 209 210 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur); 184 211 } 185 212 } … … 239 266 if(bBoost && !this->bBoostCooldown_) 240 267 { 241 //COUT(0) << "Boost startet!\n";242 268 this->bBoost_ = true; 243 269 Camera* camera = CameraManager::getInstance().getActiveCamera(); … … 247 273 if(!bBoost) 248 274 { 249 //COUT(0) << "Boost stoppt\n";275 this->bBoost_ = false; 250 276 this->resetCamera(); 251 this->bBoost_ = false; 252 } 253 } 254 277 } 278 } 279 255 280 void SpaceShip::boostCooledDown(void) 256 281 { … … 310 335 } 311 336 312 void SpaceShip::loadEngineTemplate() 313 { 314 if (!this->enginetemplate_.empty()) 315 { 316 Template* temp = Template::getTemplate(this->enginetemplate_); 317 318 if (temp) 319 { 320 Identifier* identifier = temp->getBaseclassIdentifier(); 321 322 if (identifier) 323 { 324 BaseObject* object = identifier->fabricate(this); 325 this->engine_ = orxonox_cast<Engine*>(object); 326 327 if (this->engine_) 328 { 329 this->engine_->addTemplate(temp); 330 this->engine_->addToSpaceShip(this); 331 } 332 else 333 { 334 object->destroy(); 335 } 336 } 337 } 338 } 339 } 340 341 void SpaceShip::setEngine(Engine* engine) 342 { 343 this->engine_ = engine; 344 if (engine && engine->getShip() != this) 345 engine->addToSpaceShip(this); 337 void SpaceShip::addEngine(orxonox::Engine* engine) 338 { 339 //COUT(0)<<"Adding an Engine: " << engine << endl; 340 this->engineList_.push_back(engine); 341 engine->addToSpaceShip(this); 342 this->resetEngineTicks(); 343 } 344 345 bool SpaceShip::hasEngine(Engine* engine) 346 { 347 for(unsigned int i=0; i<this->engineList_.size(); i++) 348 { 349 if(this->engineList_[i]==engine) 350 return true; 351 } 352 return false; 353 } 354 355 Engine* SpaceShip::getEngine(unsigned int i) 356 { 357 if(this->engineList_.size()>=i) 358 return 0; 359 else 360 return this->engineList_[i]; 361 } 362 363 void SpaceShip::removeAllEngines() 364 { 365 for(unsigned int i=0; i<this->engineList_.size(); i++) 366 this->engineList_[i]->~Engine(); 367 } 368 369 void SpaceShip::setSpeedFactor(float factor) 370 { 371 for(unsigned int i=0; i<this->engineList_.size(); i++) 372 this->engineList_[i]->setSpeedFactor(factor); 373 } 374 float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor. 375 { 376 float ret = 0; unsigned int i = 0; 377 for(; i<this->engineList_.size(); i++) 378 ret += this->engineList_[i]->getSpeedFactor(); 379 ret /= (float)i; 380 return ret; 381 } 382 float SpaceShip::getMaxSpeedFront() 383 { 384 float ret=0; 385 for(unsigned int i=0; i<this->engineList_.size(); i++) 386 { 387 if(this->engineList_[i]->getMaxSpeedFront() > ret) 388 ret = this->engineList_[i]->getMaxSpeedFront(); 389 } 390 return ret; 391 } 392 393 float SpaceShip::getBoostFactor() 394 { 395 float ret = 0; unsigned int i=0; 396 for(; i<this->engineList_.size(); i++) 397 ret += this->engineList_[i]->getBoostFactor(); 398 ret /= (float)i; 399 return ret; 346 400 } 347 401 … … 349 403 { 350 404 std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>(); 351 list->push_back(this->engine_); 405 for(unsigned int i=0; i<this->engineList_.size(); i++) 406 list->push_back(this->engineList_[i]); 352 407 return list; 353 408 } 354 409 410 void SpaceShip::changedEnableMotionBlur() 411 { 412 if (!this->bEnableMotionBlur_) 413 { 414 this->boostBlur_->destroy(); 415 this->boostBlur_ = 0; 416 } 417 } 355 418 356 419 }
Note: See TracChangeset
for help on using the changeset viewer.