Changeset 8727 for code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
- Timestamp:
- Jul 3, 2011, 5:42:19 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r8706 r8727 34 34 #include <string> 35 35 #include <LinearMath/btVector3.h> 36 36 37 #include "tools/Timer.h" 37 38 #include "util/Math.h" 39 #include "util/OrxAssert.h" 40 38 41 #include "Pawn.h" 39 42 40 43 namespace orxonox 41 44 { 45 46 /** 47 @brief 48 The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it. 49 50 There are several parameters that define the behavior of the SpaceShip> 51 - The <b>rotationThrust</b>, specifies the force with which the SpaceShip rotates. 52 - The <b>boost</b>, there are quite some parameters pertaining to boosting. The boost is a special move of the SpaceShip, where, for a limited amount of time, it can fly considerably faster than usual. The <b>boostPower</b> is the amount of power available for boosting. The <b>boostPowerRate</b> is the rate at which the boost power is replenished. The <b>boostRate</b> is the rate at which boosting uses power. And the <b>boostCooldownDuration</b> is the time the SpaceShip cannot boost, once all the boost power has been used up. Naturally all of these parameters must be non-negative. 53 - The <b>boost shaking</b>, when the SpaceShip boosts, the camera shakes to create a more immersive effect. Two parameters can be used to adjust the effect. The <b>shakeFrequency</b> is the frequency with which the camera shakes. And the <b>shakeAmplitude</b> is the amount with which the camera shakes. Again these parameters must bee non-negative. 54 - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated. 55 56 As mentioned @ref orxonox::Engine Engines can be mounted on the SpaceShip. Here is a (primitive) example of a SpaceShip defined in XML: 57 @code 58 <SpaceShip 59 rotationThrust = 50 60 61 lift = 1; 62 stallSpeed = 220; 63 64 boostPower = 15 65 boostPowerRate = 1 66 boostRate = 5 67 boostCooldownDuration = 10 68 69 shakeFrequency = 15 70 shakeAmplitude = 9 71 72 collisionType = "dynamic" 73 mass = 100 74 linearDamping = 0.7 75 angularDamping = 0.9999999 76 > 77 <engines> 78 <Engine /> 79 <Engine /> 80 </engines> 81 </SpaceShip> 82 @endcode 83 84 @author 85 Fabian 'x3n' Landau 86 */ 42 87 class _OrxonoxExport SpaceShip : public Pawn 43 88 { … … 50 95 void setConfigValues(); 51 96 52 virtual void moveFrontBack(const Vector2& value); 53 virtual void moveRightLeft(const Vector2& value); 54 virtual void moveUpDown(const Vector2& value); 55 56 virtual void rotateYaw(const Vector2& value); 57 virtual void rotatePitch(const Vector2& value); 58 virtual void rotateRoll(const Vector2& value); 97 /** 98 @brief Move forward or backward, 99 @param value A vector whose first component specifies the amount of movement. Positive means forward, negative means backward. 100 */ 101 virtual void moveFrontBack(const Vector2& value) 102 { this->steering_.z -= value.x; } 103 /** 104 @brief Move right or left. 105 @param value A vector whose first component specifies the amount of movement. Positive means right, negative means left. 106 */ 107 virtual void moveRightLeft(const Vector2& value) 108 { this->steering_.x += value.x; } 109 /** 110 @brief Move up or down. 111 @param value A vector whose first component specifies the amount of movement. Positive means up, negative means down. 112 */ 113 virtual void moveUpDown(const Vector2& value) 114 { this->steering_.y += value.x; } 115 116 virtual void rotateYaw(const Vector2& value); // Rotate in yaw direction. 117 virtual void rotatePitch(const Vector2& value); // Rotate in pitch direction. 118 virtual void rotateRoll(const Vector2& value); // Rotate in roll direction. 59 119 60 120 virtual void fire(); 61 121 virtual void boost(bool bBoost); // Starts or stops boosting. 62 122 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() 123 void addEngine(Engine* engine); // Add an Engine to the SpaceShip. 124 bool hasEngine(Engine* engine) const; // Check whether the SpaceShip has a particular Engine. 125 Engine* getEngine(unsigned int i); // Get the i-th Engine of the SpaceShip. 126 /** 127 @brief Get the list of all Engines that are mounted on the SpaceShip. 128 @return Returns a vector of all Engines of the SpaceShip. 129 */ 130 inline const std::vector<Engine*>& getEngineList() const 67 131 { 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 75 132 void removeEngine(Engine* engine); // Remove and destroy all Engines of the SpaceShip. 133 void removeAllEngines(); // Remove a particular Engine from the SpaceShip. 134 135 void addSpeedFactor(float factor); // Add to the speed factor for all engines of the SpaceShip. 136 void addSpeed(float speed); // Add to the speed of all engines of the SpaceShip. 137 float getSpeedFactor() const; // Get the mean speed factor over all engines of the SpaceShip. 138 139 float getMaxSpeedFront() const; // Get the largest maximal forward speed over all engines of the SpaceShip. 140 float getBoostFactor() const; // Get the mean boost factor over all engines of the SpaceShip. 141 142 /** 143 @brief Set the steering direction of the SpaceShip. 144 This is set through the user input. 145 @param direction The direction the SpaceShip should steer in. 146 */ 76 147 inline void setSteeringDirection(const Vector3& direction) 77 148 { this->steering_ = direction; } 149 /** 150 @brief Get the steering direction of the SpaceShip. 151 @return Returns the steering direction of the SpaceShip. The length of the vector is the amount of steering needed. 152 */ 78 153 inline const Vector3& getSteeringDirection() const 79 154 { 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); } 86 87 inline bool getBoost() const 155 156 /** 157 @brief Check whether the SpaceShip is currently boosting. 158 @return Returns true if the SpaceShip is boosting, false if not. 159 */ 160 inline bool isBoosting() const 88 161 { return this->bBoost_; } 89 162 /** 163 @brief Check whether the SpaceShip boost is cooling down. 164 @return Returns true if the SpaceShip is cooling down from boosting. 165 */ 166 inline bool isBoostCoolingDown() const 167 { return bBoostCooldown_; } 168 169 /** 170 @brief Set the initial power available for boosting to the input value. 171 The current boost power is set to the input value as well. 172 @param power The initial boost power. Must be non-negative. 173 */ 174 inline void setInitialBoostPower(float power) 175 { OrxAssert(power >= 0.0f, "The boost power must be non-negative."); this->initialBoostPower_ = power; this->boostPower_ = power; } 176 /** 177 @brief Set the rate, at which boost power is recharged, to the input value. 178 @param rate The boost power rate in units per second. Must be non-negative. 179 */ 180 inline void setBoostPowerRate(float rate) 181 { OrxAssert(rate >= 0.0f, "The boost power rate must be non-negative."); this->boostPowerRate_ = rate; } 182 /** 183 @brief Set the rate, at which boost power us used up, to the input value. 184 @param rate The boost rate in units per second. Must be non-negative. 185 */ 186 inline void setBoostRate(float rate) 187 { OrxAssert(rate >= 0.0f, "The boost rate must be non-negative."); this->boostRate_ = rate; } 188 /** 189 @brief Set the duration for which boosting, if in cooldown, is not possible. 190 Cooldown is reached if all boost power is depleted. 191 @param duration The cooldown duration in seconds. Must be non-negative. 192 */ 193 inline void setBoostCooldownDuration(float duration) 194 { OrxAssert(duration >= 0.0f, "The boost cooldown duration must be non-negative."); this->boostCooldownDuration_ = duration; } 195 /** 196 @brief Set the frequency with which the camera shakes during boosting. 197 @param frequency The frequency in times per second. Must be non-negative. 198 */ 199 inline void setShakeFrequency(float frequency) 200 { OrxAssert(frequency >= 0.0f, "The shake frequency must be non-negative."); this->shakeFrequency_ = frequency; } 201 /** 202 @brief Set the amplitude with which the camera shakes during boosting. 203 @param amplitude The amplitude. Must be non-negative. 204 */ 205 inline void setShakeAmplitude(float amplitude) 206 { OrxAssert(amplitude >= 0.0f, "The shake amplitude must be non-negative."); this->shakeAmplitude_ = amplitude; } 207 208 /** 209 @brief Get the initial boost power. Is non-negative. 210 @return Returns the initial boost power. 211 */ 212 inline float getInitialBoostPower() const 213 { return this->initialBoostPower_; } 214 /** 215 @brief Get the current boost power. Is non-negative. 216 @return Returns the current boost power. 217 */ 90 218 inline float getBoostPower() const 91 219 { return this->boostPower_; } 92 inline float getInitialBoostPower() const 93 { return this->initialBoostPower_; } 94 95 inline bool isBoostCoolingDown() const 96 { return bBoostCooldown_; } 220 /** 221 @brief Get the boost power rate. 222 @return Returns the boost power rate in units per second. Is non-negative. 223 */ 224 inline float getBoostPowerRate() const 225 { return this->boostPowerRate_; } 226 /** 227 @brief Get the boost rate. 228 @return Returns the boost rate in units per second. Is non-negative. 229 */ 230 inline float getBoostRate() const 231 { return this->boostRate_; } 232 /** 233 @brief Get the cooldown duration. 234 @return Returns the cooldown duration in seconds. Is non-negative. 235 */ 236 inline float getBoostCooldownDuration() const 237 { return this->boostCooldownDuration_; } 238 /** 239 @brief Get the shake frequency. 240 @return Returns the shake frequency in times per seconds. Is non-negative. 241 */ 242 inline float getShakeFrequency() const 243 { return this->shakeFrequency_; } 244 /** 245 @brief Get the shake amplitude. 246 @return Returns the shake amplitude. Is non-negative. 247 */ 248 inline float getShakeAmplitude() const 249 { return this->shakeAmplitude_; } 97 250 98 251 protected: 99 virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const;100 252 bool bInvertYAxis_; 101 253 102 bool bBoost_; 103 bool bBoostCooldown_; 104 float boostPower_; 105 float initialBoostPower_; 106 float boostRate_; 107 float boostPowerRate_; 108 float boostCooldownDuration_; 109 float lift_; 110 float stallSpeed_; 111 Vector3 steering_; 112 float primaryThrust_; 113 float auxilaryThrust_; 114 float rotationThrust_; 115 btVector3 localLinearAcceleration_; 116 btVector3 localAngularAcceleration_; 117 118 float shakeFrequency_; 119 float shakeAmplitude_; 254 Vector3 steering_; //!< The direction and magnitude of the steering action given through user input. 255 256 float rotationThrust_; //!< Force with which the SpaceShip rotates. 257 btVector3 localAngularAcceleration_; //!< The acceleration that accounts for angular movement and is used internally. 258 259 bool bBoost_; //!< Whether the SpaceShip is currently boosting. 260 bool bBoostCooldown_; //!< Whether the SpaceShip is currently in boost cooldown, during which boosting is impossible. 261 float initialBoostPower_; //!< The initial (and maximal) boost power. 262 float boostPower_; //!< The current boost power. 263 float boostPowerRate_; //!< The rate at which the boost power is recharged. 264 float boostRate_; //!< The rate at which boost power is used up. 265 float boostCooldownDuration_; //!< The duration for which boost cooldown is in effect. 266 float shakeFrequency_; //!< The frequency of the shaking of the camera due to boosting. 267 float shakeAmplitude_; //!< The amplitude of the shaking of the camera due to boosting. 268 269 float lift_; //!< The amount of lift that is added. 270 float stallSpeed_; //!< The forward speed where no more lift is added. 120 271 121 272 private: 122 273 void registerVariables(); 123 274 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 124 125 //All things booster 126 void changedEnableMotionBlur(); 127 void boostCooledDown(void); 275 276 void changedEnableMotionBlur(); // Is called when the enableMotionBlur config value has changed. 277 /** 278 @brief Callback function. Is called when the boost has cooled down. 279 */ 280 void boostCooledDown(void) 281 { this->bBoostCooldown_ = false; } 282 283 void shakeCamera(float dt); // Shake the camera for a given time interval. 284 void backupCamera(); // Save the original position and orientation of the camera. 285 void resetCamera(); // Reset the camera to its original position. 286 287 std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip. 288 289 Timer timer_; //!< Timer for the cooldown duration. 290 float shakeDt_; //!< Temporary variable for the shaking of the camera. 291 Vector3 cameraOriginalPosition_; //!< The original position of the camera before shaking it. 292 Quaternion cameraOriginalOrientation_; //!< The original orientation of the camera before shaking it. 293 294 Shader* boostBlur_; //!< A radial blur shader, applied when boosting according to the amount of boosting. 295 float blurStrength_; //!< The strength of the applied blur. 296 bool bEnableMotionBlur_; //!< Whether motion blur is enabled or not. 128 297 129 void resetCamera();130 void backupCamera();131 void shakeCamera(float dt);132 133 Shader* boostBlur_;134 float blurStrength_;135 bool bEnableMotionBlur_;136 137 std::vector<Engine*> engineList_;138 int engineTicksNotDone; // Used for knowing when to reset temporary variables.139 Timer timer_;140 Vector3 cameraOriginalPosition_;141 Quaternion cameraOriginalOrientation_;142 143 float shakeDt_;144 298 }; 145 299 }
Note: See TracChangeset
for help on using the changeset viewer.