Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ScriptableController_FS18/src/orxonox/worldentities/pawns/AAAAutonomousDrone.cc @ 11928

Last change on this file since 11928 was 11928, checked in by adamc, 6 years ago

Level & Script backup

File size: 7.7 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 *      Damian 'Mozork' Frick
26 *
27 */
28
29#include "AAAAutonomousDrone.h"
30
31#include "core/CoreIncludes.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33
34namespace orxonox
35{
36    //TODO: 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    @param creator
43        The creator of this object.
44    */
45
46    RegisterClass(AAAAutonomousDrone);
47   
48    AAAAutonomousDrone::AAAAutonomousDrone(Context* context) : Pawn(context)
49    {
50        //TODO: Put your code in here:
51        // Register the drone class to the core.
52
53        RegisterObject(AAAAutonomousDrone);
54     
55        //this->myController_ = NULL;
56
57        this->localLinearAcceleration_.setValue(0, 0, 0);
58        this->localAngularAcceleration_.setValue(0, 0, 0);
59        this->primaryThrust_  = 100;
60        this->auxiliaryThrust_ = 100;
61        this->rotationThrust_ = 10;
62            this->mass_ = 100;
63            this->linearDamping_ = 0.5;
64            this->angularDamping_ = 0.3;
65
66        this->setRadarVisibility(false);
67       
68        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
69
70        //this->setCollisionType(CollisionType::Dynamic);
71
72        //this->myController_ = new AAAAutonomousDroneController(this); // Creates a new controller and passes our this pointer to it as creator.
73    }
74
75    /**
76    @brief
77        Destructor. Destroys controller, if present.
78    */
79    AAAAutonomousDrone::~AAAAutonomousDrone()
80    {
81        // Deletes the controller if the object was initialized and the pointer to the controller is not NULL.
82        if( this->isInitialized()); //)&& this->myController_ != NULL )
83            //delete this->myController_;
84    }
85
86    /**
87    @brief
88        Method for creating a AAAAutonomousDrone through XML.
89    */
90    void AAAAutonomousDrone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
91    {
92        // This calls the XMLPort function of the parent class
93        SUPER(AAAAutonomousDrone, XMLPort, xmlelement, mode);
94
95        XMLPortParam(AAAAutonomousDrone, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
96        //TODO: Put your code in here:
97        // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort.
98        // Variables can be added by the following command
99        // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode);
100        // Also make sure that you also create the get- and set-functions in AAAAutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there.
101        XMLPortParam(AAAAutonomousDrone, "auxiliaryThrust", setAuxiliaryThrust, getAuxiliaryThrust, xmlelement, mode);
102    XMLPortParam(AAAAutonomousDrone, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
103        XMLPortParam(AAAAutonomousDrone, "mass", setMass, getMass, xmlelement, mode);
104        XMLPortParam(AAAAutonomousDrone, "linearDamping", setLinearDamping, getLinearDamping, xmlelement, mode);
105        XMLPortParam(AAAAutonomousDrone, "angularDamping", setAngularDamping, getAngularDamping, xmlelement, mode);
106
107   
108       
109       
110
111    }
112
113    /**
114    @brief
115        Defines which actions the AAAAutonomousDrone has to take in each tick.
116    @param dt
117        The length of the tick.
118    */
119    void AAAAutonomousDrone::tick(float dt)
120    {
121        SUPER(AAAAutonomousDrone, tick, dt);
122
123        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);
124        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);
125        if (this->localLinearAcceleration_.z() > 0)
126            this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);
127        else
128            this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
129        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
130        this->localLinearAcceleration_.setValue(0, 0, 0);
131
132        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
133        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
134        this->localAngularAcceleration_.setValue(0, 0, 0);
135    }
136
137    /**
138    @brief
139        Moves the AAAAutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
140    @param value
141        The vector determining the amount of the movement.
142    */
143    void AAAAutonomousDrone::moveFrontBack(const Vector2& value)
144    {
145        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
146    }
147
148    /**
149    @brief
150        Moves the AAAAutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
151    @param value
152        The vector determining the amount of the movement.
153    */
154    void AAAAutonomousDrone::moveRightLeft(const Vector2& value)
155    {
156        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
157    }
158
159    /**
160    @brief
161        Moves the AAAAutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
162    @param value
163        The vector determining the amount of the movement.
164    */
165    void AAAAutonomousDrone::moveUpDown(const Vector2& value)
166    {
167        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
168    }
169
170    /**
171    @brief
172        Rotates the AAAAutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.
173    @param value
174        The vector determining the amount of the angular movement.
175    */
176    void AAAAutonomousDrone::rotateYaw(const Vector2& value)
177    {
178        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
179    }
180
181    /**
182    @brief
183        Rotates the AAAAutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.
184    @param value
185        The vector determining the amount of the angular movement.
186    */
187    void AAAAutonomousDrone::rotatePitch(const Vector2& value)
188    {
189        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
190    }
191
192    /**
193    @brief
194        Rotates the AAAAutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.
195    @param value
196        The vector determining the amount of the angular movement.
197    */
198    void AAAAutonomousDrone::rotateRoll(const Vector2& value)
199    {
200        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
201    }
202
203
204}
Note: See TracBrowser for help on using the repository browser.