[6832] | 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 | * Oli Scheuss |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | #include "Drone.h" |
---|
| 30 | |
---|
| 31 | #include "core/XMLPort.h" |
---|
| 32 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 33 | |
---|
| 34 | namespace orxonox |
---|
| 35 | { |
---|
| 36 | CreateFactory(Drone); |
---|
| 37 | /** |
---|
| 38 | @brief |
---|
| 39 | Constructor. Registers the object and initializes some default values. |
---|
| 40 | */ |
---|
| 41 | Drone::Drone(BaseObject* creator) : Pawn(creator) |
---|
| 42 | { |
---|
[7039] | 43 | RegisterObject(Drone); |
---|
[6832] | 44 | |
---|
| 45 | this->myController_ = 0; |
---|
| 46 | |
---|
| 47 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
| 48 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
[6991] | 49 | this->setRadarVisibility(false); |
---|
[6832] | 50 | this->setCollisionType(WorldEntity::Dynamic); |
---|
| 51 | |
---|
| 52 | myController_ = new DroneController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator. |
---|
[6847] | 53 | myController_->setDrone(this); |
---|
| 54 | |
---|
[6832] | 55 | this->setController(myController_); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | @brief |
---|
| 60 | Destructor. Destroys controller, if present. |
---|
| 61 | */ |
---|
| 62 | Drone::~Drone() |
---|
| 63 | { |
---|
| 64 | if( this->isInitialized() && this->myController_ ) |
---|
| 65 | delete this->myController_; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | @brief |
---|
| 70 | Method for creating a Drone through XML. |
---|
| 71 | */ |
---|
| 72 | void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 73 | { |
---|
| 74 | SUPER(Drone, XMLPort, xmlelement, mode); |
---|
| 75 | |
---|
[7039] | 76 | XMLPortParam(Drone, "primaryThrust_", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); |
---|
| 77 | XMLPortParam(Drone, "auxilaryThrust_", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode); |
---|
| 78 | XMLPortParam(Drone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode); |
---|
[6991] | 79 | XMLPortParam(Drone, "maxDistanceToOwner_", setMaxDistanceToOwner, getMaxDistanceToOwner, xmlelement, mode); |
---|
| 80 | XMLPortParam(Drone, "minDistanceToOwner_", setMinDistanceToOwner, getMinDistanceToOwner, xmlelement, mode); |
---|
[6832] | 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | @brief |
---|
| 86 | Defines which actions the Drone has to take in each tick. |
---|
| 87 | @param dt |
---|
| 88 | The length of the tick. |
---|
| 89 | */ |
---|
| 90 | void Drone::tick(float dt) |
---|
| 91 | { |
---|
| 92 | SUPER(Drone, tick, dt); |
---|
| 93 | |
---|
| 94 | //if (this->hasLocalController()) |
---|
| 95 | //{ |
---|
| 96 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); |
---|
| 97 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); |
---|
| 98 | if (this->localLinearAcceleration_.z() > 0) |
---|
| 99 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); |
---|
| 100 | else |
---|
| 101 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); |
---|
| 102 | this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); |
---|
| 103 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
| 104 | |
---|
| 105 | this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; |
---|
| 106 | this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); |
---|
| 107 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
| 108 | //} |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | @brief |
---|
| 113 | Moves the Drone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. |
---|
| 114 | @param value |
---|
| 115 | The vector determining the amount of the movement. |
---|
| 116 | */ |
---|
| 117 | void Drone::moveFrontBack(const Vector2& value) |
---|
| 118 | { |
---|
| 119 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | @brief |
---|
| 124 | Moves the Drone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector. |
---|
| 125 | @param value |
---|
| 126 | The vector determining the amount of the movement. |
---|
| 127 | */ |
---|
| 128 | void Drone::moveRightLeft(const Vector2& value) |
---|
| 129 | { |
---|
| 130 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | @brief |
---|
| 135 | Moves the Drone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector. |
---|
| 136 | @param value |
---|
| 137 | The vector determining the amount of the movement. |
---|
| 138 | */ |
---|
| 139 | void Drone::moveUpDown(const Vector2& value) |
---|
| 140 | { |
---|
| 141 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | @brief |
---|
| 146 | Rotates the Drone around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 147 | @param value |
---|
| 148 | The vector determining the amount of the angular movement. |
---|
| 149 | */ |
---|
| 150 | void Drone::rotateYaw(const Vector2& value) |
---|
| 151 | { |
---|
[6918] | 152 | this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); |
---|
[6832] | 153 | } |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | @brief |
---|
| 157 | Rotates the Drone around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 158 | @param value |
---|
| 159 | The vector determining the amount of the angular movement. |
---|
| 160 | */ |
---|
| 161 | void Drone::rotatePitch(const Vector2& value) |
---|
| 162 | { |
---|
| 163 | this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | @brief |
---|
| 168 | Rotates the Drone around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 169 | @param value |
---|
| 170 | The vector determining the amount of the angular movement. |
---|
| 171 | */ |
---|
| 172 | void Drone::rotateRoll(const Vector2& value) |
---|
| 173 | { |
---|
| 174 | this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | } |
---|