Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 3, 2007, 11:06:43 PM (16 years ago)
Author:
rgrieder
Message:
 
File:
1 edited

Legend:

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

    r157 r159  
    5050* @param mNode The scene node which the ship will be attached to later.
    5151*/
    52 OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode)
    53             : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)),
    54       baseThrust(1000), thrust(0), sideThrust(0), n(0),
    55         bulletSpeed(400)
     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)
    5656{
    5757}
     
    7272* It might be an idea to make this function static in order for the
    7373* SceneManger to call the initialise method of every needed class (macros..)
     74* @return Returns false when failed.
    7475*/
    7576bool OrxonoxShip::initialise()
     
    8182        // create the "space ship" (currently a fish..)
    8283        // TODO: names must be unique! use static variables..
    83         mShip = mSceneMgr->createEntity("Ship", "fish.mesh");
    84         SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode");
     84        shipEntity_ = sceneMgr_->createEntity("Ship", "fish.mesh");
     85        SceneNode *fishNode = rootNode_->createChildSceneNode("fishNode");
    8586        fishNode->yaw(Degree(-90));
    86         fishNode->attachObject(mShip);
     87        fishNode->attachObject(shipEntity_);
    8788        fishNode->setScale(Vector3(10, 10, 10));
    8889
     
    9697* @param value Acceleration between 0 and 1
    9798*/
    98 void OrxonoxShip::setThrust(const Real value)
    99 {
    100         thrust = value * baseThrust;
     99void OrxonoxShip::setMainThrust(const Real value)
     100{
     101        //currentThrust_ = value * baseThrust_;
     102  currentThrust_.z = value * baseThrust_;
    101103}
    102104
     
    109111void OrxonoxShip::setSideThrust(const Real value)
    110112{
    111         sideThrust = value * baseThrust;
     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_;
    112127}
    113128
     
    119134void OrxonoxShip::turnUpAndDown(const Radian &angle)
    120135{
    121   RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL);
     136  rootNode_->pitch(-angle, Node::TS_LOCAL);
    122137}
    123138
     
    129144void OrxonoxShip::turnLeftAndRight(const Radian &angle)
    130145{
    131   RootNode_->yaw(angle, Ogre::Node::TransformSpace::TS_PARENT);
     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_;
    132166}
    133167
     
    137171* This method creates a new Entity plus a SceneNode. But be sure not make
    138172* the new Node a child of RootNode_!
     173* @return Bullet containing speed and entity.
    139174*/
    140175Bullet* OrxonoxShip::fire()
    141176{
    142177        // TODO: Names must be unique!
    143         SceneNode *temp = RootNode_->getParentSceneNode()->createChildSceneNode(
     178        SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(
    144179        "BulletNode" + StringConverter::toString(objectCounter_));
    145         temp->setOrientation(RootNode_->getOrientation());
    146         temp->setPosition(RootNode_->getPosition());
     180        temp->setOrientation(rootNode_->getOrientation());
     181        temp->setPosition(rootNode_->getPosition());
    147182        temp->setScale(Vector3(1, 1, 1) * 10);
    148183        temp->yaw(Degree(-90));
    149         return new Bullet(temp, mSceneMgr->createEntity("bullet"
    150         + StringConverter::toString(objectCounter_++), "Barrel.mesh"), speed
    151         + (RootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()
     184        return new Bullet(temp, sceneMgr_->createEntity("bullet"
     185        + StringConverter::toString(objectCounter_++), "Barrel.mesh"), currentSpeed_
     186        + (rootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()
    152187        * bulletSpeed_);
    153188}
     
    159194* @param time Absolute time.
    160195* @param deltaTime Relative time.
     196* @return Return true to continue render
    161197*/
    162198bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
    163199{
    164   Quaternion quad = mRootNode->getOrientation();
     200  Quaternion quad = rootNode_->getOrientation();
    165201  quad.normalise();
    166   speed += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime;
    167         speed += quad * Vector3(-1, 0,  0) * current_SideThrust_ * deltaTime;
    168 
    169         RootNode_->translate(currentSpeed_ * deltaTime);
     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);
    170207
    171208        return true;
Note: See TracChangeset for help on using the changeset viewer.