Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/orxonox/worldentities/Drone.cc @ 6482

Last change on this file since 6482 was 6482, checked in by rgrieder, 15 years ago

Merged HS 2009 tutorial in new FS 2010 branch. This includes all the previous tutorials as well.

File size: 6.2 KB
Line 
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
34namespace orxonox
35{
36    // put your code in here:
37    // create the factory for the drone
38    CreateFactory(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        // put your code in here:
47        // - register the drone class to the core
48        // - create a new controller and pass our this pointer to it as creator
49        this->myController_ = 0;
50        RegisterObject(Drone);
51       
52        this->localLinearAcceleration_.setValue(0, 0, 0);
53        this->localAngularAcceleration_.setValue(0, 0, 0);
54        this->primaryThrust_  = 100;
55        this->auxilaryThrust_ = 100;
56        this->rotationThrust_ = 10;
57       
58        this->setCollisionType(WorldEntity::Dynamic);
59       
60        myController_ = new DroneController(static_cast<BaseObject*>(this));
61    }
62
63    /**
64    @brief
65        Destructor. Destroys controller, if present.
66    */
67    Drone::~Drone()
68    {
69        if( this->myController_ )
70            delete this->myController_;
71    }
72
73    /**
74    @brief
75        Method for creating a Drone through XML.
76    */
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
82        XMLPortParam(Drone, "primaryThrust",  setPrimaryThrust, getPrimaryThrust,  xmlelement, mode);
83        XMLPortParam(Drone, "auxilaryThrust", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode);
84        XMLPortParam(Drone, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
85    }
86
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    */
93    void Drone::tick(float dt)
94    {
95        SUPER(Drone, tick, dt);
96       
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        //}
112    }
113   
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    */
120    void Drone::moveFrontBack(const Vector2& value)
121    {
122        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
123    }
124
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    */
131    void Drone::moveRightLeft(const Vector2& value)
132    {
133        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
134    }
135
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    */
142    void Drone::moveUpDown(const Vector2& value)
143    {
144        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
145    }
146
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    */
153    void Drone::rotateYaw(const Vector2& value)
154    {
155        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
156    }
157
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    */
164    void Drone::rotatePitch(const Vector2& value)
165    {
166        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
167    }
168
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    */
175    void Drone::rotateRoll(const Vector2& value)
176    {
177        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
178    }
179   
180}
Note: See TracBrowser for help on using the repository browser.