Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2764 was 2764, checked in by rgrieder, 15 years ago

segfault

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