Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto_vs05/src/orxonox_ship.cc @ 159

Last change on this file since 159 was 159, checked in by rgrieder, 17 years ago
File size: 6.2 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/**
29* Base class for any kind of flyable ship in Orxonox.
30*
31* The ship offers steering methods (like left, right, etc.) and translates
32* them into movement. A ship can also hold more than one weapons (where each
33* of these can be replaced during the game). This means that a ship can have
34* many WeaponManagers but only one MunitionManager (independant object that
35* is referenced in each WeaponManager).
36* Furthermore a ship in Orxonox is responsible for its visualization, which is
37* why it receives a pointer to the SceneManager.
38*/
39
40
41#include "orxonox_ship.h"
42
43
44/**
45* Standard constructor, that only initalizes a few variables. Some of them
46* could be made static, since any new ship would be derived from the BaseShip.
47* Or even better: write config files for each ship so that manipulating
48* its properties would be even easier.
49* @param mSceneMgr The current main SceneManager
50* @param mNode The scene node which the ship will be attached to later.
51*/
52OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node)
53            : sceneMgr_(sceneMgr), rootNode_(node), currentSpeed_(Vector3(0, 0, 0)),
54      baseThrust_(1000), currentThrust_(Vector3::ZERO),
55      objectCounter_(0), bulletSpeed_(400)
56{
57}
58
59
60/**
61* Standard destructor.
62* Doesn't have any work to do yet.
63*/
64OrxonoxShip::~OrxonoxShip()
65{
66}
67
68
69/**
70* Initialises everything.
71* Once that ResourceGroups are organised, this method loads them.
72* It might be an idea to make this function static in order for the
73* SceneManger to call the initialise method of every needed class (macros..)
74* @return Returns false when failed.
75*/
76bool OrxonoxShip::initialise()
77{
78        // load all the resources needed (no resource groups yet,
79  // so the allInit is not executed!)
80        // ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
81
82        // create the "space ship" (currently a fish..)
83        // TODO: names must be unique! use static variables..
84        shipEntity_ = sceneMgr_->createEntity("Ship", "fish.mesh");
85        SceneNode *fishNode = rootNode_->createChildSceneNode("fishNode");
86        fishNode->yaw(Degree(-90));
87        fishNode->attachObject(shipEntity_);
88        fishNode->setScale(Vector3(10, 10, 10));
89
90        return true;
91}
92
93
94/**
95* Gets the ship to accelerate in the current direction.
96* The value should be between 0 and 1, with one beeing full thrust and 0 none.
97* @param value Acceleration between 0 and 1
98*/
99void OrxonoxShip::setMainThrust(const Real value)
100{
101        //currentThrust_ = value * baseThrust_;
102  currentThrust_.z = value * baseThrust_;
103}
104
105
106/**
107* Gets the ship to accelerate sideways regarding the current direction.
108* The value should be between 0 and 1, with one beeing full thrust and 0 none.
109* @param value Acceleration between 0 and 1
110*/
111void OrxonoxShip::setSideThrust(const Real value)
112{
113        //currentSideThrust_ = value * baseThrust_;
114  currentThrust_.x = value * baseThrust_;
115}
116
117
118/**
119* Gets the ship to accelerate up and down.
120* The value should be between 0 and 1, with one beeing full thrust and 0 none.
121* @param value Acceleration between 0 and 1
122*/
123void OrxonoxShip::setYThrust(const Real value)
124{
125  //currentYThrust_ = value * baseThrust_;
126  currentThrust_.y = value * baseThrust_;
127}
128
129
130/**
131* Rotate the ship along with the camera up and down.
132* @param angle Pitch value.
133*/
134void OrxonoxShip::turnUpAndDown(const Radian &angle)
135{
136  rootNode_->pitch(-angle, Node::TS_LOCAL);
137}
138
139
140/**
141* Rotate the ship along with the camera left and right.
142* @param angle Yaw value.
143*/
144void OrxonoxShip::turnLeftAndRight(const Radian &angle)
145{
146  rootNode_->yaw(-angle, Node::TS_PARENT);
147}
148
149
150/**
151* Returns the current speed of the ship according to its parent node.
152* @return The current speed.
153*/
154Vector3 OrxonoxShip::getSpeed()
155{
156  return currentSpeed_;
157}
158
159/**
160* Returns the ship's root SceneNode.
161* @return The Root Node.
162*/
163SceneNode* OrxonoxShip::getRootNode()
164{
165  return rootNode_;
166}
167
168
169/**
170* Fire a bullet (Entity with SceneNode).
171* This method creates a new Entity plus a SceneNode. But be sure not make
172* the new Node a child of RootNode_!
173* @return Bullet containing speed and entity.
174*/
175Bullet* OrxonoxShip::fire()
176{
177        // TODO: Names must be unique!
178        SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(
179        "BulletNode" + StringConverter::toString(objectCounter_));
180        temp->setOrientation(rootNode_->getOrientation());
181        temp->setPosition(rootNode_->getPosition());
182        temp->setScale(Vector3(1, 1, 1) * 10);
183        temp->yaw(Degree(-90));
184        return new Bullet(temp, sceneMgr_->createEntity("bullet"
185        + StringConverter::toString(objectCounter_++), "Barrel.mesh"), currentSpeed_
186        + (rootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()
187        * bulletSpeed_);
188}
189
190
191/**
192* Standard tick() function.
193* Currently, only the speed is applied according to the thrust values.
194* @param time Absolute time.
195* @param deltaTime Relative time.
196* @return Return true to continue render
197*/
198bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
199{
200  Quaternion quad = rootNode_->getOrientation();
201  quad.normalise();
202  currentSpeed_ += quad * (Vector3(-1, -1, -1) * currentThrust_) * deltaTime;
203  //currentSpeed_ += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime;
204        //currentSpeed_ += quad * Vector3(-1, 0,  0) * currentSideThrust_ * deltaTime;
205
206        rootNode_->translate(currentSpeed_ * deltaTime);
207
208        return true;
209}
Note: See TracBrowser for help on using the repository browser.