Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/SpaceShip.cc @ 2034

Last change on this file since 2034 was 2025, checked in by rgrieder, 16 years ago

Removed something we better never mention again… ;)

File size: 6.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 "SpaceShip.h"
31
32#include "core/CoreIncludes.h"
33#include "core/ConfigValueIncludes.h"
34#include "core/XMLPort.h"
35#include "util/Math.h"
36
37namespace orxonox
38{
39    CreateFactory(SpaceShip);
40
41    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
42    {
43        RegisterObject(SpaceShip);
44
45        this->zeroDegree_ = 0;
46
47        this->maxSpeed_ = 0;
48        this->maxSecondarySpeed_ = 0;
49        this->maxRotation_ = 0;
50        this->translationAcceleration_ = 0;
51        this->rotationAcceleration_ = 0;
52        this->translationDamping_ = 0;
53
54        this->yawRotation_ = 0;
55        this->pitchRotation_ = 0;
56        this->rollRotation_ = 0;
57
58        this->bInvertYAxis_ = false;
59
60        this->setConfigValues();
61        this->registerVariables();
62    }
63
64    SpaceShip::~SpaceShip()
65    {
66    }
67
68    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
69    {
70        SUPER(SpaceShip, XMLPort, xmlelement, mode);
71
72        XMLPortParam(SpaceShip, "maxspeed",          setMaxSpeed,          getMaxSpeed,          xmlelement, mode);
73        XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode);
74        XMLPortParam(SpaceShip, "maxrotation",       setMaxRotation,       getMaxRotation,       xmlelement, mode);
75        XMLPortParam(SpaceShip, "transacc",          setTransAcc,          getTransAcc,          xmlelement, mode);
76        XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
77        XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
78    }
79
80    void SpaceShip::registerVariables()
81    {
82    }
83
84    void SpaceShip::setConfigValues()
85    {
86        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
87    }
88
89    void SpaceShip::tick(float dt)
90    {
91        // #####################################
92        // ############# STEERING ##############
93        // #####################################
94
95        Vector3 velocity = this->getVelocity();
96        if (velocity.x > this->maxSecondarySpeed_)
97            velocity.x = this->maxSecondarySpeed_;
98        if (velocity.x < -this->maxSecondarySpeed_)
99            velocity.x = -this->maxSecondarySpeed_;
100        if (velocity.y > this->maxSecondarySpeed_)
101            velocity.y = this->maxSecondarySpeed_;
102        if (velocity.y < -this->maxSecondarySpeed_)
103            velocity.y = -this->maxSecondarySpeed_;
104        if (velocity.z > this->maxSecondarySpeed_)
105            velocity.z = this->maxSecondarySpeed_;
106        if (velocity.z < -this->maxSpeed_)
107            velocity.z = -this->maxSpeed_;
108
109        // normalize velocity and acceleration
110        for (size_t dimension = 0; dimension < 3; ++dimension)
111        {
112            if (this->acceleration_[dimension] == 0)
113            {
114                if (velocity[dimension] > 0)
115                {
116                    velocity[dimension] -= (this->translationDamping_ * dt);
117                    if (velocity[dimension] < 0)
118                        velocity[dimension] = 0;
119                }
120                else if (velocity[dimension] < 0)
121                {
122                    velocity[dimension] += (this->translationDamping_ * dt);
123                    if (velocity[dimension] > 0)
124                        velocity[dimension] = 0;
125                }
126            }
127        }
128
129        this->setVelocity(velocity);
130
131
132        SUPER(SpaceShip, tick, dt);
133
134
135        this->yaw(this->yawRotation_ * dt);
136        if (this->bInvertYAxis_)
137            this->pitch(Degree(-this->pitchRotation_ * dt));
138        else
139            this->pitch(Degree( this->pitchRotation_ * dt));
140        this->roll(this->rollRotation_ * dt);
141
142        this->acceleration_.x = 0;
143        this->acceleration_.y = 0;
144        this->acceleration_.z = 0;
145
146        this->yawRotation_   = this->zeroDegree_;
147        this->pitchRotation_ = this->zeroDegree_;
148        this->rollRotation_  = this->zeroDegree_;
149    }
150
151    void SpaceShip::moveFrontBack(const Vector2& value)
152    {
153        this->acceleration_.z = -this->translationAcceleration_ * value.x;
154    }
155
156    void SpaceShip::moveRightLeft(const Vector2& value)
157    {
158        this->acceleration_.x = this->translationAcceleration_ * value.x;
159    }
160
161    void SpaceShip::moveUpDown(const Vector2& value)
162    {
163        this->acceleration_.y = this->translationAcceleration_ * value.x;
164    }
165
166    void SpaceShip::rotateYaw(const Vector2& value)
167    {
168        Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
169        if (temp > this->maxRotation_)
170            temp = this->maxRotation_;
171        if (temp < -this->maxRotation_)
172            temp = -this->maxRotation_;
173        this->yawRotation_ = Degree(temp);
174    }
175
176    void SpaceShip::rotatePitch(const Vector2& value)
177    {
178        Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
179        if (temp > this->maxRotation_)
180            temp = this->maxRotation_;
181        if (temp < -this->maxRotation_)
182            temp = -this->maxRotation_;
183        this->pitchRotation_ = Degree(temp);
184    }
185
186    void SpaceShip::rotateRoll(const Vector2& value)
187    {
188        Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
189        if (temp > this->maxRotation_)
190            temp = this->maxRotation_;
191        if (temp < -this->maxRotation_)
192            temp = -this->maxRotation_;
193        this->rollRotation_ = Degree(temp);
194    }
195
196    void SpaceShip::fire()
197    {
198    }
199}
Note: See TracBrowser for help on using the repository browser.