Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h @ 12412

Last change on this file since 12412 was 12029, checked in by merholzl, 6 years ago

added space race improvements

  • Property svn:eol-style set to native
File size: 15.8 KB
RevLine 
[2072]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
[3196]34#include <string>
35#include <LinearMath/btVector3.h>
[8727]36
[7801]37#include "tools/Timer.h"
[3196]38#include "util/Math.h"
[8727]39#include "util/OrxAssert.h"
40
[2072]41#include "Pawn.h"
42
43namespace orxonox
44{
[8727]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.
[10437]49        The feature that you can add @ref orxonox::Engine Engines is new in this class. However adding @ref orxonox::Weapon Weapons is possible because every Spaceship is a Pawn (due to inheritance) and every Pawn can carry @ref orxonox::Weapon Weapons.
[8727]50
51        There are several parameters that define the behavior of the SpaceShip>
52        - The <b>rotationThrust</b>, specifies the force with which the SpaceShip rotates.
53        - 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.
54        - 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.
[11052]55        - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again two 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.
[8727]56
[11052]57        A spaceship always needs to have the collision type "dynamic". Other collision types are illegal.
58
[8727]59        As mentioned @ref orxonox::Engine Engines can be mounted on the SpaceShip. Here is a (primitive) example of a SpaceShip defined in XML:
60        @code
61        <SpaceShip
62            rotationThrust    = 50
63
64            lift = 1;
65            stallSpeed = 220;
66
67            boostPower            = 15
68            boostPowerRate        = 1
69            boostRate             = 5
70            boostCooldownDuration = 10
71
72            shakeFrequency = 15
73            shakeAmplitude = 9
74
75            collisionType     = "dynamic"
76            mass              = 100
77            linearDamping     = 0.7
78            angularDamping    = 0.9999999
79            >
80                <engines>
81                    <Engine />
82                    <Engine />
83                </engines>
84            </SpaceShip>
85        @endcode
86
87    @author
88        Fabian 'x3n' Landau
89    */
[2072]90    class _OrxonoxExport SpaceShip : public Pawn
91    {
92        public:
[9667]93            SpaceShip(Context* context);
[2072]94            virtual ~SpaceShip();
95
96            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
97            virtual void tick(float dt);
98            void setConfigValues();
99
[8727]100            /**
101            @brief Move forward or backward,
102            @param value A vector whose first component specifies the amount of movement. Positive means forward, negative means backward.
103            */
104            virtual void moveFrontBack(const Vector2& value)
[12029]105                { this->steering_.z -= (0.6)*value.x; }
[8727]106            /**
107            @brief Move right or left.
108            @param value A vector whose first component specifies the amount of movement. Positive means right, negative means left.
109            */
110            virtual void moveRightLeft(const Vector2& value)
[12029]111                { this->steering_.x += (0.6)*value.x; }
[8727]112            /**
113            @brief Move up or down.
114            @param value A vector whose first component specifies the amount of movement. Positive means up, negative means down.
115            */
116            virtual void moveUpDown(const Vector2& value)
[12029]117                { this->steering_.y += (0.6)*value.x; }
[2072]118
[12028]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
[8727]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.
[2072]129
130            virtual void fire();
[8706]131            virtual void boost(bool bBoost); // Starts or stops boosting.
[2072]132
[8727]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.
[10216]136            Engine* getEngineByName(const std::string& name);
[8727]137            /**
138            @brief Get the list of all Engines that are mounted on the SpaceShip.
139            @return Returns a vector of all Engines of the SpaceShip.
140            */
141            inline const std::vector<Engine*>& getEngineList() const
[8706]142                { return this->engineList_; }
[8727]143            void removeEngine(Engine* engine); // Remove and destroy all Engines of the SpaceShip.
144            void removeAllEngines(); // Remove a particular Engine from the SpaceShip.
[2072]145
[8727]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.
[8706]152
[8727]153            /**
154            @brief Set the steering direction of the SpaceShip.
155                   This is set through the user input.
156            @param direction The direction the SpaceShip should steer in.
157            */
[2662]158            inline void setSteeringDirection(const Vector3& direction)
159                { this->steering_ = direction; }
[8727]160            /**
161            @brief Get the steering direction of the SpaceShip.
162            @return Returns the steering direction of the SpaceShip. The length of the vector is the amount of steering needed.
163            */
[2662]164            inline const Vector3& getSteeringDirection() const
165                { return this->steering_; }
[2072]166
[8727]167            /**
168            @brief Check whether the SpaceShip is currently boosting.
169            @return Returns true if the SpaceShip is boosting, false if not.
170            */
171            inline bool isBoosting() const
[2662]172                { return this->bBoost_; }
[8727]173            /**
174            @brief Check whether the SpaceShip boost is cooling down.
175            @return Returns true if the SpaceShip is cooling down from boosting.
176            */
177            inline bool isBoostCoolingDown() const
178                { return bBoostCooldown_; }
[2662]179
[8727]180            /**
181            @brief Set the initial power available for boosting to the input value.
182                   The current boost power is set to the input value as well.
183            @param power The initial boost power. Must be non-negative.
184            */
185            inline void setInitialBoostPower(float power)
186                { OrxAssert(power >= 0.0f, "The boost power must be non-negative."); this->initialBoostPower_ = power; this->boostPower_ = power; }
187            /**
188            @brief Set the rate, at which boost power is recharged, to the input value.
189            @param rate The boost power rate in units per second. Must be non-negative.
190            */
191            inline void setBoostPowerRate(float rate)
192                { OrxAssert(rate >= 0.0f, "The boost power rate must be non-negative."); this->boostPowerRate_ = rate; }
193            /**
194            @brief Set the rate, at which boost power us used up, to the input value.
195            @param rate The boost rate in units per second. Must be non-negative.
196            */
197            inline void setBoostRate(float rate)
198                { OrxAssert(rate >= 0.0f, "The boost rate must be non-negative."); this->boostRate_ = rate; }
199            /**
200            @brief Set the duration for which boosting, if in cooldown, is not possible.
201                   Cooldown is reached if all boost power is depleted.
202            @param duration The cooldown duration in seconds. Must be non-negative.
203            */
204            inline void setBoostCooldownDuration(float duration)
205                { OrxAssert(duration >= 0.0f, "The boost cooldown duration must be non-negative."); this->boostCooldownDuration_ = duration; }
206            /**
207            @brief Set the frequency with which the camera shakes during boosting.
208            @param frequency The frequency in times per second. Must be non-negative.
209            */
210            inline void setShakeFrequency(float frequency)
211                { OrxAssert(frequency >= 0.0f, "The shake frequency must be non-negative."); this->shakeFrequency_ = frequency; }
212            /**
213            @brief Set the amplitude with which the camera shakes during boosting.
214            @param amplitude The amplitude. Must be non-negative.
215            */
216            inline void setShakeAmplitude(float amplitude)
217                { OrxAssert(amplitude >= 0.0f, "The shake amplitude must be non-negative."); this->shakeAmplitude_ = amplitude; }
218
219            /**
220            @brief Get the initial boost power. Is non-negative.
221            @return Returns the initial boost power.
222            */
223            inline float getInitialBoostPower() const
224                { return this->initialBoostPower_; }
225            /**
226            @brief Get the current boost power. Is non-negative.
227            @return Returns the current boost power.
228            */
[8706]229            inline float getBoostPower() const
230                { return this->boostPower_; }
[8727]231            /**
232            @brief Get the boost power rate.
233            @return Returns the boost power rate in units per second. Is non-negative.
234            */
235            inline float getBoostPowerRate() const
236                { return this->boostPowerRate_; }
237            /**
238            @brief Get the boost rate.
239            @return Returns the boost rate in units per second. Is non-negative.
240            */
241            inline float getBoostRate() const
242                { return this->boostRate_; }
243            /**
244            @brief Get the cooldown duration.
245            @return Returns the cooldown duration in seconds. Is non-negative.
246            */
247            inline float getBoostCooldownDuration() const
248                { return this->boostCooldownDuration_; }
249            /**
250            @brief Get the shake frequency.
251            @return Returns the shake frequency in times per seconds. Is non-negative.
252            */
253            inline float getShakeFrequency() const
254                { return this->shakeFrequency_; }
255            /**
256            @brief Get the shake amplitude.
257            @return Returns the shake amplitude. Is non-negative.
258            */
259            inline float getShakeAmplitude() const
260                { return this->shakeAmplitude_; }
[11052]261            /**
262            @brief Add boost power. Is non-negative.
263            @return Returns the current boost power.
264            */
265            void gainBoostPower(float gainedBoostPower);
[2662]266
[2072]267        protected:
268            bool bInvertYAxis_;
269
[8727]270            Vector3 steering_; //!< The direction and magnitude of the steering action given through user input.
[2072]271
[8727]272            float rotationThrust_;               //!< Force with which the SpaceShip rotates.
273            btVector3 localAngularAcceleration_; //!< The acceleration that accounts for angular movement and is used internally.
[8706]274
[8727]275            bool bBoost_;                 //!< Whether the SpaceShip is currently boosting.
276            bool bBoostCooldown_;         //!< Whether the SpaceShip is currently in boost cooldown, during which boosting is impossible.
277            float initialBoostPower_;     //!< The initial (and maximal) boost power.
[11052]278            float boostPower_;            //!< The current boost power. If the boost power is reduced to zero the boost cooldown will start.
[8727]279            float boostPowerRate_;        //!< The rate at which the boost power is recharged.
280            float boostRate_;             //!< The rate at which boost power is used up.
281            float boostCooldownDuration_; //!< The duration for which boost cooldown is in effect.
282            float shakeFrequency_;        //!< The frequency of the shaking of the camera due to boosting.
283            float shakeAmplitude_;        //!< The amplitude of the shaking of the camera due to boosting.
284
285            float lift_;       //!< The amount of lift that is added.
286            float stallSpeed_; //!< The forward speed where no more lift is added.
287
[2662]288        private:
[7163]289            void registerVariables();
[2662]290            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
291
[8727]292            void changedEnableMotionBlur(); // Is called when the enableMotionBlur config value has changed.
293            /**
294            @brief Callback function. Is called when the boost has cooled down.
295            */
296            void boostCooledDown(void)
297                { this->bBoostCooldown_ = false; }
[8706]298
[8727]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_; //!< The list of all Engines mounted on this SpaceShip.
304
[11052]305            Timer timer_;                          //!< Timer for the cooldown of the boost.
[8727]306            float shakeDt_;                        //!< Temporary variable for the shaking of the camera.
307            Vector3 cameraOriginalPosition_;       //!< The original position of the camera before shaking it.
308            Quaternion cameraOriginalOrientation_; //!< The original orientation of the camera before shaking it.
309
310            Shader* boostBlur_;      //!< A radial blur shader, applied when boosting according to the amount of boosting.
311            float blurStrength_;     //!< The strength of the applied blur.
312            bool bEnableMotionBlur_; //!< Whether motion blur is enabled or not.
[8706]313       
[2072]314    };
315}
316
317#endif /* _SpaceShip_H__ */
Note: See TracBrowser for help on using the repository browser.