Changeset 8426 for code/branches/bigships/src/orxonox/worldentities
- Timestamp:
- May 9, 2011, 2:59:07 PM (14 years ago)
- Location:
- code/branches/bigships/src/orxonox/worldentities
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/bigships/src/orxonox/worldentities/ControllableEntity.cc
r7892 r8426 84 84 this->client_angular_velocity_ = Vector3::ZERO; 85 85 86 87 86 this->setConfigValues(); 88 87 this->setPriority( Priority::VeryHigh ); -
code/branches/bigships/src/orxonox/worldentities/ControllableEntity.h
r7889 r8426 93 93 virtual void reload() {} 94 94 95 virtual void boost() {} 95 /** 96 @brief Tells the ControllableEntity to either start or stop boosting. 97 This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will. 98 @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop. 99 */ 100 virtual void boost(bool bBoost) {} 101 96 102 virtual void greet() {} 97 103 virtual void switchCamera(); -
code/branches/bigships/src/orxonox/worldentities/MobileEntity.cc
r7163 r8426 143 143 { 144 144 if (this->isDynamic()) 145 { 145 146 this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass())); 146 147 } 148 149 // If not bullet-managed (deprecated? SpaceShip doesn't use this anymore for movement) 147 150 this->linearAcceleration_ = acceleration; 148 151 } 152 153 void MobileEntity::addAcceleration(const Vector3 &acceleration, const Vector3 &relativePosition) 154 { 155 if(this->isDynamic()) 156 { 157 this->physicalBody_->applyForce(this->getMass() * btVector3(acceleration.x, acceleration.y, acceleration.z), btVector3(relativePosition.x, relativePosition.y, relativePosition.z)); 158 } 159 } 149 160 150 161 void MobileEntity::setAngularAcceleration(const Vector3& acceleration) -
code/branches/bigships/src/orxonox/worldentities/MobileEntity.h
r5781 r8426 70 70 { return this->linearAcceleration_; } 71 71 72 // Added for making N engines work with spaceships 73 void addAcceleration(const Vector3& acceleration, const Vector3 &relativePosition); 74 inline void addAcceleration(float x, float y, float z) 75 { this->addAcceleration(Vector3(x, y, z), Vector3(0,0,0)); } 76 // Getter function above 77 72 78 void setAngularAcceleration(const Vector3& acceleration); 73 79 inline void setAngularAcceleration(float x, float y, float z) -
code/branches/bigships/src/orxonox/worldentities/pawns/SpaceShip.cc
r7860 r8426 37 37 #include "items/Engine.h" 38 38 39 // New as of Booster integration 40 #include "Scene.h" 41 #include "tools/Shader.h" 42 39 43 namespace orxonox 40 44 { … … 53 57 this->localAngularAcceleration_.setValue(0, 0, 0); 54 58 this->bBoost_ = false; 55 this->bPermanentBoost_ = false;56 59 this->steering_ = Vector3::ZERO; 57 this->engine_ = 0; 60 //this->engine_ = 0; 61 62 this->boostBlur_ = 0; 58 63 59 64 this->boostPower_ = 10.0f; … … 74 79 this->enableCollisionCallback(); 75 80 81 this->engineTicksNotDone = 0; 76 82 this->setConfigValues(); 77 83 this->registerVariables(); … … 80 86 SpaceShip::~SpaceShip() 81 87 { 82 if (this->isInitialized() && this->engine_) 83 this->engine_->destroy(); 88 if (this->isInitialized()) 89 this->removeAllEngines(); 90 91 if (this->boostBlur_) 92 this->boostBlur_->destroy(); 84 93 } 85 94 … … 88 97 SUPER(SpaceShip, XMLPort, xmlelement, mode); 89 98 90 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode);99 //XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 91 100 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 92 101 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); … … 96 105 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 97 106 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 107 108 XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode); 98 109 } 99 110 … … 103 114 registerVariable(this->auxilaryThrust_, VariableDirection::ToClient); 104 115 registerVariable(this->rotationThrust_, VariableDirection::ToClient); 116 registerVariable(this->boostPower_, VariableDirection::ToClient); 117 registerVariable(this->boostPowerRate_, VariableDirection::ToClient); 118 registerVariable(this->boostRate_, VariableDirection::ToClient); 119 registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient); 105 120 } 106 121 … … 108 123 { 109 124 SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); 125 126 SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true) 127 .description("Enable or disable the motion blur effect when moving very fast") 128 .callback(this, &SpaceShip::changedEnableMotionBlur); 129 SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f) 130 .description("Defines the strength of the motion blur effect"); 110 131 } 111 132 … … 128 149 if (this->hasLocalController()) 129 150 { 130 /* 131 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 132 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 133 if (this->localLinearAcceleration_.z() > 0) 134 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 135 else 136 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 137 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 138 this->localLinearAcceleration_.setValue(0, 0, 0); 139 */ 151 // Handle mouse look 140 152 if (!this->isInMouseLook()) 141 153 { … … 143 155 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 144 156 } 145 146 157 this->localAngularAcceleration_.setValue(0, 0, 0); 147 158 159 // Charge boostPower 148 160 if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_) 149 161 { 150 162 this->boostPower_ += this->boostPowerRate_*dt; 151 163 } 164 // Use boostPower 152 165 if(this->bBoost_) 153 166 { … … 160 173 } 161 174 } 175 176 // Enable Blur depending on settings 177 if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController()) 178 { 179 this->boostBlur_ = new Shader(this->getScene()->getSceneManager()); 180 this->boostBlur_->setCompositorName("Radial Blur"); 181 } 182 183 if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1) 184 { 185 // TODO: this->maxSpeedFront_ gets fastest engine 186 float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f); 187 188 // Show and hide blur effect depending on state of booster 189 if(this->bBoost_) 190 this->boostBlur_->setVisible(blur > 0); 191 else 192 this->boostBlur_->setVisible(false); 193 194 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur); 195 } 162 196 } 163 197 } … … 207 241 } 208 242 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 243 void SpaceShip::fire() 244 { 245 } 246 247 /** 248 @brief 249 Starts or stops boosting. 250 @param bBoost 251 Whether to start or stop boosting. 252 */ 253 void SpaceShip::boost(bool bBoost) 254 { 255 if(bBoost && !this->bBoostCooldown_) 256 this->bBoost_ = true; 257 if(!bBoost) 258 this->bBoost_ = false; 259 } 260 261 void SpaceShip::addEngine(orxonox::Engine* engine) 262 { 263 //COUT(0)<<"Adding an Engine: " << engine << endl; 264 this->engineList_.push_back(engine); 265 engine->addToSpaceShip(this); 266 this->resetEngineTicks(); 267 } 268 bool SpaceShip::hasEngine(Engine* engine) 269 { 270 for(unsigned int i=0; i<this->engineList_.size(); i++) 271 { 272 if(this->engineList_[i]==engine) 273 return true; 274 } 275 return false; 276 } 277 Engine* SpaceShip::getEngine(unsigned int i) 278 { 279 if(this->engineList_.size()>=i) 280 return 0; 281 else 282 return this->engineList_[i]; 283 } 284 void SpaceShip::removeAllEngines() 285 { 286 for(unsigned int i=0; i<this->engineList_.size(); i++) 287 this->engineList_[i]->~Engine(); 288 } 289 290 void SpaceShip::setSpeedFactor(float factor) 291 { 292 for(unsigned int i=0; i<this->engineList_.size(); i++) 293 this->engineList_[i]->setSpeedFactor(factor); 294 } 295 float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor. 296 { 297 float ret = 0; unsigned int i = 0; 298 for(; i<this->engineList_.size(); i++) 299 ret += this->engineList_[i]->getSpeedFactor(); 300 ret /= (float)i; 301 return ret; 302 } 303 float SpaceShip::getMaxSpeedFront() 304 { 305 float ret=0; 306 for(unsigned int i=0; i<this->engineList_.size(); i++) 307 { 308 if(this->engineList_[i]->getMaxSpeedFront() > ret) 309 ret = this->engineList_[i]->getMaxSpeedFront(); 310 } 311 return ret; 312 } 313 float SpaceShip::getBoostFactor() 314 { 315 float ret = 0; unsigned int i=0; 316 for(; i<this->engineList_.size(); i++) 317 ret += this->engineList_[i]->getBoostFactor(); 318 ret /= (float)i; 319 return ret; 320 } 321 322 std::vector<PickupCarrier*>* SpaceShip::getCarrierChildren(void) const 323 { 324 std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>(); 325 for(unsigned int i=0; i<this->engineList_.size(); i++) 326 list->push_back(this->engineList_[i]); 327 return list; 328 } 329 330 void SpaceShip::changedEnableMotionBlur() 331 { 332 if (!this->bEnableMotionBlur_) 218 333 { 219 this->bBoost_ = false; 334 this->boostBlur_->destroy(); 335 this->boostBlur_ = 0; 220 336 } 221 337 } 222 338 223 void SpaceShip::fire()224 {225 }226 227 void SpaceShip::boost()228 {229 if(!this->bBoostCooldown_)230 this->bBoost_ = true;231 }232 233 void SpaceShip::loadEngineTemplate()234 {235 if (!this->enginetemplate_.empty())236 {237 Template* temp = Template::getTemplate(this->enginetemplate_);238 239 if (temp)240 {241 Identifier* identifier = temp->getBaseclassIdentifier();242 243 if (identifier)244 {245 BaseObject* object = identifier->fabricate(this);246 this->engine_ = orxonox_cast<Engine*>(object);247 248 if (this->engine_)249 {250 this->engine_->addTemplate(temp);251 this->engine_->addToSpaceShip(this);252 }253 else254 {255 object->destroy();256 }257 }258 }259 }260 }261 262 void SpaceShip::setEngine(Engine* engine)263 {264 this->engine_ = engine;265 if (engine && engine->getShip() != this)266 engine->addToSpaceShip(this);267 }268 269 std::vector<PickupCarrier*>* SpaceShip::getCarrierChildren(void) const270 {271 std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>();272 list->push_back(this->engine_);273 return list;274 }275 339 } -
code/branches/bigships/src/orxonox/worldentities/pawns/SpaceShip.h
r7801 r8426 59 59 60 60 virtual void fire(); 61 virtual void boost( );61 virtual void boost(bool bBoost); // Starts or stops boosting. 62 62 63 void setEngine(Engine* engine); 64 inline Engine* getEngine() const 65 { return this->engine_; } 63 void addEngine(Engine* engine); 64 bool hasEngine(Engine* engine); 65 Engine* getEngine(unsigned int i); // This one's for XMLPort 66 inline const std::vector<Engine*>& getEngineList() 67 { return this->engineList_; } 68 void removeAllEngines(); 69 70 void setSpeedFactor(float factor); 71 float getSpeedFactor(); // Gets mean speed factor 72 float getMaxSpeedFront(); // gets largest speed forward 73 float getBoostFactor(); // gets mean boost factor 66 74 67 75 inline void setSteeringDirection(const Vector3& direction) … … 69 77 inline const Vector3& getSteeringDirection() const 70 78 { return this->steering_; } 79 inline void resetEngineTicks() 80 { this->engineTicksNotDone = this->engineList_.size(); } 81 inline void oneEngineTickDone() 82 { this->engineTicksNotDone--; } 83 inline const bool hasEngineTicksRemaining() 84 { return (this->engineTicksNotDone>0); } 71 85 72 void setBoost(bool bBoost);73 86 inline bool getBoost() const 74 87 { return this->bBoost_; } 75 76 inline void setEngineTemplate(const std::string& temp)77 { this->enginetemplate_ = temp; this->loadEngineTemplate(); }78 inline const std::string& getEngineTemplate() const79 { return this->enginetemplate_; }80 81 inline void setPermanentBoost(bool bPermanent)82 { this->bPermanentBoost_ = bPermanent; }83 inline bool getPermanentBoost() const84 { return this->bPermanentBoost_; }85 88 86 89 protected: … … 90 93 bool bBoost_; 91 94 bool bBoostCooldown_; 92 bool bPermanentBoost_;93 95 float boostPower_; 94 96 float initialBoostPower_; … … 106 108 void registerVariables(); 107 109 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 108 109 void loadEngineTemplate();110 110 111 //All things booster 112 void changedEnableMotionBlur(); 111 113 void boostCooledDown(void); 112 114 113 std::string enginetemplate_; 114 Engine* engine_; 115 Shader* boostBlur_; 116 float blurStrength_; 117 bool bEnableMotionBlur_; 118 119 std::vector<Engine*> engineList_; 120 int engineTicksNotDone; // Used for knowing when to reset temporary variables. 115 121 Timer timer_; 116 122 };
Note: See TracChangeset
for help on using the changeset viewer.