Changeset 190 for code/branches/main_reto/src/orxonox_ship.cc
- Timestamp:
- Nov 7, 2007, 10:03:26 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto/src/orxonox_ship.cc
r171 r190 33 33 34 34 #include "bullet.h" 35 #include "bullet_manager.h" 36 #include "inertial_node.h" 37 #include "weapon_manager.h" 35 38 36 39 #include "orxonox_ship.h" 37 #include "weapon_manager.h"38 40 39 41 40 42 namespace orxonox { 41 43 using namespace Ogre; 44 using namespace weapon; 42 45 43 46 /** … … 62 65 * @param mNode The scene node which the ship will be attached to later. 63 66 */ 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)), 66 70 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); 69 74 } 70 75 … … 76 81 OrxonoxShip::~OrxonoxShip() 77 82 { 83 if (mainWeapon_) 84 delete mainWeapon_; 85 if (rootNode_) 86 delete rootNode_; 78 87 } 79 88 … … 95 104 // TODO: names must be unique! use static variables.. 96 105 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)); 101 110 102 111 // 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"); 105 116 106 117 return true; … … 110 121 /** 111 122 * 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 113 124 * @param value Acceleration between 0 and 1 114 125 */ 115 126 void OrxonoxShip::setMainThrust(const Real value) 116 127 { 117 //currentThrust_ = value * baseThrust_;118 128 currentThrust_.z = value * baseThrust_; 119 129 } … … 122 132 /** 123 133 * 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 125 135 * @param value Acceleration between 0 and 1 126 136 */ 127 137 void OrxonoxShip::setSideThrust(const Real value) 128 138 { 129 //currentSideThrust_ = value * baseThrust_;130 139 currentThrust_.x = value * baseThrust_; 131 140 } … … 134 143 /** 135 144 * 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 137 146 * @param value Acceleration between 0 and 1 138 147 */ 139 148 void OrxonoxShip::setYThrust(const Real value) 140 149 { 141 //currentYThrust_ = value * baseThrust_;142 150 currentThrust_.y = value * baseThrust_; 143 151 } … … 150 158 void OrxonoxShip::turnUpAndDown(const Radian &angle) 151 159 { 152 rootNode_-> pitch(-angle, Node::TS_LOCAL);160 rootNode_->getSceneNode()->pitch(-angle, Node::TS_LOCAL); 153 161 } 154 162 … … 160 168 void OrxonoxShip::turnLeftAndRight(const Radian &angle) 161 169 { 162 rootNode_-> yaw(-angle, Node::TS_PARENT);170 rootNode_->getSceneNode()->yaw(-angle, Node::TS_PARENT); 163 171 } 164 172 … … 170 178 Vector3 OrxonoxShip::getSpeed() 171 179 { 172 return currentSpeed_;180 return rootNode_->getSpeed(); 173 181 } 174 182 … … 177 185 * @return The Root Node. 178 186 */ 179 SceneNode* OrxonoxShip::getRootNode()187 InertialNode* OrxonoxShip::getRootNode() 180 188 { 181 189 return rootNode_; … … 189 197 * @return Bullet containing speed and entity. 190 198 */ 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(); 204 202 } 205 203 … … 214 212 bool OrxonoxShip::tick(unsigned long time, Real deltaTime) 215 213 { 216 Quaternion quad = rootNode_->getOrientation(); 214 mainWeapon_->tick(time, deltaTime); 215 216 Quaternion quad = rootNode_->getSceneNode()->getOrientation(); 217 217 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); 223 221 224 222 return true;
Note: See TracChangeset
for help on using the changeset viewer.