Changeset 8426 for code/branches/bigships/src/orxonox/items
- Timestamp:
- May 9, 2011, 2:59:07 PM (14 years ago)
- Location:
- code/branches/bigships/src/orxonox/items
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/bigships/src/orxonox/items/Engine.cc
r8079 r8426 35 35 #include "Scene.h" 36 36 #include "worldentities/pawns/SpaceShip.h" 37 #include " tools/Shader.h"37 #include "core/Template.h" 38 38 39 39 namespace orxonox … … 47 47 this->ship_ = 0; 48 48 this->shipID_ = OBJECTID_UNKNOWN; 49 this->relativePosition_ = Vector3(0,0,0); 49 50 50 51 this->boostFactor_ = 1.5; … … 62 63 this->accelerationUpDown_ = 0.0; 63 64 64 this->boostBlur_ = 0;65 66 65 this->speedAdd_ = 0.0; 67 66 this->speedMultiply_ = 1.0; … … 75 74 if (this->isInitialized() && this->ship_) 76 75 { 77 this->ship_->setEngine(0);78 79 if (this->boostBlur_)80 this->boostBlur_->destroy();76 //this->ship_->setEngine(0); 77 78 //if (this->boostBlur_) 79 // this->boostBlur_->destroy(); 81 80 } 82 81 } … … 98 97 XMLPortParam(Engine, "accelerationleftright", setAccelerationLeftRight, setAccelerationLeftRight, xmlelement, mode); 99 98 XMLPortParam(Engine, "accelerationupdown", setAccelerationUpDown, setAccelerationUpDown, xmlelement, mode); 99 100 XMLPortParam(Engine, "position", setRelativePosition, getRelativePosition, xmlelement, mode); 101 XMLPortParam(Engine, "template", setEngineTemplate, getEngineTemplate, xmlelement, mode); 100 102 } 101 103 102 104 void Engine::setConfigValues() 103 105 { 104 SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true)105 .description("Enable or disable the motion blur effect when moving very fast")106 .callback(this, &Engine::changedEnableMotionBlur);107 SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f)108 .description("Defines the strength of the motion blur effect");109 106 } 110 107 … … 202 199 } 203 200 204 this->ship_->setAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd()))); 205 206 if (!this->ship_->getPermanentBoost()) 207 this->ship_->setBoost(false); 208 this->ship_->setSteeringDirection(Vector3::ZERO); 209 210 if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->ship_->hasLocalController() && this->ship_->hasHumanController()) 211 { 212 this->boostBlur_ = new Shader(this->ship_->getScene()->getSceneManager()); 213 this->boostBlur_->setCompositorName("Radial Blur"); 214 } 215 216 if (this->boostBlur_ && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1) 217 { 218 float blur = this->blurStrength_ * clamp((-velocity.z - this->maxSpeedFront_) / ((this->boostFactor_ - 1) * this->maxSpeedFront_), 0.0f, 1.0f); 219 220 this->boostBlur_->setVisible(blur > 0); 221 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur); 222 } 201 // NOTE: Bullet always uses global coordinates. 202 this->ship_->addAcceleration(this->ship_->getOrientation() * (acceleration*this->getSpeedMultiply()+Vector3(0,0,-this->getSpeedAdd())), this->ship_->getOrientation() * this->relativePosition_); 203 204 205 // Hack to reset a temporary variable "direction" 206 this->ship_->oneEngineTickDone(); 207 if(!this->ship_->hasEngineTicksRemaining()) 208 { 209 this->ship_->setSteeringDirection(Vector3::ZERO); 210 this->ship_->resetEngineTicks(); 211 } 223 212 } 224 213 … … 226 215 { 227 216 SUPER(Engine, changedActivity); 228 229 if (this->boostBlur_)230 this->boostBlur_->setVisible(this->isVisible());231 217 } 232 218 … … 238 224 { 239 225 this->shipID_ = ship->getObjectID(); 240 if (ship->getEngine() != this) 241 ship->setEngine(this); 242 243 if (this->boostBlur_) 244 { 245 this->boostBlur_->destroy(); 246 this->boostBlur_ = 0; 247 } 226 if (!ship->hasEngine(this)) 227 ship->addEngine(this); 248 228 } 249 229 } … … 267 247 } 268 248 269 void Engine::changedEnableMotionBlur() 270 { 271 if (!this->bEnableMotionBlur_) 272 { 273 this->boostBlur_->destroy(); 274 this->boostBlur_ = 0; 275 } 276 } 249 void Engine::loadEngineTemplate() 250 { 251 if(!this->engineTemplate_.empty()) 252 { 253 COUT(4)<<"Loading an engine template: "<<this->engineTemplate_<<"\n"; 254 Template *temp = Template::getTemplate(this->engineTemplate_); 255 if(temp) 256 { 257 this->addTemplate(temp); 258 } 259 } 260 } 277 261 } -
code/branches/bigships/src/orxonox/items/Engine.h
r8079 r8426 54 54 inline SpaceShip* getShip() const 55 55 { return this->ship_; } 56 57 inline void setRelativePosition(const Vector3 &position) 58 { this->relativePosition_ = position; } 59 inline Vector3& getRelativePosition() 60 { return this->relativePosition_; } 56 61 57 62 inline void setBoostFactor(float factor) … … 119 124 { this->speedMultiply_=speedMultiply; } 120 125 126 127 inline void setEngineTemplate(const std::string& temp) 128 { this->engineTemplate_ = temp; this->loadEngineTemplate(); } 129 inline const std::string& getEngineTemplate() const 130 { return this->engineTemplate_; } 131 121 132 protected: 122 133 virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const 123 134 { return new std::vector<PickupCarrier*>(); } 124 135 virtual PickupCarrier* getCarrierParent(void) const; 136 137 void loadEngineTemplate(); 125 138 126 139 private: 127 140 void registerVariables(); 128 141 void networkcallback_shipID(); 129 void changedEnableMotionBlur(); 142 143 std::string engineTemplate_; 130 144 131 145 SpaceShip* ship_; 132 146 unsigned int shipID_; 147 Vector3 relativePosition_; 133 148 134 149 float boostFactor_; … … 148 163 float accelerationLeftRight_; 149 164 float accelerationUpDown_; 150 151 Shader* boostBlur_;152 float blurStrength_;153 bool bEnableMotionBlur_;154 165 }; 155 166 }
Note: See TracChangeset
for help on using the changeset viewer.