Changeset 8706 for code/trunk/src/orxonox/worldentities
- Timestamp:
- Jun 14, 2011, 8:53:28 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/worldentities/CMakeLists.txt
r8458 r8706 12 12 SpawnPoint.cc 13 13 TeamSpawnPoint.cc 14 SpaceBoundaries.cc15 14 ) 16 15 -
code/trunk/src/orxonox/worldentities/CameraPosition.cc
r5929 r8706 46 46 this->bRenderCamera_ = false; 47 47 48 this->setSyncMode( 0x0);48 this->setSyncMode(ObjectDirection::None); 49 49 } 50 50 -
code/trunk/src/orxonox/worldentities/ControllableEntity.cc
r7892 r8706 84 84 this->client_angular_velocity_ = Vector3::ZERO; 85 85 86 87 86 this->setConfigValues(); 88 87 this->setPriority( Priority::VeryHigh ); … … 121 120 122 121 XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode); 123 XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTem kplate, xmlelement, mode);122 XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemplate, xmlelement, mode); 124 123 125 124 XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode); … … 171 170 } 172 171 return 0; 172 } 173 174 unsigned int ControllableEntity::getCurrentCameraIndex() const 175 { 176 if (this->cameraPositions_.size() <= 0) 177 return 0; 178 179 unsigned int counter = 0; 180 for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) 181 { 182 if ((*it) == this->currentCameraPosition_) 183 break; 184 counter++; 185 } 186 if (counter >= this->cameraPositions_.size()) 187 return 0; 188 189 return counter; 190 } 191 192 bool ControllableEntity::setCameraPosition(unsigned int index) 193 { 194 if(this->camera_ != NULL && this->cameraPositions_.size() > 0) 195 { 196 if(index >= this->cameraPositions_.size()) 197 index = 0; 198 199 CameraPosition* position = this->getCameraPosition(index); 200 position->attachCamera(this->camera_); 201 this->currentCameraPosition_ = position; 202 return true; 203 } 204 205 return false; 173 206 } 174 207 … … 373 406 } 374 407 408 this->createHud(); 409 } 410 411 // HACK-ish 412 void ControllableEntity::createHud(void) 413 { 375 414 if (!this->hud_ && GameMode::showsGraphics()) 376 415 { … … 381 420 this->hud_->setOwner(this); 382 421 } 422 } 423 } 424 425 void ControllableEntity::destroyHud(void) 426 { 427 if (this->hud_ != NULL) 428 { 429 this->hud_->destroy(); 430 this->hud_ = NULL; 383 431 } 384 432 } -
code/trunk/src/orxonox/worldentities/ControllableEntity.h
r7889 r8706 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(); … … 110 116 inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const 111 117 { return this->cameraPositions_; } 118 unsigned int getCurrentCameraIndex() const; 119 bool setCameraPosition(unsigned int index); 112 120 113 121 inline void setCameraPositionTemplate(const std::string& name) 114 122 { this->cameraPositionTemplate_ = name; } 115 inline const std::string& getCameraPositionTem kplate() const123 inline const std::string& getCameraPositionTemplate() const 116 124 { return this->cameraPositionTemplate_; } 117 125 … … 168 176 inline void setHudTemplate(const std::string& name) 169 177 { this->hudtemplate_ = name; } 178 // HACK-ish 179 void createHud(void); 180 void destroyHud(void); 170 181 171 182 Ogre::SceneNode* cameraPositionRootNode_; -
code/trunk/src/orxonox/worldentities/MobileEntity.cc
r7163 r8706 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; 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 } 148 159 } 149 160 -
code/trunk/src/orxonox/worldentities/MobileEntity.h
r5781 r8706 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) … … 83 89 { this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); } 84 90 inline Degree getRotationRate() const 85 { return Degree(this->getAngularVelocity().length()); }91 { return Radian(this->getAngularVelocity().length()); } 86 92 87 93 inline void setRotationAxis(const Vector3& axis) -
code/trunk/src/orxonox/worldentities/SpawnPoint.cc
r5929 r8706 50 50 COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl; 51 51 52 this->setSyncMode( 0x0);52 this->setSyncMode(ObjectDirection::None); 53 53 } 54 54 -
code/trunk/src/orxonox/worldentities/WorldEntity.cc
r7937 r8706 642 642 void WorldEntity::setScale3D(const Vector3& scale) 643 643 { 644 /* 645 HACK HACK HACK 646 if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE) 647 { 648 CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl; 649 return; 650 } 651 HACK HACK HACK 652 */ 644 // If physics is enabled scale the attached CollisionShape. 645 /*if (this->hasPhysics() && this->collisionShape_ != NULL) 646 { 647 this->collisionShape_->setScale3D(scale); 648 }*/ 649 653 650 this->node_->setScale(scale); 654 651 -
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r8351 r8706 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Simon Miescher 26 26 * 27 27 */ … … 64 64 this->maxHealth_ = 0; 65 65 this->initialHealth_ = 0; 66 66 67 this->shieldHealth_ = 0; 68 this->initialShieldHealth_ = 0; 69 this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max 67 70 this->shieldAbsorption_ = 0.5; 71 72 this->reloadRate_ = 0; 73 this->reloadWaitTime_ = 1.0f; 74 this->reloadWaitCountdown_ = 0; 68 75 69 76 this->lastHitOriginator_ = 0; … … 109 116 110 117 XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0); 118 XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0); 119 XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100); 111 120 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 112 121 … … 118 127 XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); 119 128 XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode); 129 130 XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0); 131 XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f); 120 132 } 121 133 … … 124 136 registerVariable(this->bAlive_, VariableDirection::ToClient); 125 137 registerVariable(this->health_, VariableDirection::ToClient); 126 registerVariable(this-> initialHealth_,VariableDirection::ToClient);138 registerVariable(this->maxHealth_, VariableDirection::ToClient); 127 139 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 140 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); 128 141 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 129 142 registerVariable(this->bReload_, VariableDirection::ToServer); … … 137 150 this->bReload_ = false; 138 151 152 // TODO: use the existing timer functions instead 153 if(this->reloadWaitCountdown_ > 0) 154 { 155 this->decreaseReloadCountdownTime(dt); 156 } 157 else 158 { 159 this->addShieldHealth(this->getReloadRate() * dt); 160 this->resetReloadCountdown(); 161 } 162 139 163 if (GameMode::isMaster()) 164 { 140 165 if (this->health_ <= 0 && bAlive_) 141 166 { 142 this->fireEvent(); // Event to notify anyone who want 's to know about the death.167 this->fireEvent(); // Event to notify anyone who wants to know about the death. 143 168 this->death(); 144 169 } 170 } 145 171 } 146 172 … … 168 194 } 169 195 196 170 197 void Pawn::setHealth(float health) 171 198 { 172 this->health_ = std::min(health, this->maxHealth_); 173 } 174 175 void Pawn::damage(float damage, Pawn* originator) 199 this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit 200 } 201 202 void Pawn::setShieldHealth(float shieldHealth) 203 { 204 this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_); 205 } 206 207 void Pawn::setMaxShieldHealth(float maxshieldhealth) 208 { 209 this->maxShieldHealth_ = maxshieldhealth; 210 } 211 212 void Pawn::setReloadRate(float reloadrate) 213 { 214 this->reloadRate_ = reloadrate; 215 } 216 217 void Pawn::setReloadWaitTime(float reloadwaittime) 218 { 219 this->reloadWaitTime_ = reloadwaittime; 220 } 221 222 void Pawn::decreaseReloadCountdownTime(float dt) 223 { 224 this->reloadWaitCountdown_ -= dt; 225 } 226 227 void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator) 176 228 { 177 229 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 178 230 { 179 //share the dealt damage to the shield and the Pawn. 180 float shielddamage = damage*this->shieldAbsorption_; 181 float healthdamage = damage*(1-this->shieldAbsorption_); 182 183 // In case the shield can not take all the shield damage. 184 if (shielddamage > this->getShieldHealth()) 231 if (shielddamage >= this->getShieldHealth()) 185 232 { 186 healthdamage += shielddamage-this->getShieldHealth();187 233 this->setShieldHealth(0); 234 this->setHealth(this->health_ - (healthdamage + damage)); 188 235 } 189 190 this->setHealth(this->health_ - healthdamage); 191 192 if (this->getShieldHealth() > 0) 236 else 193 237 { 194 238 this->setShieldHealth(this->shieldHealth_ - shielddamage); 239 240 // remove remaining shieldAbsorpton-Part of damage from shield 241 shielddamage = damage * this->shieldAbsorption_; 242 shielddamage = std::min(this->getShieldHealth(),shielddamage); 243 this->setShieldHealth(this->shieldHealth_ - shielddamage); 244 245 // set remaining damage to health 246 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage); 195 247 } 196 248 197 249 this->lastHitOriginator_ = originator; 198 199 // play damage effect 200 } 201 } 202 203 void Pawn::hit(Pawn* originator, const Vector3& force, float damage) 250 } 251 } 252 253 // TODO: Still valid? 254 /* HIT-Funktionen 255 Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte) 256 257 */ 258 259 void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage) 204 260 { 205 261 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 206 262 { 207 this->damage(damage, originator);263 this->damage(damage, healthdamage, shielddamage, originator); 208 264 this->setVelocity(this->getVelocity() + force); 209 210 // play hit effect 211 } 212 } 213 214 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) 265 } 266 } 267 268 269 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) 215 270 { 216 271 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 217 272 { 218 this->damage(damage, originator);273 this->damage(damage, healthdamage, shielddamage, originator); 219 274 220 275 if ( this->getController() ) 221 this->getController()->hit(originator, contactpoint, damage); 222 223 // play hit effect 224 } 225 } 276 this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? 277 } 278 } 279 226 280 227 281 void Pawn::kill() -
code/trunk/src/orxonox/worldentities/pawns/Pawn.h
r7889 r8706 72 72 { return this->initialHealth_; } 73 73 74 inline void setShieldHealth(float shieldHealth)75 { this->shieldHealth_ = shieldHealth; } 74 virtual void setShieldHealth(float shieldHealth); 75 76 76 inline float getShieldHealth() 77 77 { return this->shieldHealth_; } 78 79 inline void addShieldHealth(float amount) 80 { this->setShieldHealth(this->shieldHealth_ + amount); } 81 82 inline bool hasShield() 83 { return (this->getShieldHealth() > 0); } 84 85 virtual void setMaxShieldHealth(float maxshieldhealth); 86 inline float getMaxShieldHealth() const 87 { return this->maxShieldHealth_; } 88 89 inline void setInitialShieldHealth(float initialshieldhealth) 90 { this->initialShieldHealth_ = initialshieldhealth; this->setShieldHealth(initialshieldhealth); } 91 inline float getInitialShieldHealth() const 92 { return this->initialShieldHealth_; } 93 94 inline void restoreInitialShieldHealth() 95 { this->setShieldHealth(this->initialShieldHealth_); } 96 inline void restoreMaxShieldHealth() 97 { this->setShieldHealth(this->maxShieldHealth_); } 78 98 79 99 inline void setShieldAbsorption(float shieldAbsorption) … … 82 102 { return this->shieldAbsorption_; } 83 103 104 // TODO: Rename to shieldRechargeRate 105 virtual void setReloadRate(float reloadrate); 106 inline float getReloadRate() const 107 { return this->reloadRate_; } 108 109 virtual void setReloadWaitTime(float reloadwaittime); 110 inline float getReloadWaitTime() const 111 { return this->reloadWaitTime_; } 112 113 inline void resetReloadCountdown() 114 { this->reloadWaitCountdown_ = 0; } 115 116 inline void startReloadCountdown() 117 { this->reloadWaitCountdown_ = this->getReloadWaitTime(); } // TODO: Implement in Projectile.cc 118 119 virtual void decreaseReloadCountdownTime(float dt); 120 84 121 inline ControllableEntity* getLastHitOriginator() const 85 122 { return this->lastHitOriginator_; } 86 123 87 virtual void hit(Pawn* originator, const Vector3& force, float damage); 88 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 124 //virtual void hit(Pawn* originator, const Vector3& force, float damage); 125 //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 126 virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 127 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 128 89 129 virtual void kill(); 90 130 … … 142 182 virtual void spawneffect(); 143 183 144 virtual void damage(float damage, Pawn* originator = 0); 184 //virtual void damage(float damage, Pawn* originator = 0); 185 virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL); 145 186 146 187 bool bAlive_; … … 154 195 float maxHealth_; 155 196 float initialHealth_; 197 156 198 float shieldHealth_; 199 float maxShieldHealth_; 200 float initialShieldHealth_; 157 201 float shieldAbsorption_; // Has to be between 0 and 1 202 float reloadRate_; 203 float reloadWaitTime_; 204 float reloadWaitCountdown_; 158 205 159 206 WeakPtr<Pawn> lastHitOriginator_; -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
r7860 r8706 35 35 #include "core/Template.h" 36 36 #include "core/XMLPort.h" 37 #include "tools/Shader.h" 38 #include "util/Debug.h" // TODO: Needed? 39 #include "util/Math.h" 40 41 #include "graphics/Camera.h" 37 42 #include "items/Engine.h" 43 44 #include "CameraManager.h" 45 #include "Scene.h" 38 46 39 47 namespace orxonox … … 42 50 CreateFactory(SpaceShip); 43 51 44 SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator) 52 SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator), boostBlur_(NULL) 45 53 { 46 54 RegisterObject(SpaceShip); … … 53 61 this->localAngularAcceleration_.setValue(0, 0, 0); 54 62 this->bBoost_ = false; 55 this->bPermanentBoost_ = false;56 63 this->steering_ = Vector3::ZERO; 57 this->engine_ = 0;58 64 59 65 this->boostPower_ = 10.0f; … … 64 70 this->bBoostCooldown_ = false; 65 71 72 this->lift_ = 1.0f; // factor of the lift, standard is 1 73 this->stallSpeed_ = 220.0f; // max speed where lift is added 74 66 75 this->bInvertYAxis_ = false; 67 76 … … 74 83 this->enableCollisionCallback(); 75 84 85 this->engineTicksNotDone = 0; 76 86 this->setConfigValues(); 77 87 this->registerVariables(); 88 89 this->cameraOriginalPosition_ = Vector3::UNIT_SCALE; 90 this->cameraOriginalOrientation_ = Quaternion::IDENTITY; 91 92 this->shakeFrequency_ = 15; 93 this->shakeAmplitude_ = 5; 94 this->shakeDt_ = 0; 78 95 } 79 96 80 97 SpaceShip::~SpaceShip() 81 98 { 82 if (this->isInitialized() && this->engine_) 83 this->engine_->destroy(); 99 if (this->isInitialized()) 100 { 101 this->removeAllEngines(); 102 103 if (this->boostBlur_) 104 this->boostBlur_->destroy(); 105 } 84 106 } 85 107 … … 88 110 SUPER(SpaceShip, XMLPort, xmlelement, mode); 89 111 90 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode);112 //XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 91 113 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 92 114 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); … … 96 118 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 97 119 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 120 XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode); 121 XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode); 122 XMLPortParamVariable(SpaceShip, "lift", lift_, xmlelement, mode); 123 XMLPortParamVariable(SpaceShip, "stallSpeed", stallSpeed_, xmlelement, mode); 124 125 XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode); 98 126 } 99 127 … … 103 131 registerVariable(this->auxilaryThrust_, VariableDirection::ToClient); 104 132 registerVariable(this->rotationThrust_, VariableDirection::ToClient); 133 // TODO: Synchronization of boost needed? 134 registerVariable(this->boostPower_, VariableDirection::ToClient); 135 registerVariable(this->boostPowerRate_, VariableDirection::ToClient); 136 registerVariable(this->boostRate_, VariableDirection::ToClient); 137 registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient); 138 registerVariable(this->shakeFrequency_, VariableDirection::ToClient); 139 registerVariable(this->shakeAmplitude_, VariableDirection::ToClient); 140 registerVariable(this->lift_, VariableDirection::ToClient); 141 registerVariable(this->stallSpeed_, VariableDirection::ToClient); 105 142 } 106 143 … … 108 145 { 109 146 SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); 147 148 SetConfigValueExternal(bEnableMotionBlur_, "GraphicsSettings", "enableMotionBlur", true) 149 .description("Enable or disable the motion blur effect when moving very fast") 150 .callback(this, &SpaceShip::changedEnableMotionBlur); 151 SetConfigValueExternal(blurStrength_, "GraphicsSettings", "blurStrength", 3.0f) 152 .description("Defines the strength of the motion blur effect"); 110 153 } 111 154 … … 128 171 if (this->hasLocalController()) 129 172 { 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 */ 173 // Handle mouse look 140 174 if (!this->isInMouseLook()) 141 175 { … … 143 177 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 144 178 } 145 146 179 this->localAngularAcceleration_.setValue(0, 0, 0); 147 180 181 // Charge boostPower 148 182 if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_) 149 183 { 150 184 this->boostPower_ += this->boostPowerRate_*dt; 151 185 } 186 // Use boostPower 152 187 if(this->bBoost_) 153 188 { … … 155 190 if(this->boostPower_ <= 0.0f) 156 191 { 157 this->b Boost_ = false;192 this->boost(false); 158 193 this->bBoostCooldown_ = true; 159 194 this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this))); 160 195 } 161 } 196 197 this->shakeCamera(dt); 198 } 199 200 // Enable Blur depending on settings 201 if (this->bEnableMotionBlur_ && !this->boostBlur_ && this->hasLocalController() && this->hasHumanController()) 202 { 203 this->boostBlur_ = new Shader(this->getScene()->getSceneManager()); 204 this->boostBlur_->setCompositorName("Radial Blur"); 205 } 206 207 if (this->boostBlur_) // && this->maxSpeedFront_ != 0 && this->boostFactor_ != 1) 208 { 209 // TODO: this->maxSpeedFront_ gets fastest engine 210 float blur = this->blurStrength_ * clamp((-this->getLocalVelocity().z - 0.0f /*this->maxSpeedFront_*/) / ((150.0f /*boostFactor_*/ - 1) * 1.5f /*this->maxSpeedFront_*/), 0.0f, 1.0f); 211 212 // Show and hide blur effect depending on state of booster 213 if(this->bBoost_) 214 this->boostBlur_->setVisible(blur > 0); 215 else 216 this->boostBlur_->setVisible(false); 217 218 this->boostBlur_->setParameter(0, 0, "sampleStrength", blur); 219 } 220 } 221 } 222 223 void SpaceShip::moveFrontBack(const Vector2& value) 224 { 225 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 226 this->steering_.z -= value.x; 227 } 228 229 void SpaceShip::moveRightLeft(const Vector2& value) 230 { 231 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 232 this->steering_.x += value.x; 233 } 234 235 void SpaceShip::moveUpDown(const Vector2& value) 236 { 237 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 238 this->steering_.y += value.x; 239 } 240 241 void SpaceShip::rotateYaw(const Vector2& value) 242 { 243 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); 244 245 Pawn::rotateYaw(value); 246 247 //This function call adds a lift to the ship when it is rotating to make it's movement more "realistic" and enhance the feeling. 248 if (abs(this-> getLocalVelocity().z) < stallSpeed_) {this->moveRightLeft(-lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));} 249 } 250 251 void SpaceShip::rotatePitch(const Vector2& value) 252 { 253 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f); 254 255 Pawn::rotatePitch(value); 256 257 //This function call adds a lift to the ship when it is pitching to make it's movement more "realistic" and enhance the feeling. 258 if (abs(this-> getLocalVelocity().z) < stallSpeed_) {this->moveUpDown(lift_ / 5 * value * sqrt(abs(this-> getLocalVelocity().z)));} 259 } 260 261 void SpaceShip::rotateRoll(const Vector2& value) 262 { 263 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 264 265 Pawn::rotateRoll(value); 266 } 267 268 void SpaceShip::fire() 269 { 270 } 271 272 /** 273 @brief 274 Starts or stops boosting. 275 @param bBoost 276 Whether to start or stop boosting. 277 */ 278 void SpaceShip::boost(bool bBoost) 279 { 280 if(bBoost && !this->bBoostCooldown_) 281 { 282 this->bBoost_ = true; 283 Camera* camera = CameraManager::getInstance().getActiveCamera(); 284 this->cameraOriginalPosition_ = camera->getPosition(); 285 this->cameraOriginalOrientation_ = camera->getOrientation(); 286 } 287 if(!bBoost) 288 { 289 this->bBoost_ = false; 290 this->resetCamera(); 162 291 } 163 292 } … … 167 296 this->bBoostCooldown_ = false; 168 297 } 169 170 void SpaceShip::moveFrontBack(const Vector2& value) 171 { 172 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 173 this->steering_.z = -value.x; 174 } 175 176 void SpaceShip::moveRightLeft(const Vector2& value) 177 { 178 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 179 this->steering_.x = value.x; 180 } 181 182 void SpaceShip::moveUpDown(const Vector2& value) 183 { 184 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 185 this->steering_.y = value.x; 186 } 187 188 void SpaceShip::rotateYaw(const Vector2& value) 189 { 190 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); 191 192 Pawn::rotateYaw(value); 193 } 194 195 void SpaceShip::rotatePitch(const Vector2& value) 196 { 197 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); 198 199 Pawn::rotatePitch(value); 200 } 201 202 void SpaceShip::rotateRoll(const Vector2& value) 203 { 204 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 205 206 Pawn::rotateRoll(value); 207 } 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_) 298 299 void SpaceShip::shakeCamera(float dt) 300 { 301 //make sure the ship is only shaking if it's moving 302 if (this->getVelocity().squaredLength() > 80.0f) 303 { 304 this->shakeDt_ += dt; 305 306 float frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength()); 307 308 if (this->shakeDt_ >= 1.0f/frequency) 309 { 310 this->shakeDt_ -= 1.0f/frequency; 311 } 312 313 Degree angle = Degree(sin(this->shakeDt_ *2.0f* math::pi * frequency) * this->shakeAmplitude_); 314 315 //COUT(0) << "Angle: " << angle << std::endl; 316 Camera* camera = this->getCamera(); 317 318 //Shaking Camera effect 319 if (camera != 0) 320 { 321 camera->setOrientation(Vector3::UNIT_X, angle); 322 } 323 } 324 } 325 326 void SpaceShip::resetCamera() 327 { 328 Camera *camera = this->getCamera(); 329 330 if (camera == 0) 331 { 332 COUT(2) << "Failed to reset camera!"; 213 333 return; 214 215 if(bBoost) 216 this->boost(); 334 } 335 336 this->shakeDt_ = 0; 337 camera->setPosition(this->cameraOriginalPosition_); 338 camera->setOrientation(this->cameraOriginalOrientation_); 339 } 340 341 void SpaceShip::backupCamera() 342 { 343 Camera* camera = CameraManager::getInstance().getActiveCamera(); 344 if(camera != NULL) 345 { 346 this->cameraOriginalPosition_ = camera->getPosition(); 347 this->cameraOriginalOrientation_ = camera->getOrientation(); 348 } 349 } 350 351 void SpaceShip::addEngine(orxonox::Engine* engine) 352 { 353 //COUT(0)<<"Adding an Engine: " << engine << endl; 354 this->engineList_.push_back(engine); 355 engine->addToSpaceShip(this); 356 this->resetEngineTicks(); 357 } 358 359 bool SpaceShip::hasEngine(Engine* engine) 360 { 361 for(unsigned int i=0; i<this->engineList_.size(); i++) 362 { 363 if(this->engineList_[i]==engine) 364 return true; 365 } 366 return false; 367 } 368 369 Engine* SpaceShip::getEngine(unsigned int i) 370 { 371 if(this->engineList_.size()>=i) 372 return 0; 217 373 else 218 { 219 this->bBoost_ = false; 220 } 221 } 222 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 else 254 { 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); 374 return this->engineList_[i]; 375 } 376 377 void SpaceShip::removeAllEngines() 378 { 379 while(this->engineList_.size()) 380 this->engineList_.back()->destroy(); 381 } 382 383 void SpaceShip::removeEngine(Engine* engine) 384 { 385 for(std::vector<Engine*>::iterator it=this->engineList_.begin(); it!=this->engineList_.end(); ++it) 386 { 387 if(*it==engine) 388 { 389 this->engineList_.erase(it); 390 return; 391 } 392 } 393 } 394 395 void SpaceShip::setSpeedFactor(float factor) 396 { 397 for(unsigned int i=0; i<this->engineList_.size(); i++) 398 this->engineList_[i]->setSpeedFactor(factor); 399 } 400 float SpaceShip::getSpeedFactor() // Calculate mean SpeedFactor. 401 { 402 float ret = 0; unsigned int i = 0; 403 for(; i<this->engineList_.size(); i++) 404 ret += this->engineList_[i]->getSpeedFactor(); 405 ret /= (float)i; 406 return ret; 407 } 408 float SpaceShip::getMaxSpeedFront() 409 { 410 float ret=0; 411 for(unsigned int i=0; i<this->engineList_.size(); i++) 412 { 413 if(this->engineList_[i]->getMaxSpeedFront() > ret) 414 ret = this->engineList_[i]->getMaxSpeedFront(); 415 } 416 return ret; 417 } 418 419 float SpaceShip::getBoostFactor() 420 { 421 float ret = 0; unsigned int i=0; 422 for(; i<this->engineList_.size(); i++) 423 ret += this->engineList_[i]->getBoostFactor(); 424 ret /= (float)i; 425 return ret; 267 426 } 268 427 … … 270 429 { 271 430 std::vector<PickupCarrier*>* list = new std::vector<PickupCarrier*>(); 272 list->push_back(this->engine_); 431 for(unsigned int i=0; i<this->engineList_.size(); i++) 432 list->push_back(this->engineList_[i]); 273 433 return list; 274 434 } 435 436 void SpaceShip::changedEnableMotionBlur() 437 { 438 if (!this->bEnableMotionBlur_) 439 { 440 this->boostBlur_->destroy(); 441 this->boostBlur_ = 0; 442 } 443 } 444 275 445 } -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r7801 r8706 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 removeEngine(Engine* engine); 69 void removeAllEngines(); 70 71 void setSpeedFactor(float factor); 72 float getSpeedFactor(); // Gets mean speed factor 73 float getMaxSpeedFront(); // gets largest speed forward 74 float getBoostFactor(); // gets mean boost factor 66 75 67 76 inline void setSteeringDirection(const Vector3& direction) … … 69 78 inline const Vector3& getSteeringDirection() const 70 79 { return this->steering_; } 80 inline void resetEngineTicks() 81 { this->engineTicksNotDone = this->engineList_.size(); } 82 inline void oneEngineTickDone() 83 { this->engineTicksNotDone--; } 84 inline bool hasEngineTicksRemaining() 85 { return (this->engineTicksNotDone>0); } 71 86 72 void setBoost(bool bBoost);73 87 inline bool getBoost() const 74 88 { return this->bBoost_; } 75 89 76 inline void setEngineTemplate(const std::string& temp)77 { this->enginetemplate_ = temp; this->loadEngineTemplate(); }78 inline const std::string& getEngineTemplate() const79 { return this-> enginetemplate_; }90 inline float getBoostPower() const 91 { return this->boostPower_; } 92 inline float getInitialBoostPower() const 93 { return this->initialBoostPower_; } 80 94 81 inline void setPermanentBoost(bool bPermanent) 82 { this->bPermanentBoost_ = bPermanent; } 83 inline bool getPermanentBoost() const 84 { return this->bPermanentBoost_; } 95 inline bool isBoostCoolingDown() const 96 { return bBoostCooldown_; } 85 97 86 98 protected: … … 90 102 bool bBoost_; 91 103 bool bBoostCooldown_; 92 bool bPermanentBoost_;93 104 float boostPower_; 94 105 float initialBoostPower_; … … 96 107 float boostPowerRate_; 97 108 float boostCooldownDuration_; 109 float lift_; 110 float stallSpeed_; 98 111 Vector3 steering_; 99 112 float primaryThrust_; … … 103 116 btVector3 localAngularAcceleration_; 104 117 118 float shakeFrequency_; 119 float shakeAmplitude_; 120 105 121 private: 106 122 void registerVariables(); 107 123 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 124 125 //All things booster 126 void changedEnableMotionBlur(); 127 void boostCooledDown(void); 128 129 void resetCamera(); 130 void backupCamera(); 131 void shakeCamera(float dt); 108 132 109 void loadEngineTemplate();110 111 void boostCooledDown(void);133 Shader* boostBlur_; 134 float blurStrength_; 135 bool bEnableMotionBlur_; 112 136 113 std:: string enginetemplate_;114 Engine* engine_;137 std::vector<Engine*> engineList_; 138 int engineTicksNotDone; // Used for knowing when to reset temporary variables. 115 139 Timer timer_; 140 Vector3 cameraOriginalPosition_; 141 Quaternion cameraOriginalOrientation_; 142 143 float shakeDt_; 116 144 }; 117 145 }
Note: See TracChangeset
for help on using the changeset viewer.