Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

first efforts for a tutorial

File size: 3.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 *      Fabian 'x3n' Landau
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    // put your code in here:
38    // create the factory for the drone
39    CreateFactory(Drone);
40
41    Drone::Drone(BaseObject* creator) : ControllableEntity(creator)
42    {
43        //put your code in here:
44        // - register the drone class to the core
45        // - create a new controller and pass our this pointer to it as creator
46        RegisterObject(Drone);
47       
48        this->localLinearAcceleration_.setValue(0, 0, 0);
49        this->localAngularAcceleration_.setValue(0, 0, 0);this->rotationThrust_ = 0;
50        this->steering_ = Vector3::ZERO;
51       
52        this->setCollisionType(WorldEntity::Dynamic);
53       
54        myController = new DroneController(static_cast<BaseObject*>(this));
55    }
56
57    Drone::~Drone()
58    {
59        if( this->myController )
60            delete this->myController;
61    }
62
63    void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
64    {
65        // this calls the XMLPort function of the parent class
66        SUPER(Drone, XMLPort, xmlelement, mode);
67
68        XMLPortParamVariable(Drone, "rotationThrust", rotationThrust_, xmlelement, mode);
69    }
70
71    void Drone::tick(float dt)
72    {
73        SUPER(Drone, tick, dt);
74       
75        //if (this->hasLocalController())
76        //{
77            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
78            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
79            this->localAngularAcceleration_.setValue(0, 0, 0);
80        //}
81    }
82   
83   
84    void Drone::moveFrontBack(const Vector2& value)
85    {
86        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
87        this->steering_.z = -value.x;
88    }
89
90    void Drone::moveRightLeft(const Vector2& value)
91    {
92        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
93        this->steering_.x = value.x;
94    }
95
96    void Drone::moveUpDown(const Vector2& value)
97    {
98        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
99        this->steering_.y = value.x;
100    }
101
102    void Drone::rotateYaw(const Vector2& value)
103    {
104        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
105    }
106
107    void Drone::rotatePitch(const Vector2& value)
108    {
109        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
110    }
111
112    void Drone::rotateRoll(const Vector2& value)
113    {
114        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
115    }
116   
117}
Note: See TracBrowser for help on using the repository browser.