[9460] | 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: |
---|
[10049] | 23 | * Marian Runo, Martin Mueller |
---|
[9460] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @brief Definition of the Turret class. |
---|
| 31 | @ingroup Objects |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #ifndef _Turret_H__ |
---|
| 35 | #define _Turret_H__ |
---|
| 36 | |
---|
| 37 | #include "objects/ObjectsPrereqs.h" |
---|
[10031] | 38 | #include "worldentities/pawns/Pawn.h" |
---|
[9460] | 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[10049] | 42 | /** |
---|
| 43 | @brief |
---|
| 44 | Creates a turret with limited rotation. The point of this class is to be able to attach |
---|
| 45 | a turret to a spaceship or a spacestation which is more or less completely autonomous in |
---|
| 46 | it's behaviour. |
---|
| 47 | |
---|
[10060] | 48 | This class also contains a custom local coordinate system, which gets initially rotated through xml, and |
---|
| 49 | afterwards is updated with the parent's rotation (if there is one). This allows for almost trivialal calculation |
---|
| 50 | of pitch, yaw and roll through coordinate transformation. (TODO: Ogre should do something like this already, investigate...) |
---|
| 51 | |
---|
| 52 | |
---|
[10049] | 53 | @note |
---|
| 54 | The rotation isn't limited "physically". You have to call isInRange to find out if the turret is allowed to shoot at a target. |
---|
| 55 | */ |
---|
[10021] | 56 | class _ObjectsExport Turret : public Pawn |
---|
[9460] | 57 | { |
---|
| 58 | public: |
---|
[9667] | 59 | Turret(Context* context); |
---|
[9460] | 60 | virtual ~Turret(); |
---|
| 61 | |
---|
| 62 | virtual void rotatePitch(const Vector2& value); |
---|
[10004] | 63 | virtual void rotateYaw(const Vector2& value); |
---|
| 64 | virtual void rotateRoll(const Vector2& value); |
---|
[10060] | 65 | virtual float isInRange(const WorldEntity* target) const; |
---|
[10044] | 66 | virtual void aimAtPosition(const Vector3 &position); |
---|
[9460] | 67 | |
---|
[9469] | 68 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
[10004] | 69 | virtual void tick(float dt); |
---|
[9460] | 70 | |
---|
[10049] | 71 | /** @brief Sets the maximum distance the turret is allowed to shoot. @param radius The distance*/ |
---|
| 72 | inline void setMaxAttackRadius(float radius) |
---|
| 73 | { this->maxAttackRadius_ = radius; } |
---|
[10031] | 74 | |
---|
[10049] | 75 | /** @brief Sets the minimum distance the turret is allowed to shoot. @param radius The distance*/ |
---|
| 76 | inline void setMinAttackRadius(float radius) |
---|
| 77 | { this->minAttackRadius_ = radius; } |
---|
| 78 | |
---|
| 79 | /** @brief Sets the maximum pitch the turret can have (in both directions). @param pitch The pitch (in one direction)*/ |
---|
[10044] | 80 | inline void setMaxPitch(float pitch) |
---|
| 81 | { this->maxPitch_ = pitch; } |
---|
| 82 | |
---|
[10049] | 83 | /** @brief Sets the maximum yaw the turret can have (in both directions). @param yaw The yaw (in one direction)*/ |
---|
[10044] | 84 | inline void setMaxYaw(float yaw) |
---|
| 85 | { this->maxYaw_ = yaw; } |
---|
| 86 | |
---|
[10049] | 87 | /** @brief Returns the maximum distance the turret is allowed to shoot. @return The distance */ |
---|
| 88 | inline float getMaxAttackRadius() const |
---|
| 89 | { return this->maxAttackRadius_; } |
---|
[10044] | 90 | |
---|
[10049] | 91 | /** @brief Returns the minimum distance the turret is allowed to shoot. @return The distance */ |
---|
| 92 | inline float getMinAttackRadius() const |
---|
| 93 | { return this->minAttackRadius_; } |
---|
| 94 | |
---|
| 95 | /** @brief Returns the maximum pitch the turret can have. @return The pitch */ |
---|
[10044] | 96 | inline float getMaxPitch() const |
---|
| 97 | { return this->maxPitch_; } |
---|
| 98 | |
---|
[10049] | 99 | /** @brief Returns the maximum yaw the turret can have. @return The yaw */ |
---|
[10044] | 100 | inline float getMaxYaw() const |
---|
| 101 | { return this->maxYaw_; } |
---|
| 102 | |
---|
| 103 | protected: |
---|
[10049] | 104 | Vector3 startDir_; //!< The initial facing direction, in local coordinates. |
---|
| 105 | Vector3 localZ_; //!< The local z-axis, includes for the parent's rotation and rotations done in xml. |
---|
| 106 | Vector3 localY_; //!< The local y-axis, includes for the parent's rotation and rotations done in xml. |
---|
| 107 | Vector3 localX_; //!< The local x-axis, includes for the parent's rotation and rotations done in xml. |
---|
| 108 | Quaternion rotation_; //!< The rotation to be done by the turret. |
---|
[10044] | 109 | |
---|
[9460] | 110 | private: |
---|
[10049] | 111 | bool once_; //!< Flag for executing code in the tick function only once. |
---|
[10044] | 112 | |
---|
[10049] | 113 | Vector3 localZStart_; //!< The local z-axis, without the parent's rotation. |
---|
| 114 | Vector3 localYStart_; //!< The local y-axis, without the parent's rotation. |
---|
| 115 | Vector3 localXStart_; //!< The local x-axis, without the parent's rotation. |
---|
| 116 | float maxAttackRadius_; //!< The maximum distance the turret is allowed to shoot. |
---|
| 117 | float minAttackRadius_; //!< The minimum distance the turret is allowed to shoot. |
---|
| 118 | Ogre::Real maxPitch_; //!< The maxmium pitch the turret can have (on one side). |
---|
| 119 | Ogre::Real maxYaw_; //!< The maxmium yaw the turret can have (on one side). |
---|
| 120 | float rotationThrust_; //!< The velocity the turret rotates with. |
---|
[10018] | 121 | |
---|
[9460] | 122 | }; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | #endif |
---|