Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7676 was 7676, checked in by dafrick, 13 years ago

Some documentation and simplification

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