[127] | 1 | #include "OrxonoxShip.h" |
---|
| 2 | |
---|
| 3 | |
---|
[128] | 4 | OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode) |
---|
[133] | 5 | : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)), baseThrust(100), thrust(0), sideThrust(0), n(0), |
---|
| 6 | bulletSpeed(400) |
---|
[127] | 7 | { |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | OrxonoxShip::~OrxonoxShip() |
---|
| 12 | { |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | bool OrxonoxShip::initialise() |
---|
| 17 | { |
---|
| 18 | // load all the resources needed (no resource groups yet, so the allInit is not executed!) |
---|
| 19 | //ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 20 | |
---|
| 21 | // create the "space ship" (currently a fish..) |
---|
[133] | 22 | // TODO: names must be unique! |
---|
[127] | 23 | mShip = mSceneMgr->createEntity("Ship", "fish.mesh"); |
---|
[128] | 24 | SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode"); |
---|
| 25 | fishNode->yaw(Degree(-90)); |
---|
| 26 | fishNode->attachObject(mShip); |
---|
| 27 | fishNode->setScale(Vector3(10, 10, 10)); |
---|
[127] | 28 | |
---|
| 29 | return true; |
---|
| 30 | } |
---|
[128] | 31 | |
---|
| 32 | |
---|
| 33 | void OrxonoxShip::setThrust(const Real value) |
---|
| 34 | { |
---|
| 35 | thrust = value * baseThrust; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | void OrxonoxShip::setSideThrust(const Real value) |
---|
| 39 | { |
---|
[130] | 40 | sideThrust = value * baseThrust; |
---|
[128] | 41 | } |
---|
| 42 | |
---|
| 43 | void OrxonoxShip::setYaw(const Radian value) |
---|
| 44 | { |
---|
| 45 | mRootNode->yaw(value); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void OrxonoxShip::setPitch(const Radian value) |
---|
| 49 | { |
---|
| 50 | mRootNode->pitch(value); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void OrxonoxShip::setRoll(const Radian value) |
---|
| 54 | { |
---|
| 55 | mRootNode->roll(value); |
---|
| 56 | } |
---|
| 57 | |
---|
[130] | 58 | Real OrxonoxShip::getThrust() |
---|
| 59 | { |
---|
| 60 | return thrust; |
---|
| 61 | } |
---|
[128] | 62 | |
---|
[133] | 63 | Bullet* OrxonoxShip::fire() |
---|
| 64 | { |
---|
| 65 | // TODO: Names must be unique! |
---|
| 66 | SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode("BulletNode" + StringConverter::toString(n)); |
---|
| 67 | temp->setOrientation(mRootNode->getOrientation()); |
---|
| 68 | temp->setPosition(mRootNode->getPosition()); |
---|
| 69 | temp->setScale(Vector3(1, 1, 1) * 10); |
---|
| 70 | temp->yaw(Degree(-90)); |
---|
| 71 | return new Bullet(temp, |
---|
| 72 | mSceneMgr->createEntity("bullet" + StringConverter::toString(n++), "Barrel.mesh"), |
---|
| 73 | speed + (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy() * bulletSpeed); |
---|
| 74 | } |
---|
[130] | 75 | |
---|
[128] | 76 | bool OrxonoxShip::tick(unsigned long time, float deltaTime) |
---|
| 77 | { |
---|
[130] | 78 | speed += (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy() * thrust * deltaTime; |
---|
| 79 | speed += (mRootNode->getLocalAxes() * Vector3(1, 0, 0)).normalisedCopy() * sideThrust * deltaTime; |
---|
[128] | 80 | |
---|
| 81 | mRootNode->translate(speed * deltaTime); |
---|
| 82 | |
---|
| 83 | return true; |
---|
| 84 | } |
---|