Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 3, 2007, 6:20:21 PM (16 years ago)
Author:
rgrieder
Message:
  • added a few comments
  • converted RunManager and OrxonoxShip to match the style guide
File:
1 edited

Legend:

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

    r147 r152  
    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
     40
    2841#include "orxonox_ship.h"
    2942
    3043
     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*/
    3152OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode)
    3253            : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)),
     
    3758
    3859
     60/**
     61* Standard destructor.
     62* Doesn't have any work to do yet.
     63*/
    3964OrxonoxShip::~OrxonoxShip()
    4065{
     
    4267
    4368
     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*/
    4475bool OrxonoxShip::initialise()
    4576{
     
    4980
    5081        // create the "space ship" (currently a fish..)
    51         // TODO: names must be unique!
     82        // TODO: names must be unique! use static variables..
    5283        mShip = mSceneMgr->createEntity("Ship", "fish.mesh");
    5384        SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode");
     
    6091
    6192
     93/**
     94* Gets the ship to accelerate in the current direction.
     95* The value should be between 0 and 1, with one beeing full thrust and 0 none.
     96* @param value Acceleration between 0 and 1
     97*/
    6298void OrxonoxShip::setThrust(const Real value)
    6399{
     
    66102
    67103
     104/**
     105* Gets the ship to accelerate sideways regarding the current direction.
     106* The value should be between 0 and 1, with one beeing full thrust and 0 none.
     107* @param value Acceleration between 0 and 1
     108*/
    68109void OrxonoxShip::setSideThrust(const Real value)
    69110{
     
    71112}
    72113
    73 void OrxonoxShip::setYaw(const Radian value)
     114
     115/**
     116* Rotate the ship along with the camera up and down.
     117* @param angle Pitch value.
     118*/
     119void OrxonoxShip::turnUpAndDown(const Radian &angle)
    74120{
    75         mRootNode->yaw(value);
     121  RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL);
    76122}
    77123
    78 void OrxonoxShip::setPitch(const Radian value)
     124
     125/**
     126* Rotate the ship along with the camera left and right.
     127* @param angle Yaw value.
     128*/
     129void OrxonoxShip::turnLeftAndRight(const Radian &angle)
    79130{
    80         mRootNode->pitch(value);
     131  RootNode_->yaw(angle, Ogre::Node::TransformSpace::TS_PARENT);
    81132}
    82133
    83 void OrxonoxShip::setRoll(const Radian value)
    84 {
    85         mRootNode->roll(value);
    86 }
    87134
    88 Real OrxonoxShip::getThrust()
    89 {
    90         return thrust;
    91 }
    92 
     135/**
     136* Fire a bullet (Entity with SceneNode).
     137* This method creates a new Entity plus a SceneNode. But be sure not make
     138* the new Node a child of RootNode_!
     139*/
    93140Bullet* OrxonoxShip::fire()
    94141{
    95142        // TODO: Names must be unique!
    96         SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode(
    97         "BulletNode" + StringConverter::toString(n));
    98         temp->setOrientation(mRootNode->getOrientation());
    99         temp->setPosition(mRootNode->getPosition());
     143        SceneNode *temp = RootNode_->getParentSceneNode()->createChildSceneNode(
     144        "BulletNode" + StringConverter::toString(objectCounter_));
     145        temp->setOrientation(RootNode_->getOrientation());
     146        temp->setPosition(RootNode_->getPosition());
    100147        temp->setScale(Vector3(1, 1, 1) * 10);
    101148        temp->yaw(Degree(-90));
    102149        return new Bullet(temp, mSceneMgr->createEntity("bullet"
    103         + StringConverter::toString(n++), "Barrel.mesh"), speed
    104         + (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy()
    105         * bulletSpeed);
     150        + StringConverter::toString(objectCounter_++), "Barrel.mesh"), speed
     151        + (RootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()
     152        * bulletSpeed_);
    106153}
    107154
     155
     156/**
     157* Standard tick() function.
     158* Currently, only the speed is applied according to the thrust values.
     159* @param time Absolute time.
     160* @param deltaTime Relative time.
     161*/
    108162bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
    109163{
    110164  Quaternion quad = mRootNode->getOrientation();
    111165  quad.normalise();
    112   speed += quad * Vector3(0, 0, -1) * thrust * deltaTime;
    113         speed += quad * Vector3(-1, 0,  0) * sideThrust * deltaTime;
     166  speed += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime;
     167        speed += quad * Vector3(-1, 0,  0) * current_SideThrust_ * deltaTime;
    114168
    115         mRootNode->translate(speed * deltaTime);
     169        RootNode_->translate(currentSpeed_ * deltaTime);
    116170
    117171        return true;
Note: See TracChangeset for help on using the changeset viewer.