[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 | |
---|
[2442] | 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 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[2442] | 42 | const float orientationGain = 100; |
---|
[2072] | 43 | CreateFactory(SpaceShip); |
---|
| 44 | |
---|
| 45 | SpaceShip::SpaceShip(BaseObject* creator) : Pawn(creator) |
---|
| 46 | { |
---|
| 47 | RegisterObject(SpaceShip); |
---|
| 48 | |
---|
[2453] | 49 | this->primaryThrust_ = 100; |
---|
| 50 | this->auxilaryThrust_ = 30; |
---|
| 51 | this->rotationThrust_ = 10; |
---|
[2072] | 52 | |
---|
[2453] | 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 | |
---|
[2453] | 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 | |
---|
[2453] | 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 | { |
---|
[2453] | 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 | |
---|
[2453] | 93 | bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const |
---|
| 94 | { |
---|
| 95 | if (type != WorldEntity::Dynamic) |
---|
| 96 | { |
---|
| 97 | ThrowException(PhysicsViolation, "Cannot tell a SpaceShip not to be dynamic!"); |
---|
| 98 | return false; |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | return true; |
---|
| 102 | } |
---|
| 103 | |
---|
[2072] | 104 | void SpaceShip::tick(float dt) |
---|
| 105 | { |
---|
| 106 | SUPER(SpaceShip, tick, dt); |
---|
[2453] | 107 | |
---|
| 108 | if (this->isLocallyControlled()) |
---|
| 109 | { |
---|
| 110 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); |
---|
| 111 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); |
---|
| 112 | if (this->localLinearAcceleration_.z() > 0) |
---|
| 113 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); |
---|
| 114 | else |
---|
| 115 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); |
---|
| 116 | this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); |
---|
| 117 | this->localLinearAcceleration_.setValue(0, 0, 0); |
---|
| 118 | |
---|
| 119 | this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; |
---|
| 120 | this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); |
---|
| 121 | this->localAngularAcceleration_.setValue(0, 0, 0); |
---|
| 122 | } |
---|
[2072] | 123 | } |
---|
| 124 | |
---|
| 125 | void SpaceShip::moveFrontBack(const Vector2& value) |
---|
| 126 | { |
---|
[2453] | 127 | this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); |
---|
[2072] | 128 | } |
---|
| 129 | |
---|
| 130 | void SpaceShip::moveRightLeft(const Vector2& value) |
---|
| 131 | { |
---|
[2453] | 132 | this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); |
---|
[2072] | 133 | } |
---|
| 134 | |
---|
| 135 | void SpaceShip::moveUpDown(const Vector2& value) |
---|
| 136 | { |
---|
[2453] | 137 | this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); |
---|
[2072] | 138 | } |
---|
| 139 | |
---|
| 140 | void SpaceShip::rotateYaw(const Vector2& value) |
---|
| 141 | { |
---|
[2453] | 142 | this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); |
---|
[2072] | 143 | } |
---|
| 144 | |
---|
| 145 | void SpaceShip::rotatePitch(const Vector2& value) |
---|
| 146 | { |
---|
[2453] | 147 | this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); |
---|
[2072] | 148 | } |
---|
| 149 | |
---|
| 150 | void SpaceShip::rotateRoll(const Vector2& value) |
---|
| 151 | { |
---|
[2453] | 152 | this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); |
---|
[2072] | 153 | } |
---|
| 154 | |
---|
| 155 | void SpaceShip::fire() |
---|
| 156 | { |
---|
| 157 | } |
---|
| 158 | } |
---|