Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/objects/worldentities/pawns/SpaceShip.cc @ 2433

Last change on this file since 2433 was 2374, checked in by rgrieder, 16 years ago

Trying to synchronise phyiscs over the network.

  • Removed derivation of CollisionShape from WorldEntity (BaseObject instead).
  • Property svn:eol-style set to native
File size: 5.1 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 "BulletDynamics/Dynamics/btRigidBody.h"
33
34#include "util/Math.h"
35#include "util/Exception.h"
36#include "core/CoreIncludes.h"
37#include "core/ConfigValueIncludes.h"
38#include "core/XMLPort.h"
39
40namespace orxonox
41{
42    const float orientationGain = 100;
43    CreateFactory(SpaceShip);
44
45    SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator)
46    {
47        RegisterObject(SpaceShip);
48
49        this->zeroDegree_ = 0;
50
51        this->maxSpeed_ = 0;
52        this->maxSecondarySpeed_ = 0;
53        this->maxRotation_ = 0;
54        this->translationAcceleration_ = 0;
55        this->rotationAcceleration_ = 0;
56        this->translationDamping_ = 0;
57
58        this->yawRotation_ = 0;
59        this->pitchRotation_ = 0;
60        this->rollRotation_ = 0;
61
62        this->bInvertYAxis_ = false;
63
64        this->setDestroyWhenPlayerLeft(true);
65
66        this->setConfigValues();
67        this->registerVariables();
68    }
69
70    SpaceShip::~SpaceShip()
71    {
72    }
73
74    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        SUPER(SpaceShip, XMLPort, xmlelement, mode);
77
78        XMLPortParam(SpaceShip, "maxspeed",          setMaxSpeed,          getMaxSpeed,          xmlelement, mode);
79        XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode);
80        XMLPortParam(SpaceShip, "maxrotation",       setMaxRotation,       getMaxRotation,       xmlelement, mode);
81        XMLPortParam(SpaceShip, "transacc",          setTransAcc,          getTransAcc,          xmlelement, mode);
82        XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
83        XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
84
85        if (this->physicalBody_)
86        {
87            this->physicalBody_->setDamping(0.7, 0.3);
88        }
89    }
90
91    void SpaceShip::registerVariables()
92    {
93        REGISTERDATA(this->maxSpeed_,                network::direction::toclient);
94        REGISTERDATA(this->maxSecondarySpeed_,       network::direction::toclient);
95        REGISTERDATA(this->maxRotation_,             network::direction::toclient);
96        REGISTERDATA(this->translationAcceleration_, network::direction::toclient);
97        REGISTERDATA(this->rotationAcceleration_,    network::direction::toclient);
98        REGISTERDATA(this->translationDamping_,      network::direction::toclient);
99    }
100
101    void SpaceShip::setConfigValues()
102    {
103        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
104    }
105
106    void SpaceShip::tick(float dt)
107    {
108        SUPER(SpaceShip, tick, dt);
109    }
110
111    void SpaceShip::moveFrontBack(const Vector2& value)
112    {
113        assert(this->physicalBody_);
114        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100));
115    }
116
117    void SpaceShip::moveRightLeft(const Vector2& value)
118    {
119        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f));
120    }
121
122    void SpaceShip::moveUpDown(const Vector2& value)
123    {
124        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f));
125    }
126
127    void SpaceShip::rotateYaw(const Vector2& value)
128    {
129        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f));
130    }
131
132    void SpaceShip::rotatePitch(const Vector2& value)
133    {
134        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f));
135    }
136
137    void SpaceShip::rotateRoll(const Vector2& value)
138    {
139        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain));
140    }
141
142    void SpaceShip::fire()
143    {
144    }
145}
Note: See TracBrowser for help on using the repository browser.