Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Waypoints_HS17/src/orxonox/worldentities/Arrow.cc @ 11661

Last change on this file since 11661 was 11661, checked in by jostoffe, 6 years ago

Der Pfeil zeigt nun in die richtige Richtung. Es ist jeweils nur derjenige Waypoint sichtbar, welcher als naechstes erreicht werden muss. Sobald alle erreicht wurden, wird der Pfeil unsichtbar. Falls man spaeter neue einfuegen will, kann man einfach einen neuen ArrayController erstellen

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