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