[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 | |
---|
| 43 | namespace 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. |
---|
| 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 | */ |
---|
[7673] | 96 | inline void setVelocity(float vel) |
---|
| 97 | { this->velocity_ = vel; } |
---|
[7676] | 98 | /** |
---|
| 99 | @brief Get the velocity of the ForceField. |
---|
| 100 | @return Returns the velocity of the ForceField. |
---|
| 101 | */ |
---|
[7673] | 102 | inline float getVelocity() |
---|
| 103 | { return this->velocity_; } |
---|
[5693] | 104 | |
---|
[7676] | 105 | /** |
---|
| 106 | @brief Set the diameter of the ForceField. |
---|
| 107 | @param diam The diameter to be set. |
---|
| 108 | */ |
---|
[7673] | 109 | inline void setDiameter(float diam) |
---|
[7676] | 110 | { this->radius_ = diam/2; } |
---|
| 111 | /** |
---|
| 112 | @brief Get the diameter of the ForceField. |
---|
| 113 | @return Returns the diameter of the ForceField. |
---|
| 114 | */ |
---|
[7673] | 115 | inline float getDiameter() |
---|
[7676] | 116 | { return this->radius_*2; } |
---|
[5693] | 117 | |
---|
[7676] | 118 | /** |
---|
| 119 | @brief Set the length of the ForceField. |
---|
| 120 | @param l The length to be set. |
---|
| 121 | */ |
---|
[7673] | 122 | inline void setLength(float l) |
---|
[7676] | 123 | { this->halfLength_ = l/2; } |
---|
| 124 | /** |
---|
| 125 | @brief Get the length of the ForceField. |
---|
| 126 | @return Returns the length of the ForceField. |
---|
| 127 | */ |
---|
[7673] | 128 | inline float getLength() |
---|
[7676] | 129 | { return this->halfLength_*2; } |
---|
[2954] | 130 | |
---|
[7676] | 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 | |
---|
[7673] | 134 | private: |
---|
[7676] | 135 | //! Strings to represent the modes. |
---|
[7674] | 136 | static const std::string modeTube_s; |
---|
| 137 | static const std::string modeSphere_s; |
---|
[7677] | 138 | static const std::string modeInvertedSphere_s; |
---|
[7676] | 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. |
---|
[2954] | 144 | }; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | #endif |
---|