Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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