Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai/src/orxonox/worldentities/Drone.cc @ 6832

Last change on this file since 6832 was 6832, checked in by gasserlu, 14 years ago

dronecontroller upload

File size: 6.6 KB
Line 
1
2
3
4
5
6
7/*
8 *   ORXONOX - the hottest 3D action shooter ever to exist
9 *                    > www.orxonox.net <
10 *
11 *
12 *   License notice:
13 *
14 *   This program is free software; you can redistribute it and/or
15 *   modify it under the terms of the GNU General Public License
16 *   as published by the Free Software Foundation; either version 2
17 *   of the License, or (at your option) any later version.
18 *
19 *   This program is distributed in the hope that it will be useful,
20 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
21 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 *   GNU General Public License for more details.
23 *
24 *   You should have received a copy of the GNU General Public License
25 *   along with this program; if not, write to the Free Software
26 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
27 *
28 *   Author:
29 *      Oli Scheuss
30 *   Co-authors:
31 *      ...
32 */
33
34
35#include "Drone.h"
36
37#include "core/XMLPort.h"
38#include "BulletDynamics/Dynamics/btRigidBody.h"
39
40namespace orxonox
41{
42    // put your code in here:
43    // create the factory for the drone
44    CreateFactory(Drone);
45    /**
46    @brief
47        Constructor. Registers the object and initializes some default values.
48    */
49    Drone::Drone(BaseObject* creator) : Pawn(creator)
50    {
51        // put your code in here:
52        // - register the drone class to the core
53        RegisterObject(Drone);
54
55        this->myController_ = 0;
56       
57        this->localLinearAcceleration_.setValue(0, 0, 0);
58        this->localAngularAcceleration_.setValue(0, 0, 0);
59        this->primaryThrust_  = 100;
60        this->auxilaryThrust_ = 100;
61        this->rotationThrust_ = 10;
62       
63        this->setCollisionType(WorldEntity::Dynamic);
64       
65        myController_ = new DroneController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator.
66        this->setController(myController_);
67    }
68
69    /**
70    @brief
71        Destructor. Destroys controller, if present.
72    */
73    Drone::~Drone()
74    {
75        if( this->isInitialized() && this->myController_ )
76            delete this->myController_;
77    }
78
79    /**
80    @brief
81        Method for creating a Drone through XML.
82    */
83    void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
84    {
85        // this calls the XMLPort function of the parent class
86        SUPER(Drone, XMLPort, xmlelement, mode);
87
88        // put your code in here:
89        // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport
90        // make sure that the set- and get-functions exist.
91        // variables can be added by the following command
92        // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
93        XMLPortParam(Drone, "primaryThrust_", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
94        XMLPortParam(Drone, "auxilaryThrust_", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode);
95        XMLPortParam(Drone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode);
96
97
98    }
99
100
101    /**
102    @brief
103        Defines which actions the Drone has to take in each tick.
104    @param dt
105        The length of the tick.
106    */
107    void Drone::tick(float dt)
108    {
109        SUPER(Drone, tick, dt);
110       
111        //if (this->hasLocalController())
112        //{
113            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
114            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
115            if (this->localLinearAcceleration_.z() > 0)
116              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
117            else
118              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
119            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
120            this->localLinearAcceleration_.setValue(0, 0, 0);
121       
122            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
123            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
124            this->localAngularAcceleration_.setValue(0, 0, 0);
125        //}
126    }
127   
128    /**
129    @brief
130        Moves the Drone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
131    @param value
132        The vector determining the amount of the movement.
133    */
134    void Drone::moveFrontBack(const Vector2& value)
135    {
136        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
137    }
138
139    /**
140    @brief
141        Moves the Drone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
142    @param value
143        The vector determining the amount of the movement.
144    */
145    void Drone::moveRightLeft(const Vector2& value)
146    {
147        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
148    }
149
150    /**
151    @brief
152        Moves the Drone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
153    @param value
154        The vector determining the amount of the movement.
155    */
156    void Drone::moveUpDown(const Vector2& value)
157    {
158        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
159    }
160
161    /**
162    @brief
163        Rotates the Drone around the y-axis by the amount specified by the first component of the input 2-dim vector.
164    @param value
165        The vector determining the amount of the angular movement.
166    */
167    void Drone::rotateYaw(const Vector2& value)
168    {
169        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
170    }
171
172    /**
173    @brief
174        Rotates the Drone around the x-axis by the amount specified by the first component of the input 2-dim vector.
175    @param value
176        The vector determining the amount of the angular movement.
177    */
178    void Drone::rotatePitch(const Vector2& value)
179    {
180        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
181    }
182
183    /**
184    @brief
185        Rotates the Drone around the z-axis by the amount specified by the first component of the input 2-dim vector.
186    @param value
187        The vector determining the amount of the angular movement.
188    */
189    void Drone::rotateRoll(const Vector2& value)
190    {
191        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
192    }
193   
194}
Note: See TracBrowser for help on using the repository browser.