Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7721 was 7678, checked in by dafrick, 14 years ago

Adding documentation for invertedSphere ForceField.

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
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:
25 *      Damian 'Mozork' Frick
26 *
27 */
28
29/**
30    @file ForceField.h
31    @brief Definition of the ForceField class.
32    @ingroup Objects
33*/
34
35#ifndef _ForceField_H__
36#define _ForceField_H__
37
38#include "objects/ObjectsPrereqs.h"
39
40#include "tools/interfaces/Tickable.h"
41#include "worldentities/StaticEntity.h"
42
43namespace orxonox
44{
45
46    /**
47    @brief
48        The mode of the ForceField.
49
50    @ingroup Objects
51    */
52    namespace forceFieldMode
53    {
54        enum Value {
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        };
59    }
60
61    /**
62    @brief
63        Implements a force field, that applies a force to any @ref orxonox::MobileEntity "MobileEntity" that enters its range.
64
65        The following parameters can be set to specify the behavior of the ForceField.
66        - @b velocity The amount of force the ForceField excerts. Default is 100.
67        - @b diameter The diameter of the ForceField. Default is 500.
68        - @b length The length of the ForceField. Default is 2000.
69        - @b mode The mode the ForceField is in. For mode:
70            - <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.
71            - <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>.
72            Default is <em>tube</em>.
73            - <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.
74
75    @author
76        Aurelian Jaggi
77
78    @author
79        Damian 'Mozork' Frick
80
81    @ingroup Objects
82    */
83    class _ObjectsExport ForceField : public StaticEntity, public Tickable
84    {
85        public:
86            ForceField(BaseObject* creator);
87            virtual ~ForceField();
88
89            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML.
90            virtual void tick(float dt); //!< A method that is called every tick.
91
92            /**
93            @brief Set the velocity of the ForceField.
94            @param vel The velocity to be set.
95            */
96            inline void setVelocity(float vel)
97                { this->velocity_ = vel; }
98            /**
99            @brief Get the velocity of the ForceField.
100            @return Returns the velocity of the ForceField.
101            */
102            inline float getVelocity()
103                { return this->velocity_; }
104
105            /**
106            @brief Set the diameter of the ForceField.
107            @param diam The diameter to be set.
108            */
109            inline void setDiameter(float diam)
110                { this->radius_ = diam/2; }
111            /**
112            @brief Get the diameter of the ForceField.
113            @return Returns the diameter of the ForceField.
114            */
115            inline float getDiameter()
116                { return this->radius_*2; }
117
118            /**
119            @brief Set the length of the ForceField.
120            @param l The length to be set.
121            */
122            inline void setLength(float l)
123                { this->halfLength_ = l/2; }
124            /**
125            @brief Get the length of the ForceField.
126            @return Returns the length of the ForceField.
127            */
128            inline float getLength()
129                { return this->halfLength_*2; }
130
131            void setMode(const std::string& mode); //!< Set the mode of the ForceField.
132            const std::string& getMode(void); //!< Get the mode of the ForceField.
133
134        private:
135            //! Strings to represent the modes.
136            static const std::string modeTube_s;
137            static const std::string modeSphere_s;
138            static const std::string modeInvertedSphere_s;
139
140            float velocity_; //!< The velocity of the ForceField.
141            float radius_; //!< The radius of the ForceField.
142            float halfLength_; //!< Half of the length of the ForceField.
143            forceFieldMode::Value mode_; //!< The mode of the ForceField.
144  };
145}
146
147#endif
Note: See TracBrowser for help on using the repository browser.