Changeset 152 for code/branches/main_reto/src/orxonox_ship.cc
- Timestamp:
- Nov 3, 2007, 6:20:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto/src/orxonox_ship.cc
r147 r152 26 26 */ 27 27 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 28 41 #include "orxonox_ship.h" 29 42 30 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 */ 31 52 OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode) 32 53 : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)), … … 37 58 38 59 60 /** 61 * Standard destructor. 62 * Doesn't have any work to do yet. 63 */ 39 64 OrxonoxShip::~OrxonoxShip() 40 65 { … … 42 67 43 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 */ 44 75 bool OrxonoxShip::initialise() 45 76 { … … 49 80 50 81 // create the "space ship" (currently a fish..) 51 // TODO: names must be unique! 82 // TODO: names must be unique! use static variables.. 52 83 mShip = mSceneMgr->createEntity("Ship", "fish.mesh"); 53 84 SceneNode *fishNode = mRootNode->createChildSceneNode("fishNode"); … … 60 91 61 92 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 */ 62 98 void OrxonoxShip::setThrust(const Real value) 63 99 { … … 66 102 67 103 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 */ 68 109 void OrxonoxShip::setSideThrust(const Real value) 69 110 { … … 71 112 } 72 113 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 */ 119 void OrxonoxShip::turnUpAndDown(const Radian &angle) 74 120 { 75 mRootNode->yaw(value);121 RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL); 76 122 } 77 123 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 */ 129 void OrxonoxShip::turnLeftAndRight(const Radian &angle) 79 130 { 80 mRootNode->pitch(value);131 RootNode_->yaw(angle, Ogre::Node::TransformSpace::TS_PARENT); 81 132 } 82 133 83 void OrxonoxShip::setRoll(const Radian value)84 {85 mRootNode->roll(value);86 }87 134 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 */ 93 140 Bullet* OrxonoxShip::fire() 94 141 { 95 142 // 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()); 100 147 temp->setScale(Vector3(1, 1, 1) * 10); 101 148 temp->yaw(Degree(-90)); 102 149 return new Bullet(temp, mSceneMgr->createEntity("bullet" 103 + StringConverter::toString( n++), "Barrel.mesh"), speed104 + ( 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_); 106 153 } 107 154 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 */ 108 162 bool OrxonoxShip::tick(unsigned long time, Real deltaTime) 109 163 { 110 164 Quaternion quad = mRootNode->getOrientation(); 111 165 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; 114 168 115 mRootNode->translate(speed* deltaTime);169 RootNode_->translate(currentSpeed_ * deltaTime); 116 170 117 171 return true;
Note: See TracChangeset
for help on using the changeset viewer.