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