Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc @ 6554

Last change on this file since 6554 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 7.1 KB
RevLine 
[2072]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 "SpaceShip.h"
30
[3196]31#include <BulletDynamics/Dynamics/btRigidBody.h>
[2662]32
[2072]33#include "core/CoreIncludes.h"
34#include "core/ConfigValueIncludes.h"
[2662]35#include "core/Template.h"
[2072]36#include "core/XMLPort.h"
[5735]37#include "items/Engine.h"
[2072]38
39namespace orxonox
40{
[2662]41    const float orientationGain = 100;
[2072]42    CreateFactory(SpaceShip);
43
44    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
45    {
46        RegisterObject(SpaceShip);
47
[2662]48        this->primaryThrust_  = 100;
49        this->auxilaryThrust_ =  30;
50        this->rotationThrust_ =  10;
[2072]51
[2662]52        this->localLinearAcceleration_.setValue(0, 0, 0);
53        this->localAngularAcceleration_.setValue(0, 0, 0);
54        this->bBoost_ = false;
55        this->bPermanentBoost_ = false;
56        this->steering_ = Vector3::ZERO;
57        this->engine_ = 0;
[2072]58
59
60        this->bInvertYAxis_ = false;
61
62        this->setDestroyWhenPlayerLeft(true);
63
[2662]64        // SpaceShip is always a physical object per default
65        // Be aware of this call: The collision type legality check will not reach derived classes!
66        this->setCollisionType(WorldEntity::Dynamic);
67        // Get notification about collisions
68        this->enableCollisionCallback();
69
[2072]70        this->setConfigValues();
71        this->registerVariables();
72    }
73
74    SpaceShip::~SpaceShip()
75    {
[2662]76        if (this->isInitialized() && this->engine_)
[5929]77            this->engine_->destroy();
[2072]78    }
79
80    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
81    {
82        SUPER(SpaceShip, XMLPort, xmlelement, mode);
83
[2662]84        XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
85        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
86        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
87        XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
[2072]88    }
89
90    void SpaceShip::registerVariables()
91    {
[3280]92        registerVariable(this->primaryThrust_,  VariableDirection::ToClient);
93        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
94        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
[2072]95    }
96
97    void SpaceShip::setConfigValues()
98    {
99        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
100    }
101
[2662]102    bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const
[2072]103    {
[2662]104        if (type != WorldEntity::Dynamic)
[2072]105        {
[2662]106            CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl;
107            assert(false); // Only in debug mode
108            return false;
[2072]109        }
[2662]110        else
111            return true;
112    }
[2072]113
[2662]114    void SpaceShip::tick(float dt)
115    {
[2809]116        SUPER(SpaceShip, tick, dt);
[2072]117
[2662]118        if (this->hasLocalController())
[2072]119        {
[2662]120/*
121            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
122            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
123            if (this->localLinearAcceleration_.z() > 0)
124                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
[2072]125            else
[2662]126                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
127            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
128            this->localLinearAcceleration_.setValue(0, 0, 0);
129*/
130            if (!this->isInMouseLook())
131            {
132                this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
133                this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
134                this->localAngularAcceleration_.setValue(0, 0, 0);
135            }
[2072]136        }
137    }
138
139    void SpaceShip::moveFrontBack(const Vector2& value)
140    {
[2662]141        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
142        this->steering_.z = -value.x;
[2072]143    }
144
145    void SpaceShip::moveRightLeft(const Vector2& value)
146    {
[2662]147        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
148        this->steering_.x = value.x;
[2072]149    }
150
151    void SpaceShip::moveUpDown(const Vector2& value)
152    {
[2662]153        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
154        this->steering_.y = value.x;
[2072]155    }
156
157    void SpaceShip::rotateYaw(const Vector2& value)
158    {
[3039]159        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
[2662]160
161        Pawn::rotateYaw(value);
[2072]162    }
163
164    void SpaceShip::rotatePitch(const Vector2& value)
165    {
[2662]166        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
167
168        Pawn::rotatePitch(value);
[2072]169    }
170
171    void SpaceShip::rotateRoll(const Vector2& value)
172    {
[2662]173        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
174
175        Pawn::rotateRoll(value);
[2072]176    }
177
178    void SpaceShip::fire()
179    {
180    }
[2662]181
182    void SpaceShip::boost()
183    {
184        this->bBoost_ = true;
185    }
186
187    void SpaceShip::loadEngineTemplate()
188    {
[6417]189        if (!this->enginetemplate_.empty())
[2662]190        {
191            Template* temp = Template::getTemplate(this->enginetemplate_);
192
193            if (temp)
194            {
195                Identifier* identifier = temp->getBaseclassIdentifier();
196
197                if (identifier)
198                {
199                    BaseObject* object = identifier->fabricate(this);
[3325]200                    this->engine_ = orxonox_cast<Engine*>(object);
[2662]201
202                    if (this->engine_)
203                    {
204                        this->engine_->addTemplate(temp);
205                        this->engine_->addToSpaceShip(this);
206                    }
207                    else
208                    {
[5929]209                        object->destroy();
[2662]210                    }
211                }
212            }
213        }
214    }
215
216    void SpaceShip::setEngine(Engine* engine)
217    {
218        this->engine_ = engine;
219        if (engine && engine->getShip() != this)
220            engine->addToSpaceShip(this);
221    }
[2072]222}
Note: See TracBrowser for help on using the repository browser.