[10657] | 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: |
---|
[10659] | 23 | * Cyrill Burgener |
---|
[10657] | 24 | * |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | /** |
---|
[10659] | 28 | @file HoverShip.cc |
---|
[10929] | 29 | @brief Implementation of the HoverShip control |
---|
[10657] | 30 | */ |
---|
| 31 | |
---|
[10659] | 32 | #include "HoverShip.h" |
---|
[10657] | 33 | #include "core/CoreIncludes.h" |
---|
[11041] | 34 | #include "core/XMLPort.h" |
---|
[12290] | 35 | #include "graphics/Camera.h" |
---|
[10657] | 36 | |
---|
[11041] | 37 | #include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> |
---|
| 38 | |
---|
[10657] | 39 | namespace orxonox |
---|
| 40 | { |
---|
[10659] | 41 | RegisterClass(HoverShip); |
---|
[10657] | 42 | |
---|
[10659] | 43 | HoverShip::HoverShip(Context* context) : SpaceShip(context) |
---|
[10657] | 44 | { |
---|
[10659] | 45 | RegisterObject(HoverShip); |
---|
[10784] | 46 | enableCollisionCallback(); |
---|
| 47 | isFloor_ = false; |
---|
[12290] | 48 | jumpBoost_ = 0; |
---|
[10657] | 49 | } |
---|
| 50 | |
---|
[10784] | 51 | void HoverShip::moveFrontBack(const Vector2& value) |
---|
[12290] | 52 | { this->steering_.z -= value.x; |
---|
| 53 | Vector3 currentPosition = this->getPosition(); |
---|
| 54 | currentPosition.y -= 2*value.y; |
---|
| 55 | this->setPosition(currentPosition); |
---|
| 56 | } |
---|
[10694] | 57 | |
---|
| 58 | void HoverShip::moveRightLeft(const Vector2& value) |
---|
[12290] | 59 | { |
---|
| 60 | this->steering_.x += value.x; |
---|
| 61 | Vector3 currentPosition = this->getPosition(); |
---|
| 62 | currentPosition.x -= 2*value.x; |
---|
| 63 | this->setPosition(currentPosition); |
---|
| 64 | } |
---|
[10694] | 65 | |
---|
| 66 | void HoverShip::moveUpDown(const Vector2& value) |
---|
[12290] | 67 | { |
---|
| 68 | this->steering_.y += value.x; |
---|
| 69 | this->setPosition(Vector3(0, 0, 0)); |
---|
| 70 | } |
---|
[10694] | 71 | |
---|
[10784] | 72 | void HoverShip::rotateYaw(const Vector2& value) |
---|
| 73 | { |
---|
| 74 | this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); |
---|
[10694] | 75 | |
---|
[10784] | 76 | Pawn::rotateYaw(value); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | void HoverShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 80 | { |
---|
| 81 | SUPER(HoverShip, XMLPort, xmlelement, mode); |
---|
| 82 | |
---|
| 83 | XMLPortParam(HoverShip, "jumpBoost", setJumpBoost, getJumpBoost, xmlelement, mode); |
---|
| 84 | } |
---|
| 85 | |
---|
[12290] | 86 | void HoverShip::tick(float dt) |
---|
| 87 | { |
---|
| 88 | SUPER(HoverShip, tick, dt); |
---|
| 89 | //Execute movement |
---|
| 90 | if (this->hasLocalController()) |
---|
| 91 | { |
---|
| 92 | // Camera |
---|
| 93 | Camera* camera = this->getCamera(); |
---|
| 94 | if (camera != nullptr) |
---|
| 95 | { |
---|
| 96 | camera->setPosition(0,1000,0); |
---|
| 97 | camera->setOrientation(Vector3::UNIT_X, Degree(-90)); |
---|
| 98 | |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[10929] | 103 | /** |
---|
| 104 | @brief |
---|
| 105 | Removed, does nothing. |
---|
[10784] | 106 | @param value |
---|
| 107 | */ |
---|
| 108 | void HoverShip::rotatePitch(const Vector2& value) { } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | @brief |
---|
[10929] | 112 | Removed, does nothing. |
---|
[10784] | 113 | @param value |
---|
| 114 | */ |
---|
| 115 | void HoverShip::rotateRoll(const Vector2& value) { } |
---|
| 116 | |
---|
[10929] | 117 | /** |
---|
| 118 | @brief |
---|
| 119 | Checks if the ship is touching the floor. The ship can only jump if there is contact with someting beneath it. |
---|
| 120 | */ |
---|
[10760] | 121 | bool HoverShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
[10694] | 122 | { |
---|
[10784] | 123 | SpaceShip::collidesAgainst(otherObject, cs, contactPoint); |
---|
| 124 | //SUPER(HoverShip, collidesAgainst, otherObject, cs, contactPoint); |
---|
[10760] | 125 | |
---|
[10784] | 126 | if (contactPoint.m_normalWorldOnB.y() > 0.6 |
---|
| 127 | && this->getVelocity().y < 1) { |
---|
[10694] | 128 | this->isFloor_ = true; |
---|
[10784] | 129 | } else { |
---|
[10694] | 130 | this->isFloor_ = false; |
---|
[10784] | 131 | } |
---|
[10694] | 132 | |
---|
| 133 | return false; |
---|
| 134 | } |
---|
| 135 | |
---|
[10929] | 136 | /** |
---|
| 137 | @brief |
---|
| 138 | Makes the ship jump |
---|
| 139 | @param bBoost |
---|
| 140 | */ |
---|
[10694] | 141 | void HoverShip::boost(bool bBoost) { |
---|
[10784] | 142 | if (bBoost && this->isFloor_) |
---|
[10694] | 143 | { |
---|
[10784] | 144 | this->setVelocity( |
---|
| 145 | this->getVelocity().x, |
---|
| 146 | jumpBoost_, |
---|
| 147 | this->getVelocity().z |
---|
| 148 | ); |
---|
[10694] | 149 | this->isFloor_ = false; |
---|
[10784] | 150 | } |
---|
[10694] | 151 | } |
---|
[10657] | 152 | } |
---|