Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc @ 2459

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

Merged physics_merge back to presentation branch.

  • Property svn:eol-style set to native
File size: 5.4 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 "OrxonoxStableHeaders.h"
30#include "SpaceShip.h"
31
[2459]32#include "BulletDynamics/Dynamics/btRigidBody.h"
33
34#include "util/Math.h"
35#include "util/Exception.h"
[2072]36#include "core/CoreIncludes.h"
37#include "core/ConfigValueIncludes.h"
38#include "core/XMLPort.h"
39
40namespace orxonox
41{
[2459]42    const float orientationGain = 100;
[2072]43    CreateFactory(SpaceShip);
44
45    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
46    {
47        RegisterObject(SpaceShip);
48
[2459]49        this->primaryThrust_  = 100;
50        this->auxilaryThrust_ =  30;
51        this->rotationThrust_ =  10;
[2072]52
[2459]53        this->localLinearAcceleration_.setValue(0, 0, 0);
54        this->localAngularAcceleration_.setValue(0, 0, 0);
[2072]55
56        this->bInvertYAxis_ = false;
57
58        this->setDestroyWhenPlayerLeft(true);
59
[2459]60        // SpaceShip is always a physical object per default
61        // Be aware of this call: The collision type legality check will not reach derived classes!
62        this->setCollisionType(WorldEntity::Dynamic);
63
[2072]64        this->setConfigValues();
65        this->registerVariables();
66    }
67
68    SpaceShip::~SpaceShip()
69    {
70    }
71
72    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
73    {
74        SUPER(SpaceShip, XMLPort, xmlelement, mode);
75
[2459]76        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
77        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
78        XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
[2072]79    }
80
81    void SpaceShip::registerVariables()
82    {
[2459]83        registerVariable(this->primaryThrust_,  variableDirection::toclient);
84        registerVariable(this->auxilaryThrust_, variableDirection::toclient);
85        registerVariable(this->rotationThrust_, variableDirection::toclient);
[2072]86    }
87
88    void SpaceShip::setConfigValues()
89    {
90        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
91    }
92
[2459]93    bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const
[2072]94    {
[2459]95        if (type != WorldEntity::Dynamic)
[2072]96        {
[2459]97            CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl;
98            assert(false); // Only in debug mode
99            return false;
[2072]100        }
[2459]101        else
102            return true;
103    }
[2072]104
[2459]105    void SpaceShip::tick(float dt)
106    {
[2072]107        SUPER(SpaceShip, tick, dt);
108
109        if (this->isLocallyControlled())
110        {
[2459]111            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
112            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
113            if (this->localLinearAcceleration_.z() > 0)
114                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
[2072]115            else
[2459]116                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
117            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
118            this->localLinearAcceleration_.setValue(0, 0, 0);
[2072]119
[2459]120            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
121            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
122            this->localAngularAcceleration_.setValue(0, 0, 0);
[2072]123        }
124    }
125
126    void SpaceShip::moveFrontBack(const Vector2& value)
127    {
[2459]128        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
[2072]129    }
130
131    void SpaceShip::moveRightLeft(const Vector2& value)
132    {
[2459]133        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
[2072]134    }
135
136    void SpaceShip::moveUpDown(const Vector2& value)
137    {
[2459]138        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
[2072]139    }
140
141    void SpaceShip::rotateYaw(const Vector2& value)
142    {
[2459]143        this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
[2072]144    }
145
146    void SpaceShip::rotatePitch(const Vector2& value)
147    {
[2459]148        this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
[2072]149    }
150
151    void SpaceShip::rotateRoll(const Vector2& value)
152    {
[2459]153        this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
[2072]154    }
155
156    void SpaceShip::fire()
157    {
158    }
159}
Note: See TracBrowser for help on using the repository browser.