Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7864 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
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
[2954]26 *
27 */
28
[7601]29/**
30    @file ForceField.h
31    @brief Definition of the ForceField class.
32    @ingroup Objects
33*/
[2954]34
35#ifndef _ForceField_H__
36#define _ForceField_H__
37
[5730]38#include "objects/ObjectsPrereqs.h"
[3196]39
[5693]40#include "tools/interfaces/Tickable.h"
[5735]41#include "worldentities/StaticEntity.h"
[2954]42
43namespace orxonox
44{
[7673]45
46    /**
47    @brief
48        The mode of the ForceField.
[7676]49
50    @ingroup Objects
[7673]51    */
[7674]52    namespace forceFieldMode
[7673]53    {
54        enum Value {
55            tube, //!< The ForceField has a tube shape.
[7677]56            sphere, //!< The ForceField has a spherical shape.
57            invertedSphere //!< The ForceField has a spherical shape but "inverted" behavior.
[7673]58        };
59    }
60
61    /**
62    @brief
[7678]63        Implements a force field, that applies a force to any @ref orxonox::MobileEntity "MobileEntity" that enters its range.
[7676]64
[7673]65        The following parameters can be set to specify the behavior of the ForceField.
[7676]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.
[7673]69        - @b mode The mode the ForceField is in. For mode:
[7677]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.
[7676]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>.
[7678]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.
[7676]74
[7673]75    @author
76        Aurelian Jaggi
[7676]77
[7673]78    @author
79        Damian 'Mozork' Frick
[7676]80
81    @ingroup Objects
[7673]82    */
[5730]83    class _ObjectsExport ForceField : public StaticEntity, public Tickable
[3064]84    {
[7673]85        public:
86            ForceField(BaseObject* creator);
87            virtual ~ForceField();
[2954]88
[7676]89            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML.
[7801]90            void registerVariables(); //!< Registers the variables that should get synchronised over the network
[7676]91            virtual void tick(float dt); //!< A method that is called every tick.
[7801]92           
[7676]93
94            /**
95            @brief Set the velocity of the ForceField.
96            @param vel The velocity to be set.
97            */
[7673]98            inline void setVelocity(float vel)
99                { this->velocity_ = vel; }
[7676]100            /**
101            @brief Get the velocity of the ForceField.
102            @return Returns the velocity of the ForceField.
103            */
[7673]104            inline float getVelocity()
105                { return this->velocity_; }
[5693]106
[7676]107            /**
108            @brief Set the diameter of the ForceField.
109            @param diam The diameter to be set.
110            */
[7673]111            inline void setDiameter(float diam)
[7676]112                { this->radius_ = diam/2; }
113            /**
114            @brief Get the diameter of the ForceField.
115            @return Returns the diameter of the ForceField.
116            */
[7673]117            inline float getDiameter()
[7676]118                { return this->radius_*2; }
[5693]119
[7676]120            /**
121            @brief Set the length of the ForceField.
122            @param l The length to be set.
123            */
[7673]124            inline void setLength(float l)
[7676]125                { this->halfLength_ = l/2; }
126            /**
127            @brief Get the length of the ForceField.
128            @return Returns the length of the ForceField.
129            */
[7673]130            inline float getLength()
[7676]131                { return this->halfLength_*2; }
[2954]132
[7676]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
[7673]136        private:
[7676]137            //! Strings to represent the modes.
[7674]138            static const std::string modeTube_s;
139            static const std::string modeSphere_s;
[7677]140            static const std::string modeInvertedSphere_s;
[7676]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.
[7801]145            int mode_; //!< The mode of the ForceField.
[2954]146  };
147}
148
149#endif
Note: See TracBrowser for help on using the repository browser.