Orxonox  0.0.5 Codename: Arcturus
SpaceShip.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Fabian 'x3n' Landau
24  * Co-authors:
25  * ...
26  *
27  */
28 
29 #ifndef _SpaceShip_H__
30 #define _SpaceShip_H__
31 
32 #include "OrxonoxPrereqs.h"
33 
34 #include <string>
35 #include <LinearMath/btVector3.h>
36 
37 #include "tools/Timer.h"
38 #include "util/Math.h"
39 #include "util/OrxAssert.h"
40 
41 #include "Pawn.h"
42 
43 namespace orxonox
44 {
45 
90  class _OrxonoxExport SpaceShip : public Pawn
91  {
92  public:
93  SpaceShip(Context* context);
94  virtual ~SpaceShip();
95 
96  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
97  virtual void tick(float dt);
98  void setConfigValues();
99 
104  virtual void moveFrontBack(const Vector2& value)
105  { this->steering_.z -= (0.6)*value.x; }
110  virtual void moveRightLeft(const Vector2& value)
111  { this->steering_.x += (0.6)*value.x; }
116  virtual void moveUpDown(const Vector2& value)
117  { this->steering_.y += (0.6)*value.x; }
118 
119  inline void moveFrontBack(float value)
120  { this->moveFrontBack(Vector2(value, 0)); }
121  inline void moveRightLeft(float value)
122  { this->moveRightLeft(Vector2(value, 0)); }
123  inline void moveUpDown(float value)
124  { this->moveUpDown(Vector2(value, 0)); }
125 
126  virtual void rotateYaw(const Vector2& value); // Rotate in yaw direction.
127  virtual void rotatePitch(const Vector2& value); // Rotate in pitch direction.
128  virtual void rotateRoll(const Vector2& value); // Rotate in roll direction.
129 
130  virtual void fire();
131  virtual void boost(bool bBoost); // Starts or stops boosting.
132 
133  void addEngine(Engine* engine); // Add an Engine to the SpaceShip.
134  bool hasEngine(Engine* engine) const; // Check whether the SpaceShip has a particular Engine.
135  Engine* getEngine(unsigned int i); // Get the i-th Engine of the SpaceShip.
136  Engine* getEngineByName(const std::string& name);
141  inline const std::vector<Engine*>& getEngineList() const
142  { return this->engineList_; }
143  void removeEngine(Engine* engine); // Remove and destroy all Engines of the SpaceShip.
144  void removeAllEngines(); // Remove a particular Engine from the SpaceShip.
145 
146  void addSpeedFactor(float factor); // Add to the speed factor for all engines of the SpaceShip.
147  void addSpeed(float speed); // Add to the speed of all engines of the SpaceShip.
148  float getSpeedFactor() const; // Get the mean speed factor over all engines of the SpaceShip.
149 
150  float getMaxSpeedFront() const; // Get the largest maximal forward speed over all engines of the SpaceShip.
151  float getBoostFactor() const; // Get the mean boost factor over all engines of the SpaceShip.
152 
158  inline void setSteeringDirection(const Vector3& direction)
159  { this->steering_ = direction; }
164  inline const Vector3& getSteeringDirection() const
165  { return this->steering_; }
166 
171  inline bool isBoosting() const
172  { return this->bBoost_; }
177  inline bool isBoostCoolingDown() const
178  { return bBoostCooldown_; }
179 
185  inline void setInitialBoostPower(float power)
186  { OrxAssert(power >= 0.0f, "The boost power must be non-negative."); this->initialBoostPower_ = power; this->boostPower_ = power; }
191  inline void setBoostPowerRate(float rate)
192  { OrxAssert(rate >= 0.0f, "The boost power rate must be non-negative."); this->boostPowerRate_ = rate; }
197  inline void setBoostRate(float rate)
198  { OrxAssert(rate >= 0.0f, "The boost rate must be non-negative."); this->boostRate_ = rate; }
204  inline void setBoostCooldownDuration(float duration)
205  { OrxAssert(duration >= 0.0f, "The boost cooldown duration must be non-negative."); this->boostCooldownDuration_ = duration; }
210  inline void setShakeFrequency(float frequency)
211  { OrxAssert(frequency >= 0.0f, "The shake frequency must be non-negative."); this->shakeFrequency_ = frequency; }
216  inline void setShakeAmplitude(float amplitude)
217  { OrxAssert(amplitude >= 0.0f, "The shake amplitude must be non-negative."); this->shakeAmplitude_ = amplitude; }
218 
223  inline float getInitialBoostPower() const
224  { return this->initialBoostPower_; }
229  inline float getBoostPower() const
230  { return this->boostPower_; }
235  inline float getBoostPowerRate() const
236  { return this->boostPowerRate_; }
241  inline float getBoostRate() const
242  { return this->boostRate_; }
247  inline float getBoostCooldownDuration() const
248  { return this->boostCooldownDuration_; }
253  inline float getShakeFrequency() const
254  { return this->shakeFrequency_; }
259  inline float getShakeAmplitude() const
260  { return this->shakeAmplitude_; }
265  void gainBoostPower(float gainedBoostPower);
266 
267  protected:
269 
270  Vector3 steering_;
271 
274 
275  bool bBoost_;
278  float boostPower_;
280  float boostRate_;
284 
285  float lift_;
286  float stallSpeed_;
287 
288  private:
289  void registerVariables();
290  virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
291 
292  void changedEnableMotionBlur(); // Is called when the enableMotionBlur config value has changed.
296  void boostCooledDown(void)
297  { this->bBoostCooldown_ = false; }
298 
299  void shakeCamera(float dt); // Shake the camera for a given time interval.
300  void backupCamera(); // Save the original position and orientation of the camera.
301  void resetCamera(); // Reset the camera to its original position.
302 
303  std::vector<Engine*> engineList_;
304 
306  float shakeDt_;
309 
313 
314  };
315 }
316 
317 #endif /* _SpaceShip_H__ */
const std::vector< Engine * > & getEngineList() const
Get the list of all Engines that are mounted on the SpaceShip.
Definition: SpaceShip.h:141
Everything in Orxonox that has a health attribute is a Pawn.
Definition: Pawn.h:56
bool isBoostCoolingDown() const
Check whether the SpaceShip boost is cooling down.
Definition: SpaceShip.h:177
void moveRightLeft(float value)
Definition: SpaceShip.h:121
float initialBoostPower_
The initial (and maximal) boost power.
Definition: SpaceShip.h:277
bool bInvertYAxis_
Definition: SpaceShip.h:268
Definition: CorePrereqs.h:309
Vector3 steering_
The direction and magnitude of the steering action given through user input.
Definition: SpaceShip.h:270
bool bBoostCooldown_
Whether the SpaceShip is currently in boost cooldown, during which boosting is impossible.
Definition: SpaceShip.h:276
bool bBoost_
Whether the SpaceShip is currently boosting.
Definition: SpaceShip.h:275
void setBoostPowerRate(float rate)
Set the rate, at which boost power is recharged, to the input value.
Definition: SpaceShip.h:191
bool isBoosting() const
Check whether the SpaceShip is currently boosting.
Definition: SpaceShip.h:171
float boostPower_
The current boost power. If the boost power is reduced to zero the boost cooldown will start...
Definition: SpaceShip.h:278
float boostPowerRate_
The rate at which the boost power is recharged.
Definition: SpaceShip.h:279
float getBoostPowerRate() const
Get the boost power rate.
Definition: SpaceShip.h:235
virtual void moveRightLeft(const Vector2 &value)
Move right or left.
Definition: SpaceShip.h:110
void setShakeFrequency(float frequency)
Set the frequency with which the camera shakes during boosting.
Definition: SpaceShip.h:210
float rotationThrust_
Force with which the SpaceShip rotates.
Definition: SpaceShip.h:272
::std::string string
Definition: gtest-port.h:756
void moveFrontBack(float value)
Definition: SpaceShip.h:119
float shakeAmplitude_
The amplitude of the shaking of the camera due to boosting.
Definition: SpaceShip.h:283
float blurStrength_
The strength of the applied blur.
Definition: SpaceShip.h:311
#define OrxAssert(condition, errorMessage)
Run time assertion like assert(), but with an embedded message.
Definition: OrxAssert.h:54
Shader is a wrapper class around Ogre::CompositorInstance.
Definition: Shader.h:47
float getBoostPower() const
Get the current boost power.
Definition: SpaceShip.h:229
xmlelement
Definition: Super.h:519
The SpaceShip is the principal entity through which the player interacts with the game...
Definition: SpaceShip.h:90
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
Declaration of the Timer class, used to call functions after a given time-interval.
float getInitialBoostPower() const
Get the initial boost power.
Definition: SpaceShip.h:223
float lift_
The amount of lift that is added.
Definition: SpaceShip.h:285
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
float getBoostRate() const
Get the boost rate.
Definition: SpaceShip.h:241
float stallSpeed_
The forward speed where no more lift is added.
Definition: SpaceShip.h:286
Mode
Definition: CorePrereqs.h:102
CollisionType
Denotes the possible types of physical objects in a Scene.
Definition: WorldEntity.h:265
Shared library macros, enums, constants and forward declarations for the orxonox library ...
Shader * boostBlur_
A radial blur shader, applied when boosting according to the amount of boosting.
Definition: SpaceShip.h:310
Quaternion cameraOriginalOrientation_
The original orientation of the camera before shaking it.
Definition: SpaceShip.h:308
float getShakeFrequency() const
Get the shake frequency.
Definition: SpaceShip.h:253
const Vector3 & getSteeringDirection() const
Get the steering direction of the SpaceShip.
Definition: SpaceShip.h:164
Definition: Context.h:45
float shakeDt_
Temporary variable for the shaking of the camera.
Definition: SpaceShip.h:306
Timer timer_
Timer for the cooldown of the boost.
Definition: SpaceShip.h:305
float getBoostCooldownDuration() const
Get the cooldown duration.
Definition: SpaceShip.h:247
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
void setInitialBoostPower(float power)
Set the initial power available for boosting to the input value.
Definition: SpaceShip.h:185
void setBoostCooldownDuration(float duration)
Set the duration for which boosting, if in cooldown, is not possible.
Definition: SpaceShip.h:204
virtual void moveFrontBack(const Vector2 &value)
Move forward or backward,.
Definition: SpaceShip.h:104
void setShakeAmplitude(float amplitude)
Set the amplitude with which the camera shakes during boosting.
Definition: SpaceShip.h:216
void boostCooledDown(void)
Callback function.
Definition: SpaceShip.h:296
Vector3 cameraOriginalPosition_
The original position of the camera before shaking it.
Definition: SpaceShip.h:307
void moveUpDown(float value)
Definition: SpaceShip.h:123
virtual void moveUpDown(const Vector2 &value)
Move up or down.
Definition: SpaceShip.h:116
The Engine class provides propulsion to the SpaceShip.
Definition: Engine.h:55
std::vector< Engine * > engineList_
The list of all Engines mounted on this SpaceShip.
Definition: SpaceShip.h:303
Timer is a helper class that executes a function after a given amount of seconds in game-time...
Definition: Timer.h:105
float boostCooldownDuration_
The duration for which boost cooldown is in effect.
Definition: SpaceShip.h:281
void setBoostRate(float rate)
Set the rate, at which boost power us used up, to the input value.
Definition: SpaceShip.h:197
float boostRate_
The rate at which boost power is used up.
Definition: SpaceShip.h:280
btVector3 localAngularAcceleration_
The acceleration that accounts for angular movement and is used internally.
Definition: SpaceShip.h:273
float shakeFrequency_
The frequency of the shaking of the camera due to boosting.
Definition: SpaceShip.h:282
Declaration of custom assertion facilities
void setSteeringDirection(const Vector3 &direction)
Set the steering direction of the SpaceShip.
Definition: SpaceShip.h:158
bool bEnableMotionBlur_
Whether motion blur is enabled or not.
Definition: SpaceShip.h:312
float getShakeAmplitude() const
Get the shake amplitude.
Definition: SpaceShip.h:259