[6778] | 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 "RocketDrone.h" |
---|
| 30 | |
---|
| 31 | #include "core/XMLPort.h" |
---|
| 32 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 33 | #include "graphics/Model.h" |
---|
| 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
| 37 | CreateFactory(RocketDrone); |
---|
| 38 | // put your code in here: |
---|
| 39 | // create the factory for the drone |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | @brief |
---|
| 43 | Constructor. Registers the object and initializes some default values. |
---|
| 44 | */ |
---|
| 45 | RocketDrone::RocketDrone(BaseObject* creator) : ControllableEntity(creator) |
---|
| 46 | { |
---|
| 47 | RegisterObject(RocketDrone); |
---|
| 48 | // put your code in here: |
---|
| 49 | // - register the drone class to the core |
---|
| 50 | this->myController_ = 0; |
---|
| 51 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
| 52 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
| 53 | this->primaryThrust_ = 100; |
---|
| 54 | this->auxilaryThrust_ = 100; |
---|
| 55 | this->rotationThrust_ = 10; |
---|
| 56 | Model *model = new Model(this); |
---|
| 57 | model->setMeshSource("rocket.mesh"); |
---|
| 58 | model->scale(0.7f); |
---|
| 59 | this->setCollisionType(WorldEntity::Dynamic); |
---|
| 60 | |
---|
| 61 | myController_ = new RocketController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator. |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | @brief |
---|
| 66 | Destructor. Destroys controller, if present. |
---|
| 67 | */ |
---|
| 68 | RocketDrone::~RocketDrone() |
---|
| 69 | { |
---|
| 70 | if( this->isInitialized() && this->myController_ ) |
---|
| 71 | delete this->myController_; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | @brief |
---|
| 76 | Method for creating a Drone through XML. |
---|
| 77 | */ |
---|
| 78 | void RocketDrone::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 79 | { |
---|
| 80 | // this calls the XMLPort function of the parent class |
---|
| 81 | SUPER(RocketDrone, XMLPort, xmlelement, mode); |
---|
| 82 | |
---|
| 83 | // put your code in here: |
---|
| 84 | // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport |
---|
| 85 | // make sure that the set- and get-functions exist. |
---|
| 86 | // variables can be added by the following command |
---|
| 87 | // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode) |
---|
| 88 | XMLPortParam(RocketDrone, "primaryThrust_", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); |
---|
| 89 | XMLPortParam(RocketDrone, "auxilaryThrust_", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode); |
---|
| 90 | XMLPortParam(RocketDrone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode); |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | @brief |
---|
| 96 | Defines which actions the Drone has to take in each tick. |
---|
| 97 | @param dt |
---|
| 98 | The length of the tick. |
---|
| 99 | */ |
---|
| 100 | void RocketDrone::tick(float dt) |
---|
| 101 | { |
---|
| 102 | SUPER(RocketDrone, tick, dt); |
---|
| 103 | |
---|
| 104 | //if (this->hasLocalController()) |
---|
| 105 | //{ |
---|
| 106 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); |
---|
| 107 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); |
---|
| 108 | if (this->localLinearAcceleration_.z() > 0) |
---|
| 109 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); |
---|
| 110 | else |
---|
| 111 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); |
---|
| 112 | this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); |
---|
| 113 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
| 114 | |
---|
| 115 | this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; |
---|
| 116 | this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); |
---|
| 117 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
| 118 | //} |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | @brief |
---|
| 123 | Moves the Drone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. |
---|
| 124 | @param value |
---|
| 125 | The vector determining the amount of the movement. |
---|
| 126 | */ |
---|
| 127 | void RocketDrone::moveFrontBack(const Vector2& value) |
---|
| 128 | { |
---|
| 129 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | @brief |
---|
| 134 | Moves the Drone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector. |
---|
| 135 | @param value |
---|
| 136 | The vector determining the amount of the movement. |
---|
| 137 | */ |
---|
| 138 | void RocketDrone::moveRightLeft(const Vector2& value) |
---|
| 139 | { |
---|
| 140 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | @brief |
---|
| 145 | Moves the Drone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector. |
---|
| 146 | @param value |
---|
| 147 | The vector determining the amount of the movement. |
---|
| 148 | */ |
---|
| 149 | void RocketDrone::moveUpDown(const Vector2& value) |
---|
| 150 | { |
---|
| 151 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /** |
---|
| 155 | @brief |
---|
| 156 | Rotates the Drone around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 157 | @param value |
---|
| 158 | The vector determining the amount of the angular movement. |
---|
| 159 | */ |
---|
| 160 | void RocketDrone::rotateYaw(const Vector2& value) |
---|
| 161 | { |
---|
| 162 | this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /** |
---|
| 166 | @brief |
---|
| 167 | Rotates the Drone around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 168 | @param value |
---|
| 169 | The vector determining the amount of the angular movement. |
---|
| 170 | */ |
---|
| 171 | void RocketDrone::rotatePitch(const Vector2& value) |
---|
| 172 | { |
---|
| 173 | this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | @brief |
---|
| 178 | Rotates the Drone around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
| 179 | @param value |
---|
| 180 | The vector determining the amount of the angular movement. |
---|
| 181 | */ |
---|
| 182 | void RocketDrone::rotateRoll(const Vector2& value) |
---|
| 183 | { |
---|
| 184 | this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | //void RocketDrone::setOwner(Pawn* owner) |
---|
| 188 | //{ |
---|
| 189 | // this->owner_ = owner; |
---|
| 190 | //} |
---|
| 191 | |
---|
| 192 | } |
---|