Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ogre1.9/src/modules/objects/ForceField.h @ 12107

Last change on this file since 12107 was 11083, checked in by muemart, 9 years ago

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1
2/*
3 *   ORXONOX - the hottest 3D action shooter ever to exist
4 *                    > www.orxonox.net <
5 *
6 *
7 *   License notice:
8 *
9 *   This program is free software; you can redistribute it and/or
10 *   modify it under the terms of the GNU General Public License
11 *   as published by the Free Software Foundation; either version 2
12 *   of the License, or (at your option) any later version.
13 *
14 *   This program is distributed in the hope that it will be useful,
15 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *   GNU General Public License for more details.
18 *
19 *   You should have received a copy of the GNU General Public License
20 *   along with this program; if not, write to the Free Software
21 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 *
23 *   Author:
24 *      Aurelian Jaggi
25 *   Co-authors:
26 *      Damian 'Mozork' Frick
27 *      Kevin Young
28 *
29 */
30
31/**
32    @file ForceField.h
33    @brief Definition of the ForceField class.
34    @ingroup Objects
35*/
36
37#ifndef _ForceField_H__
38#define _ForceField_H__
39
40#include "objects/ObjectsPrereqs.h"
41
42#include "tools/interfaces/Tickable.h"
43#include "worldentities/StaticEntity.h"
44
45namespace orxonox
46{
47
48    /**
49    @brief
50        The mode of the ForceField.
51
52    @ingroup Objects
53    */
54    enum class ForceFieldMode {
55        tube, //!< The ForceField has a tube shape.
56        sphere, //!< The ForceField has a spherical shape.
57        invertedSphere, //!< The ForceField has a spherical shape but "inverted" behavior.
58        newtonianGravity, //!< The ForceField imitates Newtonian gravitation for use in stellar bodies.
59        homogen //!< Local homogenous Force field with changeable direction for the Space Station
60    };
61
62    /**
63    @brief
64        Implements a force field, that applies a force to any @ref orxonox::MobileEntity "MobileEntity" that enters its range.
65
66        The following parameters can be set to specify the behavior of the ForceField.
67        - @b forcedirection The direction and the strength of the homogenous force field. Default is 0,-400,0.
68        - @b velocity The amount of force the ForceField excerts. Default is 100.
69        - @b diameter The diameter of the ForceField. Default is 500.
70        - @b length The length of the ForceField. Default is 2000.
71        - @b mode The mode the ForceField is in. For mode:
72            - <em>tube</em> A ForceField which exerts force only in the direction it is oriented. The force is only exerted on objects that are in a tube of length <em>length</em> and diameter <em>diameter</em> (with rounded start and end faces, so in fact the <em>length</em> parameter specifies a ball with <code>origin + length/2</code> as the center and <code>length/2</code> as the radius). The magintude of the force is proportional to the <em>velocity</em>, being highest when an object is in the middle of the tube (radius-wise), linearly decreasing with greater radii and finally reaching zero, when the object is <code>diameter/2</code> away from the orientation vector.
73            - <em>sphere</em> A Force Field which exerts force radially away from itself, with the greatest magnitude (proportional to <em>velocity</em>) being in the origin of the ForceField, linearly decreasing with respect to the distance to the origin and finally reaching zero at distance <code>diameter/2</code>.
74            Default is <em>tube</em>.
75            - <em>invertedSphere</em> A ForceField which excerts force radially towards itself, with the highest force at the boundary of the sphere, linear decreasing until reaching a distance of <code>radius-length</code> from the origin, where the force reaches zero.
76
77    @author
78        Aurelian Jaggi
79
80    @author
81        Damian 'Mozork' Frick
82
83    @ingroup Objects
84    */
85    class _ObjectsExport ForceField : public StaticEntity, public Tickable
86    {
87        public:
88            ForceField(Context* context);
89            virtual ~ForceField();
90
91            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Creates a ForceField object through XML.
92            void registerVariables(); //!< Registers the variables that should get synchronised over the network
93            virtual void tick(float dt) override; //!< A method that is called every tick.
94           
95
96            /**
97            @brief Set the velocity of the ForceField.
98            @param vel The velocity to be set.
99            */
100            inline void setFieldVelocity(float vel)
101                { this->velocity_ = vel; }
102            /**
103            @brief Get the velocity of the ForceField.
104            @return Returns the velocity of the ForceField.
105            */
106            inline float getFieldVelocity()
107                { return this->velocity_; }
108
109            /**
110            @brief Set the diameter of the ForceField. In mode StellarBody this stands for the outer radius.
111            @param diam The diameter to be set.
112            */
113            inline void setDiameter(float diam)
114                { this->radius_ = diam/2; }
115            /**
116            @brief Get the diameter of the ForceField. In mode StellarBody this stands for the outer radius.
117            @return Returns the diameter of the ForceField.
118            */
119            inline float getDiameter()
120                { return this->radius_*2; }
121       
122            /**
123            @brief Set the diameter of the stellar body for the Newtonian ForceField.
124            @param massDiam The diameter of the stellar body.
125            */
126            inline void setMassDiameter(float massDiam)
127                { this->massRadius_ = massDiam/2; }
128       
129            /**
130            @brief Get the diameter of the stellar body for the Newtonian ForceField.
131            @return float Returns the diameter of the stellar body.
132            */
133            inline float getMassDiameter()
134                { return this->massRadius_*2; }
135
136            /**
137            @brief Set the length of the ForceField.
138            @param l The length to be set.
139            */
140            inline void setLength(float l)
141                { this->halfLength_ = l/2; }
142            /**
143            @brief Get the length of the ForceField.
144            @return Returns the length of the ForceField.
145            */
146            inline float getLength()
147                { return this->halfLength_*2; }
148
149            inline void setForceDirection(Vector3 forcedir)
150                { this->forceDirection_ = forcedir; }
151
152            inline Vector3 getForceDirection()
153                { return this->forceDirection_; }
154
155
156            void setMode(const std::string& mode); //!< Set the mode of the ForceField.
157            const std::string& getMode(void); //!< Get the mode of the ForceField.
158
159            //! Strings to represent the modes.
160            static const std::string modeTube_s;
161            static const std::string modeSphere_s;
162            static const std::string modeInvertedSphere_s;
163            static const std::string modeNewtonianGravity_s;
164            static const std::string modeHomogen_s;
165
166        private:
167            float velocity_; //!< The velocity of the ForceField.
168            float radius_; //!< The radius of the ForceField.
169            float massRadius_; //!< The radius of the stellar body for the Newtonian ForceField.
170            float halfLength_; //!< Half of the length of the ForceField.
171            ForceFieldMode mode_; //!< The mode of the ForceField.
172           
173            //! Gravitational constant for Newtonian ForceFields.
174            static const float gravConstant_;
175            //! Attenuation factor for Newtonian ForceFields
176            static const float attenFactor_;
177            Vector3 forceDirection_;
178  };
179}
180
181#endif
Note: See TracBrowser for help on using the repository browser.