Changeset 177 for code/branches/main_reto_vs05/src
- Timestamp:
- Nov 7, 2007, 12:39:30 AM (17 years ago)
- Location:
- code/branches/main_reto_vs05/src
- Files:
-
- 2 added
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/orxonox_prerequisites.h
r169 r177 34 34 class AmmunitionDump; 35 35 class Bullet; 36 class BulletManager; 36 37 class CameraManager; 37 38 class OgreControl; -
code/branches/main_reto_vs05/src/orxonox_ship.cc
r169 r177 33 33 34 34 #include "bullet.h" 35 #include "bullet_manager.h" 35 36 36 37 #include "orxonox_ship.h" … … 62 63 * @param mNode The scene node which the ship will be attached to later. 63 64 */ 64 OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node) 65 OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node, 66 BulletManager *bulletManager) 65 67 : sceneMgr_(sceneMgr), rootNode_(node), currentSpeed_(Vector3(0, 0, 0)), 66 68 baseThrust_(1000), currentThrust_(Vector3::ZERO), 67 objectCounter_(0), bullet Speed_(400)69 objectCounter_(0), bulletManager_(bulletManager)//, bulletSpeed_(400) 68 70 { 69 71 } … … 76 78 OrxonoxShip::~OrxonoxShip() 77 79 { 80 if (mainWeapon_) 81 delete mainWeapon_; 78 82 } 79 83 … … 101 105 102 106 // initialise weapon(s) 103 SceneNode *mainWeaponNode = rootNode_->createChildSceneNode("mainWeaponNode"); 104 mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode, 1); 107 SceneNode *mainWeaponNode = rootNode_ 108 ->createChildSceneNode("mainWeaponNode"); 109 mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode, 110 bulletManager_, 1); 111 mainWeapon_->addWeapon("Barrel Gun"); 105 112 106 113 return true; … … 110 117 /** 111 118 * 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 .119 * The value should be between 0 and 1, with one beeing full thrust and 0 none 113 120 * @param value Acceleration between 0 and 1 114 121 */ 115 122 void OrxonoxShip::setMainThrust(const Real value) 116 123 { 117 //currentThrust_ = value * baseThrust_;118 124 currentThrust_.z = value * baseThrust_; 119 125 } … … 122 128 /** 123 129 * 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 .130 * The value should be between 0 and 1, with one beeing full thrust and 0 none 125 131 * @param value Acceleration between 0 and 1 126 132 */ 127 133 void OrxonoxShip::setSideThrust(const Real value) 128 134 { 129 //currentSideThrust_ = value * baseThrust_;130 135 currentThrust_.x = value * baseThrust_; 131 136 } … … 134 139 /** 135 140 * 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 .141 * The value should be between 0 and 1, with one beeing full thrust and 0 none 137 142 * @param value Acceleration between 0 and 1 138 143 */ 139 144 void OrxonoxShip::setYThrust(const Real value) 140 145 { 141 //currentYThrust_ = value * baseThrust_;142 146 currentThrust_.y = value * baseThrust_; 143 147 } … … 189 193 * @return Bullet containing speed and entity. 190 194 */ 191 Bullet*OrxonoxShip::fire()195 void OrxonoxShip::fire() 192 196 { 193 197 // TODO: Names must be unique! 194 SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(198 /*SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode( 195 199 "BulletNode" + StringConverter::toString(objectCounter_)); 196 200 temp->setOrientation(rootNode_->getOrientation()); … … 201 205 + StringConverter::toString(objectCounter_++), "Barrel.mesh"), currentSpeed_ 202 206 + (rootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy() 203 * bulletSpeed_); 207 * bulletSpeed_);*/ 208 209 mainWeapon_->primaryFireRequest(); 204 210 } 205 211 … … 214 220 bool OrxonoxShip::tick(unsigned long time, Real deltaTime) 215 221 { 222 mainWeapon_->tick(time, deltaTime); 223 216 224 Quaternion quad = rootNode_->getOrientation(); 217 225 quad.normalise(); 218 226 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 227 222 228 rootNode_->translate(currentSpeed_ * deltaTime); -
code/branches/main_reto_vs05/src/orxonox_ship.h
r169 r177 40 40 { 41 41 public: 42 OrxonoxShip(Ogre::SceneManager*, Ogre::SceneNode* );42 OrxonoxShip(Ogre::SceneManager*, Ogre::SceneNode*, BulletManager*); 43 43 virtual ~OrxonoxShip(); 44 44 … … 54 54 Ogre::Vector3 getSpeed(); 55 55 56 Bullet*fire();56 void fire(); 57 57 58 58 bool tick(unsigned long, Ogre::Real); … … 69 69 Ogre::Real baseThrust_; 70 70 int objectCounter_; 71 Ogre::Vector3 bulletSpeed_; 71 72 BulletManager *bulletManager_; 73 //Ogre::Vector3 bulletSpeed_; 72 74 73 75 WeaponManager *mainWeapon_; -
code/branches/main_reto_vs05/src/run_manager.cc
r169 r177 52 52 #include "orxonox_ship.h" 53 53 #include "bullet.h" 54 #include "bullet_manager.h" 54 55 #include "camera_manager.h" 56 #include "weapon_manager.h" 55 57 56 58 #include "run_manager.h" … … 97 99 // background scene (world objects, skybox, lights, etc.) 98 100 backgroundScene_ = new OrxonoxScene(sceneMgr_); 101 102 103 // BULLET LIST FOR THE TEST APPLICATION 104 105 // create a bullet manager 106 bulletManager_ = new BulletManager(sceneMgr_); 107 WeaponManager::loadWeapons(); 108 109 // TODO: Use STL to make life easier. But it works this way too.. 110 /*bullets_ = new Bullet*[10]; 111 bulletsIndex_ = 0; 112 bulletsSize_ = 10;*/ 113 99 114 100 115 // PLAYER SPACESHIP … … 114 129 // Construct a new spaceship and give it the node 115 130 playerShip_ = new OrxonoxShip(sceneMgr_, sceneMgr_->getRootSceneNode() 116 ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)) );131 ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)), bulletManager_); 117 132 118 133 … … 140 155 141 156 142 // BULLET LIST FOR THE TEST APPLICATION143 144 // TODO: Use STL to make life easier. But it works this way too..145 bullets_ = new Bullet*[10];146 bulletsIndex_ = 0;147 bulletsSize_ = 10;148 149 157 150 158 // HUMAN INTERFACE … … 205 213 if (playerShip_) 206 214 delete playerShip_; 215 if (bulletManager_) 216 delete bulletManager_; 217 218 WeaponManager::destroyWeapons(); 207 219 208 220 // clean up the bullet list 209 for (int i = 0; i < bulletsIndex_; i++)221 /*for (int i = 0; i < bulletsIndex_; i++) 210 222 delete bullets_[i]; 211 delete bullets_; 223 delete bullets_;*/ 212 224 } 213 225 … … 239 251 240 252 // update the bullet positions 241 for (int i = 0; i < bulletsIndex_; i++) 253 bulletManager_->tick(time, deltaTime); 254 255 /*for (int i = 0; i < bulletsIndex_; i++) 242 256 { 243 257 bullets_[i]->node_->translate(bullets_[i]->speed_*deltaTime); 244 258 bullets_[i]->node_->yaw(Degree(deltaTime*100)); 245 259 bullets_[i]->node_->roll(Degree(deltaTime*300)); 246 } 260 }*/ 247 261 248 262 // HUMAN INTERFACE … … 447 461 // Prevent continuous fire for the moment. 448 462 leftButtonDown_ = true; 463 464 playerShip_->fire(); 449 465 450 466 // let ship fire one shot with its only weapon (Barrels..) 451 Bullet *tempBullet = playerShip_->fire();467 /*Bullet *tempBullet = playerShip_->fire(); 452 468 453 469 // resize array if neccessary (double the size then) … … 464 480 465 481 // add the bullet to the list 466 bullets_[bulletsIndex_++] = tempBullet; 482 bullets_[bulletsIndex_++] = tempBullet;*/ 467 483 468 484 } -
code/branches/main_reto_vs05/src/run_manager.h
r169 r177 109 109 110 110 // Bullet array 111 Bullet **bullets_;111 /*Bullet **bullets_; 112 112 int bulletsSize_; 113 int bulletsIndex_; 113 int bulletsIndex_;*/ 114 BulletManager *bulletManager_; 114 115 115 116 // previously elapsed render time -
code/branches/main_reto_vs05/src/weapon.h
r169 r177 30 30 #define WEAPON_H 31 31 32 #include "OgrePrerequisites.h" 32 33 #include "OgreString.h" 33 34 … … 39 40 { 40 41 public: 41 Weapon(const Ogre::String &name, int firePower, int firingRate) 42 : name_(name), firePower_(firePower), firingRate_(firingRate) { } 42 Weapon(const Ogre::String &name, int firePower, int firingRate, 43 Ogre::Real bulletSpeed) 44 : name_(name), firePower_(firePower), firingRate_(firingRate), 45 bulletSpeed_(bulletSpeed) { } 46 43 47 virtual ~Weapon() { } 44 48 … … 47 51 int firePower_; 48 52 int firingRate_; 53 Ogre::Real bulletSpeed_; 49 54 }; 50 55 -
code/branches/main_reto_vs05/src/weapon_manager.cc
r169 r177 27 27 28 28 #include "OgreSceneManager.h" 29 #include "OgreEntity.h" 30 #include "OgreSceneNode.h" 31 #include "OgreVector3.h" 32 #include "OgreStringConverter.h" 29 33 30 34 #include "weapon.h" 35 #include "bullet.h" 36 #include "bullet_manager.h" 31 37 #include "weapon_manager.h" 38 39 #define ACTION_LIST_SIZE 4 32 40 33 41 … … 38 46 39 47 WeaponManager::WeaponManager(SceneManager *sceneMgr, SceneNode *node, 40 int slotSize) 41 : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0) 48 BulletManager *bulletManager, int slotSize) 49 : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0), 50 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 51 secondaryFireRequest_(false), selectedWeapon_(0), 52 bulletManager_(bulletManager), 53 actionListReadIndex_(0), actionListWriteIndex_(0) 42 54 { 43 55 slots_ = new Weapon*[slotSize]; 56 actionList_ = new Action[ACTION_LIST_SIZE]; 57 for (int i = 0; i < ACTION_LIST_SIZE; i++) 58 actionList_[i] = NOTHING; 44 59 } 45 60 … … 49 64 if (slots_) 50 65 delete slots_; 66 if (actionList_) 67 delete actionList_; 51 68 } 52 69 … … 54 71 bool WeaponManager::addWeapon(const Ogre::String &name) 55 72 { 73 if (!weaponList_s) 74 return false; 75 56 76 if (name == weaponList_s[0]->name_) 57 77 { 58 78 // this is ugly, but for the time being, it has to fit. 79 selectedWeapon_ = slotIndex_; 59 80 slots_[slotIndex_++] = weaponList_s[0]; 60 81 return true; … … 65 86 66 87 88 bool WeaponManager::addAction(const Action act) 89 { 90 if (actionList_[actionListWriteIndex_] == NOTHING) 91 { 92 actionList_[actionListWriteIndex_] = act; 93 actionListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE; 94 return true; 95 } 96 else 97 return false; 98 } 99 100 101 void WeaponManager::primaryFireRequest() 102 { 103 primaryFireRequest_ = true; 104 } 105 106 107 void WeaponManager::primaryFire() 108 { 109 currentState_ = PRIMARY_FIRE; 110 111 // TODO: add the name of the weapon manager. but for that, 112 // the factory is required. 113 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( 114 "BulletNode" + StringConverter::toString(bulletCounter_), 115 node_->getWorldPosition(), node_->getWorldOrientation()); 116 temp->setScale(Vector3(1, 1, 1) * 10); 117 temp->yaw(Degree(-90)); 118 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity" 119 + StringConverter::toString(bulletCounter_++), "Barrel.mesh"); 120 Vector3 speed = (node_->getOrientation() * Vector3(0, 0, -1)) 121 .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_; 122 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); 123 124 currentState_ = IDLE; 125 } 126 127 128 void WeaponManager::secondaryFireRequest() 129 { 130 secondaryFireRequest_ = true; 131 } 132 133 void WeaponManager::secondaryFire() 134 { 135 } 136 137 138 bool WeaponManager::tick(unsigned long time, Real deltaTime) 139 { 140 // return if no weapon has been added 141 if (!slots_[slotIndex_]) 142 return true; 143 144 switch (currentState_) 145 { 146 case IDLE: 147 // first, process actions 148 if (actionList_[actionListReadIndex_] != NOTHING) 149 { 150 actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE; 151 break; 152 } 153 154 switch (actionList_[actionListReadIndex_]) 155 { 156 case RELOAD: 157 break; 158 159 case ZOOM_IN: 160 break; 161 162 case ZOOM_OUT: 163 break; 164 165 default: 166 break; 167 } 168 169 // secondly, execute firing 170 if (primaryFireRequest_) 171 primaryFire(); 172 else if (secondaryFireRequest_) 173 secondaryFire(); 174 175 break; 176 177 case PRIMARY_FIRE: 178 break; 179 180 case SECONDARY_FIRE: 181 break; 182 183 case RELOADING: 184 break; 185 } 186 187 primaryFireRequest_ = false; 188 secondaryFireRequest_ = false; 189 190 return true; 191 } 192 193 67 194 // static 68 195 bool WeaponManager::loadWeapons() 69 196 { 70 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2); 197 weaponList_s = new Weapon*[5]; 198 for (int i = 0; i < 5; i++) 199 weaponList_s[i] = NULL; 200 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500); 71 201 return true; 72 202 } … … 76 206 void WeaponManager::destroyWeapons() 77 207 { 78 delete weaponList_s[0]; 208 if (weaponList_s) 209 { 210 for (int i = 0; i < 5; i++) 211 if (weaponList_s[i]) 212 delete weaponList_s[i]; 213 delete weaponList_s; 214 } 79 215 } 80 216 -
code/branches/main_reto_vs05/src/weapon_manager.h
r169 r177 40 40 { 41 41 public: 42 WeaponManager(Ogre::SceneManager*, Ogre::SceneNode*, int); 42 enum Action { 43 NOTHING = 0, 44 RELOAD = 1, 45 ZOOM_IN = 2, 46 ZOOM_OUT = 3 47 }; 48 49 protected: 50 enum State { 51 IDLE = 0, 52 PRIMARY_FIRE = 1, 53 SECONDARY_FIRE = 2, 54 RELOADING = 4 55 }; 56 57 public: 58 WeaponManager(Ogre::SceneManager*, Ogre::SceneNode*, BulletManager*, int); 43 59 virtual ~WeaponManager(); 44 60 45 61 bool addWeapon(const Ogre::String&); 46 62 63 bool addAction(const Action); 64 65 void primaryFireRequest(); 66 67 void secondaryFireRequest(); 68 69 bool tick(unsigned long, Ogre::Real); 70 47 71 bool static loadWeapons(); 48 72 49 73 void static destroyWeapons(); 74 75 protected: 76 void primaryFire(); 77 78 void secondaryFire(); 79 80 public: 50 81 51 82 protected: … … 56 87 int slotSize_; 57 88 int slotIndex_; 89 int selectedWeapon_; 90 91 int bulletCounter_; 92 BulletManager *bulletManager_; 93 94 bool primaryFireRequest_; 95 bool secondaryFireRequest_; 96 97 State currentState_; 98 99 Action *actionList_; 100 int actionListReadIndex_; 101 int actionListWriteIndex_; 58 102 59 103 static Weapon **weaponList_s;
Note: See TracChangeset
for help on using the changeset viewer.