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