Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialHS09/src/orxonox/worldentities/Drone.cc @ 10022

Last change on this file since 10022 was 5841, checked in by dafrick, 15 years ago

Removed the code, the PPS students have to insert.

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
39    /**
40    @brief
41        Constructor. Registers the object and initializes some default values.
42    */
43    Drone::Drone(BaseObject* creator) : ControllableEntity(creator)
44    {
45        // put your code in here:
46        // - register the drone class to the core
47        this->myController_ = 0;
48       
49        this->localLinearAcceleration_.setValue(0, 0, 0);
50        this->localAngularAcceleration_.setValue(0, 0, 0);
51        this->primaryThrust_  = 100;
52        this->auxilaryThrust_ = 100;
53        this->rotationThrust_ = 10;
54       
55        this->setCollisionType(WorldEntity::Dynamic);
56       
57        myController_ = new DroneController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator.
58    }
59
60    /**
61    @brief
62        Destructor. Destroys controller, if present.
63    */
64    Drone::~Drone()
65    {
66        if( this->myController_ )
67            delete this->myController_;
68    }
69
70    /**
71    @brief
72        Method for creating a Drone through XML.
73    */
74    void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        // this calls the XMLPort function of the parent class
77        SUPER(Drone, XMLPort, xmlelement, mode);
78
79        // put your code in here:
80        // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport
81        // make sure that the set- and get-functions exist.
82        // variables can be added by the following command
83        // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
84 
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.