Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2766 was 2766, checked in by scheusso, 15 years ago

removed the lines that the student have to find out themselves

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