Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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