Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

reverted r5766 since we forgot some adjustments to the code (i.e. remove xml hack)

File size: 4.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 *      ...
26 *
27 */
28
29#include "Drone.h"
30
31#include "core/XMLPort.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33
34namespace orxonox
35{
36    // put your code in here:
37    // create the factory for the drone
38    CreateFactory(Drone);
39
40    Drone::Drone(BaseObject* creator) : ControllableEntity(creator)
41    {
42        //put your code in here:
43        // - register the drone class to the core
44        // - create a new controller and pass our this pointer to it as creator
45        this->myController_ = 0;
46        RegisterObject(Drone);
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        std::cout << "sdfasdfasdf====================";
56       
57        this->setCollisionType(WorldEntity::Dynamic);
58       
59        myController_ = new DroneController(static_cast<BaseObject*>(this));
60    }
61
62    Drone::~Drone()
63    {
64        if( this->myController_ )
65            delete this->myController_;
66    }
67
68    void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
69    {
70        // this calls the XMLPort function of the parent class
71        SUPER(Drone, XMLPort, xmlelement, mode);
72
73        XMLPortParamVariable(Drone, "primaryThrust",  primaryThrust_,  xmlelement, mode);
74        XMLPortParamVariable(Drone, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
75        XMLPortParamVariable(Drone, "rotationThrust", rotationThrust_, xmlelement, mode);
76    }
77
78    void Drone::tick(float dt)
79    {
80        SUPER(Drone, tick, dt);
81       
82        //if (this->hasLocalController())
83        //{
84            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
85            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
86            if (this->localLinearAcceleration_.z() > 0)
87              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
88            else
89              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
90            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
91            this->localLinearAcceleration_.setValue(0, 0, 0);
92       
93            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
94            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
95            this->localAngularAcceleration_.setValue(0, 0, 0);
96        //}
97    }
98   
99   
100    void Drone::moveFrontBack(const Vector2& value)
101    {
102        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
103        this->steering_.z = -value.x;
104    }
105
106    void Drone::moveRightLeft(const Vector2& value)
107    {
108        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
109        this->steering_.x = value.x;
110    }
111
112    void Drone::moveUpDown(const Vector2& value)
113    {
114        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
115        this->steering_.y = value.x;
116    }
117
118    void Drone::rotateYaw(const Vector2& value)
119    {
120        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
121    }
122
123    void Drone::rotatePitch(const Vector2& value)
124    {
125        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
126    }
127
128    void Drone::rotateRoll(const Vector2& value)
129    {
130        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
131    }
132   
133}
Note: See TracBrowser for help on using the repository browser.