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 "OrxonoxStableHeaders.h" |
---|
30 | #include "Drone.h" |
---|
31 | |
---|
32 | #include "core/XMLPort.h" |
---|
33 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | // PLACE YOUR CODE HERE |
---|
38 | // create the factory for the drone |
---|
39 | |
---|
40 | Drone::Drone(BaseObject* creator) : ControllableEntity(creator) |
---|
41 | { |
---|
42 | this->myController_ = 0; |
---|
43 | // PLACE YOUR CODE HERE |
---|
44 | // - register the drone class to the core |
---|
45 | // - create a new controller and pass our this pointer to it as creator |
---|
46 | |
---|
47 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
48 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
49 | this->primaryThrust_ = 100; |
---|
50 | this->auxilaryThrust_ = 100; |
---|
51 | this->rotationThrust_ = 10; |
---|
52 | this->steering_ = Vector3::ZERO; |
---|
53 | |
---|
54 | this->setCollisionType(WorldEntity::Dynamic); |
---|
55 | |
---|
56 | this->myController_ = new DroneController(this); |
---|
57 | } |
---|
58 | |
---|
59 | Drone::~Drone() |
---|
60 | { |
---|
61 | if (this->isInitialized() && this->myController_) |
---|
62 | delete this->myController_; |
---|
63 | } |
---|
64 | |
---|
65 | void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
66 | { |
---|
67 | // this calls the XMLPort function of the parent class |
---|
68 | SUPER(Drone, XMLPort, xmlelement, mode); |
---|
69 | |
---|
70 | // PLACE YOUR CODE HERE |
---|
71 | // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport |
---|
72 | // variables can be added by the following command |
---|
73 | // XMLPortParamVariable(Class, "xml-attribute-name", variable_name, xmlelement, mode); |
---|
74 | } |
---|
75 | |
---|
76 | void Drone::tick(float dt) |
---|
77 | { |
---|
78 | // PLACE YOUR CODE HERE |
---|
79 | // make sure the tick function of the base class gets called here |
---|
80 | |
---|
81 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); |
---|
82 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); |
---|
83 | if (this->localLinearAcceleration_.z() > 0) |
---|
84 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); |
---|
85 | else |
---|
86 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); |
---|
87 | this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); |
---|
88 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
89 | |
---|
90 | this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; |
---|
91 | this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); |
---|
92 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | void Drone::moveFrontBack(const Vector2& value) |
---|
97 | { |
---|
98 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); |
---|
99 | this->steering_.z = -value.x; |
---|
100 | } |
---|
101 | |
---|
102 | void Drone::moveRightLeft(const Vector2& value) |
---|
103 | { |
---|
104 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); |
---|
105 | this->steering_.x = value.x; |
---|
106 | } |
---|
107 | |
---|
108 | void Drone::moveUpDown(const Vector2& value) |
---|
109 | { |
---|
110 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); |
---|
111 | this->steering_.y = value.x; |
---|
112 | } |
---|
113 | |
---|
114 | void Drone::rotateYaw(const Vector2& value) |
---|
115 | { |
---|
116 | this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x); |
---|
117 | } |
---|
118 | |
---|
119 | void Drone::rotatePitch(const Vector2& value) |
---|
120 | { |
---|
121 | this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); |
---|
122 | } |
---|
123 | |
---|
124 | void Drone::rotateRoll(const Vector2& value) |
---|
125 | { |
---|
126 | this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); |
---|
127 | } |
---|
128 | } |
---|