Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 7, 2007, 10:03:26 PM (16 years ago)
Author:
rgrieder
Message:

added files from rev 189

File:
1 edited

Legend:

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

    r171 r190  
    3333
    3434#include "bullet.h"
     35#include "bullet_manager.h"
     36#include "inertial_node.h"
     37#include "weapon_manager.h"
    3538
    3639#include "orxonox_ship.h"
    37 #include "weapon_manager.h"
    3840
    3941
    4042namespace orxonox {
    4143  using namespace Ogre;
     44  using namespace weapon;
    4245
    4346  /**
     
    6265  * @param mNode The scene node which the ship will be attached to later.
    6366  */
    64   OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node)
    65               : sceneMgr_(sceneMgr), rootNode_(node), currentSpeed_(Vector3(0, 0, 0)),
     67  OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node,
     68        BulletManager *bulletManager)
     69              : sceneMgr_(sceneMgr), //currentSpeed_(Vector3(0, 0, 0)),
    6670        baseThrust_(1000), currentThrust_(Vector3::ZERO),
    67         objectCounter_(0), bulletSpeed_(400)
    68   {
     71        objectCounter_(0), bulletManager_(bulletManager)//, bulletSpeed_(400)
     72  {
     73    rootNode_ = new InertialNode(node, Vector3::ZERO);
    6974  }
    7075
     
    7681  OrxonoxShip::~OrxonoxShip()
    7782  {
     83    if (mainWeapon_)
     84      delete mainWeapon_;
     85    if (rootNode_)
     86      delete rootNode_;
    7887  }
    7988
     
    95104          // TODO: names must be unique! use static variables..
    96105          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));
     106          InertialNode *fishNode = rootNode_->createChildNode();
     107    fishNode->getSceneNode()->yaw(Degree(-90));
     108          fishNode->getSceneNode()->attachObject(shipEntity_);
     109          fishNode->getSceneNode()->setScale(Vector3(10, 10, 10));
    101110
    102111    // initialise weapon(s)
    103     SceneNode *mainWeaponNode = rootNode_->createChildSceneNode("mainWeaponNode");
    104     mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode, 1);
     112    InertialNode *mainWeaponNode = rootNode_->createChildNode();
     113    mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode,
     114          bulletManager_, 1);
     115    mainWeapon_->addWeapon("Barrel Gun");
    105116
    106117          return true;
     
    110121  /**
    111122  * 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.
     123  * The value should be between 0 and 1, with one beeing full thrust and 0 none
    113124  * @param value Acceleration between 0 and 1
    114125  */
    115126  void OrxonoxShip::setMainThrust(const Real value)
    116127  {
    117           //currentThrust_ = value * baseThrust_;
    118128    currentThrust_.z = value * baseThrust_;
    119129  }
     
    122132  /**
    123133  * 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.
     134  * The value should be between 0 and 1, with one beeing full thrust and 0 none
    125135  * @param value Acceleration between 0 and 1
    126136  */
    127137  void OrxonoxShip::setSideThrust(const Real value)
    128138  {
    129           //currentSideThrust_ = value * baseThrust_;
    130139    currentThrust_.x = value * baseThrust_;
    131140  }
     
    134143  /**
    135144  * 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.
     145  * The value should be between 0 and 1, with one beeing full thrust and 0 none
    137146  * @param value Acceleration between 0 and 1
    138147  */
    139148  void OrxonoxShip::setYThrust(const Real value)
    140149  {
    141     //currentYThrust_ = value * baseThrust_;
    142150    currentThrust_.y = value * baseThrust_;
    143151  }
     
    150158  void OrxonoxShip::turnUpAndDown(const Radian &angle)
    151159  {
    152     rootNode_->pitch(-angle, Node::TS_LOCAL);
     160    rootNode_->getSceneNode()->pitch(-angle, Node::TS_LOCAL);
    153161  }
    154162
     
    160168  void OrxonoxShip::turnLeftAndRight(const Radian &angle)
    161169  {
    162     rootNode_->yaw(-angle, Node::TS_PARENT);
     170    rootNode_->getSceneNode()->yaw(-angle, Node::TS_PARENT);
    163171  }
    164172
     
    170178  Vector3 OrxonoxShip::getSpeed()
    171179  {
    172     return currentSpeed_;
     180    return rootNode_->getSpeed();
    173181  }
    174182
     
    177185  * @return The Root Node.
    178186  */
    179   SceneNode* OrxonoxShip::getRootNode()
     187  InertialNode* OrxonoxShip::getRootNode()
    180188  {
    181189    return rootNode_;
     
    189197  * @return Bullet containing speed and entity.
    190198  */
    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_);
     199  void OrxonoxShip::fire()
     200  {
     201    mainWeapon_->primaryFireRequest();
    204202  }
    205203
     
    214212  bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
    215213  {
    216     Quaternion quad = rootNode_->getOrientation();
     214    mainWeapon_->tick(time, deltaTime);
     215
     216    Quaternion quad = rootNode_->getSceneNode()->getOrientation();
    217217    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);
     218    rootNode_->addSpeed(quad * (Vector3(-1, -1, -1) * currentThrust_) * deltaTime);
     219
     220    rootNode_->getSceneNode()->translate(rootNode_->getSpeed() * deltaTime);
    223221
    224222          return true;
Note: See TracChangeset for help on using the changeset viewer.