Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/ForceField.h @ 10108

Last change on this file since 10108 was 9939, checked in by jo, 11 years ago

presentationHS13 branch merged into trunk

  • Property svn:eol-style set to native
File size: 7.6 KB
RevLine 
[9939]1
[2954]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:
[7673]26 *      Damian 'Mozork' Frick
[8397]27 *      Kevin Young
[2954]28 *
29 */
30
[7601]31/**
32    @file ForceField.h
33    @brief Definition of the ForceField class.
34    @ingroup Objects
35*/
[2954]36
37#ifndef _ForceField_H__
38#define _ForceField_H__
39
[5730]40#include "objects/ObjectsPrereqs.h"
[3196]41
[5693]42#include "tools/interfaces/Tickable.h"
[5735]43#include "worldentities/StaticEntity.h"
[2954]44
45namespace orxonox
46{
[7673]47
48    /**
49    @brief
50        The mode of the ForceField.
[7676]51
52    @ingroup Objects
[7673]53    */
[7674]54    namespace forceFieldMode
[7673]55    {
56        enum Value {
57            tube, //!< The ForceField has a tube shape.
[7677]58            sphere, //!< The ForceField has a spherical shape.
[8397]59            invertedSphere, //!< The ForceField has a spherical shape but "inverted" behavior.
[9939]60            newtonianGravity, //!< The ForceField imitates Newtonian gravitation for use in stellar bodies.
61            homogen //!< Local homogenous Force field with changeable direction for the Space Station
[7673]62        };
63    }
64
65    /**
66    @brief
[7678]67        Implements a force field, that applies a force to any @ref orxonox::MobileEntity "MobileEntity" that enters its range.
[7676]68
[7673]69        The following parameters can be set to specify the behavior of the ForceField.
[9939]70        - @b forcedirection The direction and the strength of the homogenous force field. Default is 0,-400,0.
[7676]71        - @b velocity The amount of force the ForceField excerts. Default is 100.
72        - @b diameter The diameter of the ForceField. Default is 500.
73        - @b length The length of the ForceField. Default is 2000.
[7673]74        - @b mode The mode the ForceField is in. For mode:
[7677]75            - <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.
[7676]76            - <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>.
77            Default is <em>tube</em>.
[7678]78            - <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.
[7676]79
[7673]80    @author
81        Aurelian Jaggi
[7676]82
[7673]83    @author
84        Damian 'Mozork' Frick
[7676]85
86    @ingroup Objects
[7673]87    */
[5730]88    class _ObjectsExport ForceField : public StaticEntity, public Tickable
[3064]89    {
[7673]90        public:
[9667]91            ForceField(Context* context);
[7673]92            virtual ~ForceField();
[2954]93
[7676]94            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML.
[7801]95            void registerVariables(); //!< Registers the variables that should get synchronised over the network
[7676]96            virtual void tick(float dt); //!< A method that is called every tick.
[7801]97           
[7676]98
99            /**
100            @brief Set the velocity of the ForceField.
101            @param vel The velocity to be set.
102            */
[7673]103            inline void setVelocity(float vel)
104                { this->velocity_ = vel; }
[7676]105            /**
106            @brief Get the velocity of the ForceField.
107            @return Returns the velocity of the ForceField.
108            */
[7673]109            inline float getVelocity()
110                { return this->velocity_; }
[5693]111
[7676]112            /**
[8397]113            @brief Set the diameter of the ForceField. In mode StellarBody this stands for the outer radius.
[7676]114            @param diam The diameter to be set.
115            */
[7673]116            inline void setDiameter(float diam)
[7676]117                { this->radius_ = diam/2; }
118            /**
[8397]119            @brief Get the diameter of the ForceField. In mode StellarBody this stands for the outer radius.
[7676]120            @return Returns the diameter of the ForceField.
121            */
[7673]122            inline float getDiameter()
[7676]123                { return this->radius_*2; }
[8397]124       
125            /**
126            @brief Set the diameter of the stellar body for the Newtonian ForceField.
127            @param massDiam The diameter of the stellar body.
128            */
129            inline void setMassDiameter(float massDiam)
130                { this->massRadius_ = massDiam/2; }
131       
132            /**
133            @brief Get the diameter of the stellar body for the Newtonian ForceField.
134            @return float Returns the diameter of the stellar body.
135            */
136            inline float getMassDiameter()
137                { return this->massRadius_*2; }
[5693]138
[7676]139            /**
140            @brief Set the length of the ForceField.
141            @param l The length to be set.
142            */
[7673]143            inline void setLength(float l)
[7676]144                { this->halfLength_ = l/2; }
145            /**
146            @brief Get the length of the ForceField.
147            @return Returns the length of the ForceField.
148            */
[7673]149            inline float getLength()
[7676]150                { return this->halfLength_*2; }
[2954]151
[9939]152            inline void setForceDirection(Vector3 forcedir)
153                { this->forceDirection_ = forcedir; }
154
155            inline Vector3 getForceDirection()
156                { return this->forceDirection_; }
157
158
[7676]159            void setMode(const std::string& mode); //!< Set the mode of the ForceField.
160            const std::string& getMode(void); //!< Get the mode of the ForceField.
161
[7673]162        private:
[7676]163            //! Strings to represent the modes.
[7674]164            static const std::string modeTube_s;
165            static const std::string modeSphere_s;
[7677]166            static const std::string modeInvertedSphere_s;
[8397]167            static const std::string modeNewtonianGravity_s;
[7676]168
[9939]169            static const std::string modeHomogen_s;
170
[7676]171            float velocity_; //!< The velocity of the ForceField.
172            float radius_; //!< The radius of the ForceField.
[8397]173            float massRadius_; //!< The radius of the stellar body for the Newtonian ForceField.
[7676]174            float halfLength_; //!< Half of the length of the ForceField.
[7801]175            int mode_; //!< The mode of the ForceField.
[8397]176           
177            //! Gravitational constant for Newtonian ForceFields.
178            static const float gravConstant_;
179            //! Attenuation factor for Newtonian ForceFields
180            static const float attenFactor_;
[9939]181            Vector3 forceDirection_;
[2954]182  };
183}
184
185#endif
Note: See TracBrowser for help on using the repository browser.