Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto/src/OrxonoxShip.cpp @ 136

Last change on this file since 136 was 136, checked in by rgrieder, 16 years ago
File size: 2.1 KB
RevLine 
[127]1#include "OrxonoxShip.h"
2
3
[128]4OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode)
[136]5        : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)), baseThrust(1000), thrust(0), sideThrust(0), n(0),
[133]6        bulletSpeed(400)
[127]7{
8}
9
10
11OrxonoxShip::~OrxonoxShip()
12{
13}
14
15
16bool 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
33void OrxonoxShip::setThrust(const Real value)
34{
35        thrust = value * baseThrust;
36}
37
38void OrxonoxShip::setSideThrust(const Real value)
39{
[130]40        sideThrust = value * baseThrust;
[128]41}
42
43void OrxonoxShip::setYaw(const Radian value)
44{
45        mRootNode->yaw(value);
46}
47
48void OrxonoxShip::setPitch(const Radian value)
49{
50        mRootNode->pitch(value);
51}
52
53void OrxonoxShip::setRoll(const Radian value)
54{
55        mRootNode->roll(value);
56}
57
[130]58Real OrxonoxShip::getThrust()
59{
60        return thrust;
61}
[128]62
[133]63Bullet* 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]76bool OrxonoxShip::tick(unsigned long time, float deltaTime)
77{
[130]78        speed += (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy() * thrust * deltaTime;
[136]79        speed += (mRootNode->getLocalAxes() * Vector3(-1, 0,  0)).normalisedCopy() * sideThrust * deltaTime;
[128]80
81        mRootNode->translate(speed * deltaTime);
82
83        return true;
84}
Note: See TracBrowser for help on using the repository browser.