Changeset 159 for code/branches/main_reto_vs05/src/orxonox_ship.cc
- Timestamp:
- Nov 3, 2007, 11:06:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/orxonox_ship.cc
r157 r159 50 50 * @param mNode The scene node which the ship will be attached to later. 51 51 */ 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)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 56 { 57 57 } … … 72 72 * It might be an idea to make this function static in order for the 73 73 * SceneManger to call the initialise method of every needed class (macros..) 74 * @return Returns false when failed. 74 75 */ 75 76 bool OrxonoxShip::initialise() … … 81 82 // create the "space ship" (currently a fish..) 82 83 // 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"); 85 86 fishNode->yaw(Degree(-90)); 86 fishNode->attachObject( mShip);87 fishNode->attachObject(shipEntity_); 87 88 fishNode->setScale(Vector3(10, 10, 10)); 88 89 … … 96 97 * @param value Acceleration between 0 and 1 97 98 */ 98 void OrxonoxShip::setThrust(const Real value) 99 { 100 thrust = value * baseThrust; 99 void OrxonoxShip::setMainThrust(const Real value) 100 { 101 //currentThrust_ = value * baseThrust_; 102 currentThrust_.z = value * baseThrust_; 101 103 } 102 104 … … 109 111 void OrxonoxShip::setSideThrust(const Real value) 110 112 { 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 */ 123 void OrxonoxShip::setYThrust(const Real value) 124 { 125 //currentYThrust_ = value * baseThrust_; 126 currentThrust_.y = value * baseThrust_; 112 127 } 113 128 … … 119 134 void OrxonoxShip::turnUpAndDown(const Radian &angle) 120 135 { 121 RootNode_->pitch(angle, Ogre::Node::TransformSpace::TS_LOCAL);136 rootNode_->pitch(-angle, Node::TS_LOCAL); 122 137 } 123 138 … … 129 144 void OrxonoxShip::turnLeftAndRight(const Radian &angle) 130 145 { 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 */ 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_; 132 166 } 133 167 … … 137 171 * This method creates a new Entity plus a SceneNode. But be sure not make 138 172 * the new Node a child of RootNode_! 173 * @return Bullet containing speed and entity. 139 174 */ 140 175 Bullet* OrxonoxShip::fire() 141 176 { 142 177 // TODO: Names must be unique! 143 SceneNode *temp = RootNode_->getParentSceneNode()->createChildSceneNode(178 SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode( 144 179 "BulletNode" + StringConverter::toString(objectCounter_)); 145 temp->setOrientation( RootNode_->getOrientation());146 temp->setPosition( RootNode_->getPosition());180 temp->setOrientation(rootNode_->getOrientation()); 181 temp->setPosition(rootNode_->getPosition()); 147 182 temp->setScale(Vector3(1, 1, 1) * 10); 148 183 temp->yaw(Degree(-90)); 149 return new Bullet(temp, mSceneMgr->createEntity("bullet"150 + StringConverter::toString(objectCounter_++), "Barrel.mesh"), speed151 + ( 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() 152 187 * bulletSpeed_); 153 188 } … … 159 194 * @param time Absolute time. 160 195 * @param deltaTime Relative time. 196 * @return Return true to continue render 161 197 */ 162 198 bool OrxonoxShip::tick(unsigned long time, Real deltaTime) 163 199 { 164 Quaternion quad = mRootNode->getOrientation();200 Quaternion quad = rootNode_->getOrientation(); 165 201 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); 170 207 171 208 return true;
Note: See TracChangeset
for help on using the changeset viewer.