Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto/src/orxonox_ship.cc @ 146

Last change on this file since 146 was 146, checked in by rgrieder, 12 years ago
File size: 3.0 KB
Line 
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
31OrxonoxShip::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
39OrxonoxShip::~OrxonoxShip()
40{
41}
42
43
44bool 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
62void OrxonoxShip::setThrust(const Real value)
63{
64        thrust = value * baseThrust;
65}
66
67void OrxonoxShip::setSideThrust(const Real value)
68{
69        sideThrust = value * baseThrust;
70}
71
72void OrxonoxShip::setYaw(const Radian value)
73{
74        mRootNode->yaw(value);
75}
76
77void OrxonoxShip::setPitch(const Radian value)
78{
79        mRootNode->pitch(value);
80}
81
82void OrxonoxShip::setRoll(const Radian value)
83{
84        mRootNode->roll(value);
85}
86
87Real OrxonoxShip::getThrust()
88{
89        return thrust;
90}
91
92Bullet* OrxonoxShip::fire()
93{
94        // TODO: Names must be unique!
95        SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode(
96        "BulletNode" + StringConverter::toString(n));
97        temp->setOrientation(mRootNode->getOrientation());
98        temp->setPosition(mRootNode->getPosition());
99        temp->setScale(Vector3(1, 1, 1) * 10);
100        temp->yaw(Degree(-90));
101        return new Bullet(temp, mSceneMgr->createEntity("bullet"
102        + StringConverter::toString(n++), "Barrel.mesh"), speed
103        + (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy()
104        * bulletSpeed);
105}
106
107bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
108{
109  Quaternion quad = mRootNode->getOrientation();
110  quad.normalise();
111  speed += quad * Vector3(0, 0, -1) * thrust * deltaTime;
112        speed += quad * Vector3(-1, 0,  0) * sideThrust * deltaTime;
113
114        mRootNode->translate(speed * deltaTime);
115
116        return true;
117}
Note: See TracBrowser for help on using the repository browser.