Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8923 was 8397, checked in by youngk, 14 years ago

Added Newtonian Gravitation to the selection of force fields.

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