Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/Drone.cc @ 12398

Last change on this file since 12398 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 6.4 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 "core/CoreIncludes.h"
33#include "BulletDynamics/Dynamics/btRigidBody.h"
34
35namespace orxonox
36{
37    RegisterClass(Drone);
38    /**
39    @brief
40        Constructor. Registers the object and initializes some default values.
41    */
42    Drone::Drone(Context* context) : Pawn(context)
43    {
44        RegisterObject(Drone);
45
46        this->myController_ = nullptr;
47
48        this->localLinearAcceleration_.setValue(0, 0, 0);
49        this->localAngularAcceleration_.setValue(0, 0, 0);
50        this->setRadarVisibility(false);
51        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
52
53        myController_ = new DroneController(this->getContext()); //!< Creates a new controller and passes our this pointer to it as creator.
54        myController_->setDrone(this);
55
56        this->setController(myController_);
57    }
58
59    /**
60    @brief
61        Destructor. Destroys controller, if present.
62    */
63    Drone::~Drone()
64    {
65        if( this->isInitialized() && this->myController_ )
66            this->myController_->destroy();
67    }
68
69    /**
70    @brief
71        Method for creating a Drone through XML.
72    */
73    void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
74    {
75        SUPER(Drone, XMLPort, xmlelement, mode);
76
77        XMLPortParam(Drone, "primaryThrust_", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
78        XMLPortParam(Drone, "auxilaryThrust_", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode);
79        XMLPortParam(Drone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode);
80        XMLPortParam(Drone, "maxDistanceToOwner_", setMaxDistanceToOwner, getMaxDistanceToOwner, xmlelement, mode);
81        XMLPortParam(Drone, "minDistanceToOwner_", setMinDistanceToOwner, getMinDistanceToOwner, xmlelement, mode);
82        XMLPortParam(Drone, "maxShootingRange_", setMaxShootingRange, getMaxShootingRange, xmlelement, mode);
83    }
84
85
86    /**
87    @brief
88        Defines which actions the Drone has to take in each tick.
89    @param dt
90        The length of the tick.
91    */
92    void Drone::tick(float dt)
93    {
94        SUPER(Drone, tick, dt);
95
96        //if (this->hasLocalController())
97        //{
98            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
99            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
100            if (this->localLinearAcceleration_.z() > 0)
101              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
102            else
103              this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
104            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
105            this->localLinearAcceleration_.setValue(0, 0, 0);
106
107            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
108            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
109            this->localAngularAcceleration_.setValue(0, 0, 0);
110        //}
111    }
112
113    /**
114    @brief
115        Moves the Drone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
116    @param value
117        The vector determining the amount of the movement.
118    */
119    void Drone::moveFrontBack(const Vector2& value)
120    {
121        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
122    }
123
124    /**
125    @brief
126        Moves the Drone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
127    @param value
128        The vector determining the amount of the movement.
129    */
130    void Drone::moveRightLeft(const Vector2& value)
131    {
132        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
133    }
134
135    /**
136    @brief
137        Moves the Drone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
138    @param value
139        The vector determining the amount of the movement.
140    */
141    void Drone::moveUpDown(const Vector2& value)
142    {
143        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
144    }
145
146    /**
147    @brief
148        Rotates the Drone around the y-axis by the amount specified by the first component of the input 2-dim vector.
149    @param value
150        The vector determining the amount of the angular movement.
151    */
152    void Drone::rotateYaw(const Vector2& value)
153    {
154        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
155    }
156
157    /**
158    @brief
159        Rotates the Drone around the x-axis by the amount specified by the first component of the input 2-dim vector.
160    @param value
161        The vector determining the amount of the angular movement.
162    */
163    void Drone::rotatePitch(const Vector2& value)
164    {
165        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
166    }
167
168    /**
169    @brief
170        Rotates the Drone around the z-axis by the amount specified by the first component of the input 2-dim vector.
171    @param value
172        The vector determining the amount of the angular movement.
173    */
174    void Drone::rotateRoll(const Vector2& value)
175    {
176        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
177    }
178
179}
Note: See TracBrowser for help on using the repository browser.