[146] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software: you can redistribute it and/or modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | * (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | * |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Reto Grieder |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include "orxonox_ship.h" |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode) |
---|
| 32 | : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)), |
---|
| 33 | baseThrust(1000), thrust(0), sideThrust(0), n(0), |
---|
| 34 | bulletSpeed(400) |
---|
| 35 | { |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | OrxonoxShip::~OrxonoxShip() |
---|
| 40 | { |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | bool OrxonoxShip::initialise() |
---|
| 45 | { |
---|
| 46 | // load all the resources needed (no resource groups yet, |
---|
| 47 | // so the allInit is not executed!) |
---|
| 48 | // ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 49 | |
---|
| 50 | // create the "space ship" (currently a fish..) |
---|
| 51 | // TODO: names must be unique! |
---|
| 52 | mShip = mSceneMgr->createEntity("Ship", "fish.mesh"); |
---|
| 53 | SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode"); |
---|
| 54 | fishNode->yaw(Degree(-90)); |
---|
| 55 | fishNode->attachObject(mShip); |
---|
| 56 | fishNode->setScale(Vector3(10, 10, 10)); |
---|
| 57 | |
---|
| 58 | return true; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | void OrxonoxShip::setThrust(const Real value) |
---|
| 63 | { |
---|
| 64 | thrust = value * baseThrust; |
---|
| 65 | } |
---|
| 66 | |
---|
[147] | 67 | |
---|
[146] | 68 | void OrxonoxShip::setSideThrust(const Real value) |
---|
| 69 | { |
---|
| 70 | sideThrust = value * baseThrust; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void OrxonoxShip::setYaw(const Radian value) |
---|
| 74 | { |
---|
| 75 | mRootNode->yaw(value); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void OrxonoxShip::setPitch(const Radian value) |
---|
| 79 | { |
---|
| 80 | mRootNode->pitch(value); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void OrxonoxShip::setRoll(const Radian value) |
---|
| 84 | { |
---|
| 85 | mRootNode->roll(value); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | Real OrxonoxShip::getThrust() |
---|
| 89 | { |
---|
| 90 | return thrust; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | Bullet* OrxonoxShip::fire() |
---|
| 94 | { |
---|
| 95 | // TODO: Names must be unique! |
---|
| 96 | SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode( |
---|
| 97 | "BulletNode" + StringConverter::toString(n)); |
---|
| 98 | temp->setOrientation(mRootNode->getOrientation()); |
---|
| 99 | temp->setPosition(mRootNode->getPosition()); |
---|
| 100 | temp->setScale(Vector3(1, 1, 1) * 10); |
---|
| 101 | temp->yaw(Degree(-90)); |
---|
| 102 | return new Bullet(temp, mSceneMgr->createEntity("bullet" |
---|
| 103 | + StringConverter::toString(n++), "Barrel.mesh"), speed |
---|
| 104 | + (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy() |
---|
| 105 | * bulletSpeed); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | bool OrxonoxShip::tick(unsigned long time, Real deltaTime) |
---|
| 109 | { |
---|
| 110 | Quaternion quad = mRootNode->getOrientation(); |
---|
| 111 | quad.normalise(); |
---|
| 112 | speed += quad * Vector3(0, 0, -1) * thrust * deltaTime; |
---|
| 113 | speed += quad * Vector3(-1, 0, 0) * sideThrust * deltaTime; |
---|
| 114 | |
---|
| 115 | mRootNode->translate(speed * deltaTime); |
---|
| 116 | |
---|
| 117 | return true; |
---|
| 118 | } |
---|