Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 4, 2007, 5:00:41 PM (16 years ago)
Author:
rgrieder
Message:
  • added namespace Orxonox to every file
    • removed all the "using namespace Ogre" in the header files
  • cleaned up with the includes: attempt to include as little as possible to reduce compile time.
    • created a header file: orxonox_prerequisites.h
    • used OgrePrerequisites in the header files
    • avoided including "Ogre.h", using separate files instead
  • created empty class: AmmunitionDump
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto_vs05/src/orxonox_ship.cc

    r159 r161  
    2626 */
    2727
    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 
     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"
    4035
    4136#include "orxonox_ship.h"
    4237
    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 */
    52 OrxonoxShip::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 {
     38namespace Orxonox {
     39  using namespace Ogre;
     40
     41  /**
     42  * Base class for any kind of flyable ship in Orxonox.
     43  *
     44  * The ship offers steering methods (like left, right, etc.) and translates
     45  * them into movement. A ship can also hold more than one weapons (where each
     46  * of these can be replaced during the game). This means that a ship can have
     47  * many WeaponManagers but only one MunitionManager (independant object that
     48  * is referenced in each WeaponManager).
     49  * Furthermore a ship in Orxonox is responsible for its visualization, which is
     50  * why it receives a pointer to the SceneManager.
     51  */
     52
     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          return true;
     103  }
     104
     105
     106  /**
     107  * Gets the ship to accelerate in 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  */
     111  void OrxonoxShip::setMainThrust(const Real value)
     112  {
     113          //currentThrust_ = value * baseThrust_;
     114    currentThrust_.z = value * baseThrust_;
     115  }
     116
     117
     118  /**
     119  * Gets the ship to accelerate sideways regarding the current direction.
     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  */
     123  void OrxonoxShip::setSideThrust(const Real value)
     124  {
     125          //currentSideThrust_ = value * baseThrust_;
     126    currentThrust_.x = value * baseThrust_;
     127  }
     128
     129
     130  /**
     131  * Gets the ship to accelerate up and down.
     132  * The value should be between 0 and 1, with one beeing full thrust and 0 none.
     133  * @param value Acceleration between 0 and 1
     134  */
     135  void OrxonoxShip::setYThrust(const Real value)
     136  {
     137    //currentYThrust_ = value * baseThrust_;
     138    currentThrust_.y = value * baseThrust_;
     139  }
     140
     141
     142  /**
     143  * Rotate the ship along with the camera up and down.
     144  * @param angle Pitch value.
     145  */
     146  void OrxonoxShip::turnUpAndDown(const Radian &angle)
     147  {
     148    rootNode_->pitch(-angle, Node::TS_LOCAL);
     149  }
     150
     151
     152  /**
     153  * Rotate the ship along with the camera left and right.
     154  * @param angle Yaw value.
     155  */
     156  void OrxonoxShip::turnLeftAndRight(const Radian &angle)
     157  {
     158    rootNode_->yaw(-angle, Node::TS_PARENT);
     159  }
     160
     161
     162  /**
     163  * Returns the current speed of the ship according to its parent node.
     164  * @return The current speed.
     165  */
     166  Vector3 OrxonoxShip::getSpeed()
     167  {
     168    return currentSpeed_;
     169  }
     170
     171  /**
     172  * Returns the ship's root SceneNode.
     173  * @return The Root Node.
     174  */
     175  SceneNode* OrxonoxShip::getRootNode()
     176  {
     177    return rootNode_;
     178  }
     179
     180
     181  /**
     182  * Fire a bullet (Entity with SceneNode).
     183  * This method creates a new Entity plus a SceneNode. But be sure not make
     184  * the new Node a child of RootNode_!
     185  * @return Bullet containing speed and entity.
     186  */
     187  Bullet* OrxonoxShip::fire()
     188  {
     189          // TODO: Names must be unique!
     190          SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(
     191          "BulletNode" + StringConverter::toString(objectCounter_));
     192          temp->setOrientation(rootNode_->getOrientation());
     193          temp->setPosition(rootNode_->getPosition());
     194          temp->setScale(Vector3(1, 1, 1) * 10);
     195          temp->yaw(Degree(-90));
     196          return new Bullet(temp, sceneMgr_->createEntity("bullet"
     197          + StringConverter::toString(objectCounter_++), "Barrel.mesh"), currentSpeed_
     198          + (rootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()
     199          * bulletSpeed_);
     200  }
     201
     202
     203  /**
     204  * Standard tick() function.
     205  * Currently, only the speed is applied according to the thrust values.
     206  * @param time Absolute time.
     207  * @param deltaTime Relative time.
     208  * @return Return true to continue render
     209  */
     210  bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
     211  {
     212    Quaternion quad = rootNode_->getOrientation();
     213    quad.normalise();
     214    currentSpeed_ += quad * (Vector3(-1, -1, -1) * currentThrust_) * deltaTime;
     215    //currentSpeed_ += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime;
     216          //currentSpeed_ += quad * Vector3(-1, 0,  0) * currentSideThrust_ * deltaTime;
     217
     218          rootNode_->translate(currentSpeed_ * deltaTime);
     219
     220          return true;
     221  }
     222
    57223}
    58 
    59 
    60 /**
    61 * Standard destructor.
    62 * Doesn't have any work to do yet.
    63 */
    64 OrxonoxShip::~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 */
    76 bool 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 */
    99 void 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 */
    111 void 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 */
    123 void 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 */
    134 void 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 */
    144 void 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 */
    154 Vector3 OrxonoxShip::getSpeed()
    155 {
    156   return currentSpeed_;
    157 }
    158 
    159 /**
    160 * Returns the ship's root SceneNode.
    161 * @return The Root Node.
    162 */
    163 SceneNode* 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 */
    175 Bullet* 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 */
    198 bool 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 TracChangeset for help on using the changeset viewer.