Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/modules/objects/ForceField.h @ 10255

Last change on this file since 10255 was 7801, checked in by dafrick, 14 years ago

Merging presentation2 branch back to trunk.

  • Property svn:eol-style set to native
File size: 5.9 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            void registerVariables(); //!< Registers the variables that should get synchronised over the network
91            virtual void tick(float dt); //!< A method that is called every tick.
92           
93
94            /**
95            @brief Set the velocity of the ForceField.
96            @param vel The velocity to be set.
97            */
98            inline void setVelocity(float vel)
99                { this->velocity_ = vel; }
100            /**
101            @brief Get the velocity of the ForceField.
102            @return Returns the velocity of the ForceField.
103            */
104            inline float getVelocity()
105                { return this->velocity_; }
106
107            /**
108            @brief Set the diameter of the ForceField.
109            @param diam The diameter to be set.
110            */
111            inline void setDiameter(float diam)
112                { this->radius_ = diam/2; }
113            /**
114            @brief Get the diameter of the ForceField.
115            @return Returns the diameter of the ForceField.
116            */
117            inline float getDiameter()
118                { return this->radius_*2; }
119
120            /**
121            @brief Set the length of the ForceField.
122            @param l The length to be set.
123            */
124            inline void setLength(float l)
125                { this->halfLength_ = l/2; }
126            /**
127            @brief Get the length of the ForceField.
128            @return Returns the length of the ForceField.
129            */
130            inline float getLength()
131                { return this->halfLength_*2; }
132
133            void setMode(const std::string& mode); //!< Set the mode of the ForceField.
134            const std::string& getMode(void); //!< Get the mode of the ForceField.
135
136        private:
137            //! Strings to represent the modes.
138            static const std::string modeTube_s;
139            static const std::string modeSphere_s;
140            static const std::string modeInvertedSphere_s;
141
142            float velocity_; //!< The velocity of the ForceField.
143            float radius_; //!< The radius of the ForceField.
144            float halfLength_; //!< Half of the length of the ForceField.
145            int mode_; //!< The mode of the ForceField.
146  };
147}
148
149#endif
Note: See TracBrowser for help on using the repository browser.