Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed lines students will have to reinsert again

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