| [637] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
| [1056] | 3 |  *                    > www.orxonox.net < | 
|---|
| [637] | 4 |  * | 
|---|
 | 5 |  * | 
|---|
 | 6 |  *   License notice: | 
|---|
 | 7 |  * | 
|---|
 | 8 |  *   This program is free software; you can redistribute it and/or | 
|---|
 | 9 |  *   modify it under the terms of the GNU General Public License | 
|---|
 | 10 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
 | 11 |  *   of the License, or (at your option) any later version. | 
|---|
 | 12 |  * | 
|---|
 | 13 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 14 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 15 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 16 |  *   GNU General Public License for more details. | 
|---|
 | 17 |  * | 
|---|
 | 18 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 19 |  *   along with this program; if not, write to the Free Software | 
|---|
 | 20 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
 | 21 |  * | 
|---|
 | 22 |  *   Author: | 
|---|
 | 23 |  *      ... | 
|---|
 | 24 |  *   Co-authors: | 
|---|
 | 25 |  *      ... | 
|---|
 | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
| [786] | 29 | #include "OrxonoxStableHeaders.h" | 
|---|
| [784] | 30 |  | 
|---|
| [715] | 31 | #include <string> | 
|---|
 | 32 |  | 
|---|
| [708] | 33 | #include <OgreCamera.h> | 
|---|
 | 34 | #include <OgreRenderWindow.h> | 
|---|
 | 35 | #include <OgreSceneManager.h> | 
|---|
 | 36 | #include <OgreSceneNode.h> | 
|---|
| [637] | 37 |  | 
|---|
| [742] | 38 | #include "util/tinyxml/tinyxml.h" | 
|---|
 | 39 | #include "util/String2Number.h" | 
|---|
| [1021] | 40 | #include "core/CoreIncludes.h" | 
|---|
| [1052] | 41 | #include "core/ConfigValueIncludes.h" | 
|---|
| [1032] | 42 | #include "GraphicsEngine.h" | 
|---|
| [1024] | 43 | #include "core/InputManager.h" | 
|---|
| [1021] | 44 | #include "particle/ParticleInterface.h" | 
|---|
| [768] | 45 | #include "weapon/AmmunitionDump.h" | 
|---|
 | 46 | #include "weapon/BarrelGun.h" | 
|---|
| [637] | 47 |  | 
|---|
| [708] | 48 | #include "Fighter.h" | 
|---|
| [637] | 49 |  | 
|---|
 | 50 | namespace orxonox | 
|---|
 | 51 | { | 
|---|
 | 52 |     CreateFactory(Fighter); | 
|---|
 | 53 |  | 
|---|
 | 54 |     Fighter::Fighter() | 
|---|
 | 55 |     { | 
|---|
 | 56 |         RegisterObject(Fighter); | 
|---|
 | 57 |  | 
|---|
| [697] | 58 |         this->setConfigValues(); | 
|---|
| [637] | 59 |  | 
|---|
 | 60 |         this->setMouseEventCallback_ = false; | 
|---|
 | 61 |  | 
|---|
 | 62 |         this->w = NULL; | 
|---|
 | 63 |         this->tt = NULL; | 
|---|
 | 64 |         this->ammoDump_ = NULL; | 
|---|
 | 65 |         this->mainWeapon_ = NULL; | 
|---|
| [645] | 66 |         this->rightButtonPressed_ = false; | 
|---|
 | 67 |         this->leftButtonPressed_ = false; | 
|---|
| [637] | 68 |  | 
|---|
 | 69 |         this->moveForward_ = 0; | 
|---|
 | 70 |         this->rotateUp_ = 0; | 
|---|
 | 71 |         this->rotateDown_ = 0; | 
|---|
 | 72 |         this->rotateRight_ = 0; | 
|---|
 | 73 |         this->rotateLeft_ = 0; | 
|---|
 | 74 |         this->loopRight_ = 0; | 
|---|
 | 75 |         this->loopLeft_ = 0; | 
|---|
 | 76 |         this->brakeForward_ = 0; | 
|---|
 | 77 |         this->brakeRotate_ = 0; | 
|---|
 | 78 |         this->brakeLoop_ = 0; | 
|---|
 | 79 |         this->speedForward_ = 0; | 
|---|
 | 80 |         this->speedRotateUpDown_ = 0; | 
|---|
 | 81 |         this->speedRotateRightLeft_ = 0; | 
|---|
 | 82 |         this->speedLoopRightLeft_ = 0; | 
|---|
 | 83 |         this->maxSpeedForward_ = 0; | 
|---|
 | 84 |         this->maxSpeedRotateUpDown_ = 0; | 
|---|
 | 85 |         this->maxSpeedRotateRightLeft_ = 0; | 
|---|
 | 86 |         this->maxSpeedLoopRightLeft_ = 0; | 
|---|
 | 87 |         this->accelerationForward_ = 0; | 
|---|
 | 88 |         this->accelerationRotateUpDown_ = 0; | 
|---|
 | 89 |         this->accelerationRotateRightLeft_ = 0; | 
|---|
 | 90 |         this->accelerationLoopRightLeft_ = 0; | 
|---|
 | 91 |  | 
|---|
 | 92 |         this->speed = 250; | 
|---|
 | 93 |         this->loop = 100; | 
|---|
 | 94 |         this->rotate = 10; | 
|---|
 | 95 |         this->mouseX = 0; | 
|---|
 | 96 |         this->mouseY = 0; | 
|---|
 | 97 |         this->maxMouseX = 0; | 
|---|
 | 98 |         this->minMouseX = 0; | 
|---|
 | 99 |         this->moved = false; | 
|---|
 | 100 |  | 
|---|
 | 101 |         this->brakeRotate(rotate*10); | 
|---|
 | 102 |         this->brakeLoop(loop); | 
|---|
 | 103 |  | 
|---|
 | 104 |         COUT(3) << "Info: Fighter was loaded" << std::endl; | 
|---|
 | 105 |     } | 
|---|
 | 106 |  | 
|---|
 | 107 |     Fighter::~Fighter() | 
|---|
 | 108 |     { | 
|---|
 | 109 |         if (w) | 
|---|
 | 110 |             delete w; | 
|---|
 | 111 |         if (tt) | 
|---|
 | 112 |             delete tt; | 
|---|
 | 113 |     } | 
|---|
 | 114 |  | 
|---|
| [697] | 115 |     void Fighter::setConfigValues() | 
|---|
 | 116 |     { | 
|---|
| [706] | 117 |         SetConfigValue(bInvertMouse_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); | 
|---|
| [697] | 118 |     } | 
|---|
 | 119 |  | 
|---|
| [637] | 120 |     void Fighter::setMaxSpeedValues(float maxSpeedForward, float maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float maxSpeedLoopRightLeft) | 
|---|
 | 121 |     { | 
|---|
 | 122 |         this->maxSpeedForward_ = maxSpeedForward; | 
|---|
 | 123 |         this->maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; | 
|---|
 | 124 |         this->maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; | 
|---|
 | 125 |         this->maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; | 
|---|
 | 126 |     } | 
|---|
 | 127 |  | 
|---|
 | 128 |     void Fighter::loadParams(TiXmlElement* xmlElem) | 
|---|
 | 129 |     { | 
|---|
 | 130 |         Model::loadParams(xmlElem); | 
|---|
 | 131 |  | 
|---|
| [645] | 132 | #if 0 | 
|---|
| [1032] | 133 |         w = new particle::ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"schuss" + this->getName(),"Orxonox/schuss"); | 
|---|
| [637] | 134 |         w->getParticleSystem()->setParameter("local_space","true"); | 
|---|
 | 135 |         w->newEmitter(); | 
|---|
 | 136 | /* | 
|---|
 | 137 |         w->setDirection(Vector3(0,0,1)); | 
|---|
 | 138 |         w->setPositionOfEmitter(0, Vector3(10,10,0)); | 
|---|
 | 139 |         w->setPositionOfEmitter(1, Vector3(-10,10,0)); | 
|---|
 | 140 | */ | 
|---|
 | 141 |         w->setDirection(Vector3(1,0,0)); | 
|---|
 | 142 |         w->setPositionOfEmitter(0, Vector3(0,10,10)); | 
|---|
 | 143 |         w->setPositionOfEmitter(1, Vector3(0,-10,10)); | 
|---|
 | 144 |  | 
|---|
 | 145 |         emitterRate_ = w->getRate(); | 
|---|
 | 146 |  | 
|---|
 | 147 |         Ogre::SceneNode* node1 = this->getNode()->createChildSceneNode(this->getName() + "particle1"); | 
|---|
 | 148 |         node1->setInheritScale(false); | 
|---|
 | 149 |         w->addToSceneNode(node1); | 
|---|
| [645] | 150 | #endif | 
|---|
| [637] | 151 |  | 
|---|
| [1032] | 152 |         tt = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); | 
|---|
| [637] | 153 |         tt->getParticleSystem()->setParameter("local_space","true"); | 
|---|
 | 154 |         tt->newEmitter(); | 
|---|
 | 155 | /* | 
|---|
 | 156 |         tt->setDirection(Vector3(0,0,1)); | 
|---|
 | 157 |         tt->setPositionOfEmitter(0, Vector3(20,-1,-15)); | 
|---|
 | 158 |         tt->setPositionOfEmitter(1, Vector3(-20,-1,-15)); | 
|---|
 | 159 | */ | 
|---|
 | 160 |         tt->setDirection(Vector3(-1,0,0)); | 
|---|
 | 161 |         tt->setPositionOfEmitter(0, Vector3(-15,20,-1)); | 
|---|
 | 162 |         tt->setPositionOfEmitter(1, Vector3(-15,-20,-1)); | 
|---|
 | 163 |         tt->setVelocity(50); | 
|---|
 | 164 |  | 
|---|
 | 165 |         Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); | 
|---|
 | 166 |         node2->setInheritScale(false); | 
|---|
 | 167 |         tt->addToSceneNode(node2); | 
|---|
 | 168 |  | 
|---|
 | 169 |         // add weapon | 
|---|
 | 170 |  | 
|---|
 | 171 |         ammoDump_ = new AmmunitionDump(); | 
|---|
 | 172 |         ammoDump_->setDumpSize("Barrel", 1000); | 
|---|
 | 173 |         ammoDump_->store("Barrel", 420); | 
|---|
 | 174 |  | 
|---|
 | 175 |         mainWeapon_ = new BarrelGun(); | 
|---|
 | 176 |         mainWeapon_->setAmmoDump(ammoDump_); | 
|---|
| [1032] | 177 |         GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeChild(mainWeapon_->getNode()); | 
|---|
| [645] | 178 |         getNode()->addChild(mainWeapon_->getNode()); | 
|---|
| [637] | 179 |  | 
|---|
 | 180 |         if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) | 
|---|
 | 181 |         { | 
|---|
| [715] | 182 |             std::string forwardStr = xmlElem->Attribute("forward"); | 
|---|
 | 183 |             std::string rotateupdownStr = xmlElem->Attribute("rotateupdown"); | 
|---|
 | 184 |             std::string rotaterightleftStr = xmlElem->Attribute("rotaterightleft"); | 
|---|
 | 185 |             std::string looprightleftStr = xmlElem->Attribute("looprightleft"); | 
|---|
| [637] | 186 |  | 
|---|
 | 187 |             String2Number<float>(this->maxSpeedForward_, forwardStr); | 
|---|
 | 188 |             String2Number<float>(this->maxSpeedRotateUpDown_, rotateupdownStr); | 
|---|
 | 189 |             String2Number<float>(this->maxSpeedRotateRightLeft_, rotaterightleftStr); | 
|---|
 | 190 |             String2Number<float>(this->maxSpeedLoopRightLeft_, looprightleftStr); | 
|---|
 | 191 |  | 
|---|
 | 192 |             COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl; | 
|---|
 | 193 |         } | 
|---|
 | 194 |  | 
|---|
 | 195 |         if (xmlElem->Attribute("camera")) | 
|---|
 | 196 |         { | 
|---|
| [1032] | 197 |             Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam"); | 
|---|
| [637] | 198 |             Ogre::SceneNode *node = this->getNode()->createChildSceneNode("CamNode"); | 
|---|
 | 199 | /* | 
|---|
 | 200 | //            node->setInheritOrientation(false); | 
|---|
 | 201 |             cam->setPosition(Vector3(0,50,-150)); | 
|---|
 | 202 |             cam->lookAt(Vector3(0,20,0)); | 
|---|
 | 203 |             cam->roll(Degree(0)); | 
|---|
 | 204 | */ | 
|---|
 | 205 |  | 
|---|
 | 206 |             cam->setPosition(Vector3(-150,0,50)); | 
|---|
 | 207 | //            cam->setPosition(Vector3(0,-350,0)); | 
|---|
 | 208 |             cam->lookAt(Vector3(0,0,20)); | 
|---|
 | 209 |             cam->roll(Degree(-90)); | 
|---|
 | 210 |  | 
|---|
 | 211 |             node->attachObject(cam); | 
|---|
| [1032] | 212 |             GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); | 
|---|
| [637] | 213 |         } | 
|---|
 | 214 |     } | 
|---|
 | 215 |  | 
|---|
 | 216 |     bool Fighter::mouseMoved(const OIS::MouseEvent &e) | 
|---|
 | 217 |     { | 
|---|
 | 218 |         this->mouseX += e.state.X.rel; | 
|---|
| [650] | 219 |         //if (this->bInvertMouse_) | 
|---|
 | 220 |             //this->mouseY += e.state.Y.rel; | 
|---|
 | 221 |         //else | 
|---|
| [637] | 222 |             this->mouseY -= e.state.Y.rel; | 
|---|
 | 223 |  | 
|---|
 | 224 | //        if(mouseX>maxMouseX) maxMouseX = mouseX; | 
|---|
 | 225 | //        if(mouseX<minMouseX) minMouseX = mouseX; | 
|---|
 | 226 | //        cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; | 
|---|
 | 227 |  | 
|---|
 | 228 |         this->moved = true; | 
|---|
 | 229 |  | 
|---|
 | 230 |         return true; | 
|---|
 | 231 |     } | 
|---|
 | 232 |  | 
|---|
 | 233 |     bool Fighter::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id ) | 
|---|
 | 234 |     { | 
|---|
| [645] | 235 |       if (id == OIS::MB_Left) | 
|---|
 | 236 |       { | 
|---|
 | 237 |         this->leftButtonPressed_ = true; | 
|---|
 | 238 |       } | 
|---|
 | 239 |       else if (id == OIS::MB_Right) | 
|---|
 | 240 |         this->rightButtonPressed_ = true; | 
|---|
 | 241 |       return true; | 
|---|
 | 242 |     } | 
|---|
| [637] | 243 |  | 
|---|
| [645] | 244 |     bool Fighter::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id ) | 
|---|
 | 245 |     { | 
|---|
 | 246 |       if (id == OIS::MB_Left) | 
|---|
 | 247 |       { | 
|---|
 | 248 |         this->leftButtonPressed_ = false; | 
|---|
 | 249 |       } | 
|---|
 | 250 |       else if (id == OIS::MB_Right) | 
|---|
 | 251 |         this->rightButtonPressed_ = false; | 
|---|
| [637] | 252 |       return true; | 
|---|
 | 253 |     } | 
|---|
 | 254 |  | 
|---|
 | 255 |     void Fighter::tick(float dt) | 
|---|
 | 256 |     { | 
|---|
 | 257 |         if (!this->setMouseEventCallback_) | 
|---|
 | 258 |         { | 
|---|
| [1024] | 259 |             if (InputManager::getSingleton()->getMouse()) | 
|---|
| [637] | 260 |             { | 
|---|
| [1024] | 261 |                 InputManager::getSingleton()->getMouse()->setEventCallback(this); | 
|---|
| [637] | 262 |                 this->setMouseEventCallback_ = true; | 
|---|
 | 263 |             } | 
|---|
 | 264 |         } | 
|---|
 | 265 |  | 
|---|
 | 266 |         WorldEntity::tick(dt); | 
|---|
 | 267 |  | 
|---|
| [1024] | 268 |         OIS::Keyboard* mKeyboard = InputManager::getSingleton()->getKeyboard(); | 
|---|
 | 269 |         OIS::Mouse* mMouse = InputManager::getSingleton()->getMouse(); | 
|---|
| [637] | 270 |  | 
|---|
| [1024] | 271 |         //mKeyboard->capture(); | 
|---|
 | 272 |         //mMouse->capture(); | 
|---|
| [637] | 273 |  | 
|---|
| [645] | 274 |         if (leftButtonPressed_) | 
|---|
 | 275 |             mainWeapon_->primaryFireRequest(); | 
|---|
 | 276 |         if (rightButtonPressed_) | 
|---|
 | 277 |             mainWeapon_->secondaryFireRequest(); | 
|---|
 | 278 |  | 
|---|
| [637] | 279 |         if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) | 
|---|
 | 280 |             this->moveForward(speed); | 
|---|
 | 281 |         else | 
|---|
 | 282 |             this->moveForward(0); | 
|---|
 | 283 |  | 
|---|
 | 284 |         if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) | 
|---|
 | 285 |             this->brakeForward(speed); | 
|---|
 | 286 |         else | 
|---|
 | 287 |             this->brakeForward(speed/10); | 
|---|
 | 288 |  | 
|---|
 | 289 |         if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) | 
|---|
 | 290 |             this->loopRight(loop); | 
|---|
 | 291 |         else | 
|---|
 | 292 |             this->loopRight(0); | 
|---|
 | 293 |  | 
|---|
 | 294 |         if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) | 
|---|
 | 295 |             this->loopLeft(loop); | 
|---|
 | 296 |         else | 
|---|
 | 297 |             this->loopLeft(0); | 
|---|
 | 298 |  | 
|---|
| [645] | 299 |         if (mKeyboard->isKeyDown(OIS::KC_G)) | 
|---|
 | 300 |             this->mainWeapon_->addAction(BaseWeapon::RELOAD); | 
|---|
 | 301 |         else | 
|---|
 | 302 |             this->loopLeft(0); | 
|---|
 | 303 |  | 
|---|
| [637] | 304 |         if(moved) | 
|---|
 | 305 |         { | 
|---|
 | 306 |             if (mouseY<=0) | 
|---|
 | 307 |                 this->rotateUp(-mouseY*rotate); | 
|---|
 | 308 |             if (mouseY>0) | 
|---|
 | 309 |                 this->rotateDown(mouseY*rotate); | 
|---|
 | 310 |             if (mouseX>0) | 
|---|
 | 311 |                 this->rotateRight(mouseX*rotate); | 
|---|
 | 312 |             if (mouseX<=0) | 
|---|
 | 313 |                 this->rotateLeft(-mouseX*rotate); | 
|---|
 | 314 |  | 
|---|
 | 315 |             mouseY = 0; | 
|---|
 | 316 |             mouseX = 0; | 
|---|
 | 317 |             moved = false; | 
|---|
 | 318 |         } | 
|---|
 | 319 |         else | 
|---|
 | 320 |         { | 
|---|
 | 321 |             this->rotateUp(0); | 
|---|
 | 322 |             this->rotateDown(0); | 
|---|
 | 323 |             this->rotateRight(0); | 
|---|
 | 324 |             this->rotateLeft(0); | 
|---|
 | 325 |         } | 
|---|
 | 326 |  | 
|---|
 | 327 |         if(moveForward_ > 0) | 
|---|
 | 328 |         { | 
|---|
 | 329 |             accelerationForward_ = moveForward_; | 
|---|
 | 330 |             if(speedForward_ < maxSpeedForward_) | 
|---|
 | 331 |                 speedForward_ += accelerationForward_*dt; | 
|---|
 | 332 |             if(speedForward_ > maxSpeedForward_) | 
|---|
 | 333 |                 speedForward_ = maxSpeedForward_; | 
|---|
 | 334 |         } | 
|---|
 | 335 |  | 
|---|
 | 336 |         if(moveForward_ <= 0) | 
|---|
 | 337 |         { | 
|---|
 | 338 |             accelerationForward_ = -brakeForward_; | 
|---|
 | 339 |             if(speedForward_ > 0) | 
|---|
 | 340 |                 speedForward_ += accelerationForward_*dt; | 
|---|
 | 341 |             if(speedForward_ < 0) | 
|---|
 | 342 |                 speedForward_ = 0; | 
|---|
 | 343 |         } | 
|---|
 | 344 |  | 
|---|
 | 345 |         if(rotateUp_ > 0) | 
|---|
 | 346 |         { | 
|---|
 | 347 |             accelerationRotateUpDown_ = rotateUp_; | 
|---|
 | 348 |             if(speedRotateUpDown_ < maxSpeedRotateUpDown_) | 
|---|
 | 349 |                 speedRotateUpDown_ += accelerationRotateUpDown_*dt; | 
|---|
 | 350 |             if(speedRotateUpDown_ > maxSpeedRotateUpDown_) | 
|---|
 | 351 |             speedRotateUpDown_ = maxSpeedRotateUpDown_; | 
|---|
 | 352 |         } | 
|---|
 | 353 |  | 
|---|
 | 354 |         if(rotateDown_ > 0) | 
|---|
 | 355 |         { | 
|---|
 | 356 |             accelerationRotateUpDown_ = rotateDown_; | 
|---|
 | 357 |             if(speedRotateUpDown_ > -maxSpeedRotateUpDown_) | 
|---|
 | 358 |                 speedRotateUpDown_ -= accelerationRotateUpDown_*dt; | 
|---|
 | 359 |             if(speedRotateUpDown_ < -maxSpeedRotateUpDown_) | 
|---|
 | 360 |                 speedRotateUpDown_ = -maxSpeedRotateUpDown_; | 
|---|
 | 361 |         } | 
|---|
 | 362 |  | 
|---|
 | 363 |         if(rotateUp_ == 0 && rotateDown_ == 0) | 
|---|
 | 364 |         { | 
|---|
 | 365 |             accelerationRotateUpDown_ = brakeRotate_; | 
|---|
 | 366 |             if(speedRotateUpDown_ > 0) | 
|---|
 | 367 |                 speedRotateUpDown_ -= accelerationRotateUpDown_*dt; | 
|---|
 | 368 |             if(speedRotateUpDown_ < 0) | 
|---|
 | 369 |                 speedRotateUpDown_ += accelerationRotateUpDown_*dt; | 
|---|
 | 370 |             if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt) | 
|---|
 | 371 |                 speedRotateUpDown_ = 0; | 
|---|
 | 372 |         } | 
|---|
 | 373 |  | 
|---|
 | 374 |         if(rotateRight_ > 0) | 
|---|
 | 375 |         { | 
|---|
 | 376 |             accelerationRotateRightLeft_ = rotateRight_; | 
|---|
 | 377 |             if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_) | 
|---|
 | 378 |                 speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt; | 
|---|
 | 379 |             if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_) | 
|---|
 | 380 |                 speedRotateRightLeft_ = -maxSpeedRotateRightLeft_; | 
|---|
 | 381 |         } | 
|---|
 | 382 |  | 
|---|
 | 383 |         if(rotateLeft_ > 0) | 
|---|
 | 384 |         { | 
|---|
 | 385 |             accelerationRotateRightLeft_ = rotateLeft_; | 
|---|
 | 386 |             if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_) | 
|---|
 | 387 |                 speedRotateRightLeft_ += accelerationRotateRightLeft_*dt; | 
|---|
 | 388 |             if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_) | 
|---|
 | 389 |                 speedRotateRightLeft_ = maxSpeedRotateRightLeft_; | 
|---|
 | 390 |         } | 
|---|
 | 391 |  | 
|---|
 | 392 |         if(rotateRight_ == 0 && rotateLeft_ == 0) | 
|---|
 | 393 |         { | 
|---|
 | 394 |             accelerationRotateRightLeft_ = brakeRotate_; | 
|---|
 | 395 |             if(speedRotateRightLeft_ > 0) | 
|---|
 | 396 |                 speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt; | 
|---|
 | 397 |             if(speedRotateRightLeft_ < 0) | 
|---|
 | 398 |                 speedRotateRightLeft_ += accelerationRotateRightLeft_*dt; | 
|---|
 | 399 |             if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt) | 
|---|
 | 400 |                 speedRotateRightLeft_ = 0; | 
|---|
 | 401 |         } | 
|---|
 | 402 |  | 
|---|
 | 403 |         if(loopRight_ > 0) | 
|---|
 | 404 |         { | 
|---|
 | 405 |             accelerationLoopRightLeft_ = loopRight_; | 
|---|
 | 406 |             if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_) | 
|---|
 | 407 |                 speedLoopRightLeft_ += accelerationLoopRightLeft_*dt; | 
|---|
 | 408 |             if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_) | 
|---|
 | 409 |                 speedLoopRightLeft_ = maxSpeedLoopRightLeft_; | 
|---|
 | 410 |         } | 
|---|
 | 411 |  | 
|---|
 | 412 |         if(loopLeft_ > 0) | 
|---|
 | 413 |         { | 
|---|
 | 414 |             accelerationLoopRightLeft_ = loopLeft_; | 
|---|
 | 415 |             if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_) | 
|---|
 | 416 |                 speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt; | 
|---|
 | 417 |             if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_) | 
|---|
 | 418 |                 speedLoopRightLeft_ = -maxSpeedLoopRightLeft_; | 
|---|
 | 419 |         } | 
|---|
 | 420 |  | 
|---|
 | 421 |         if(loopLeft_ == 0 && loopRight_ == 0) | 
|---|
 | 422 |         { | 
|---|
 | 423 |             accelerationLoopRightLeft_ = brakeLoop_; | 
|---|
 | 424 |             if(speedLoopRightLeft_ > 0) | 
|---|
 | 425 |                 speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt; | 
|---|
 | 426 |             if(speedLoopRightLeft_ < 0) | 
|---|
 | 427 |                 speedLoopRightLeft_ += accelerationLoopRightLeft_*dt; | 
|---|
 | 428 |             if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt) | 
|---|
 | 429 |                 speedLoopRightLeft_ = 0; | 
|---|
 | 430 |         } | 
|---|
 | 431 |  | 
|---|
 | 432 |         Vector3 transVector = Vector3::ZERO; | 
|---|
 | 433 | /* | 
|---|
 | 434 |         transVector.z = 1; | 
|---|
 | 435 |         this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); | 
|---|
 | 436 |         this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL); | 
|---|
 | 437 |         this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); | 
|---|
 | 438 |         this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); | 
|---|
 | 439 | */ | 
|---|
 | 440 |  | 
|---|
 | 441 |         transVector.x = 1; | 
|---|
 | 442 |         this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); | 
|---|
 | 443 |         this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL); | 
|---|
 | 444 |         this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); | 
|---|
 | 445 |         this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); | 
|---|
 | 446 |  | 
|---|
 | 447 |         if (accelerationForward_ > 25.0) | 
|---|
 | 448 |         { | 
|---|
 | 449 |           this->tt->setRate(emitterRate_); | 
|---|
 | 450 |         } | 
|---|
 | 451 |         else | 
|---|
 | 452 |         { | 
|---|
 | 453 |           this->tt->setRate(0); | 
|---|
 | 454 |         } | 
|---|
 | 455 |  | 
|---|
 | 456 |     } | 
|---|
 | 457 |  | 
|---|
 | 458 |     void Fighter::moveForward(float moveForward) { | 
|---|
 | 459 |         moveForward_ = moveForward; | 
|---|
 | 460 |     } | 
|---|
 | 461 |  | 
|---|
 | 462 |     void Fighter::rotateUp(float rotateUp) { | 
|---|
 | 463 |         rotateUp_ = rotateUp; | 
|---|
 | 464 |     } | 
|---|
 | 465 |  | 
|---|
 | 466 |     void Fighter::rotateDown(float rotateDown) { | 
|---|
 | 467 |         rotateDown_ = rotateDown; | 
|---|
 | 468 |     } | 
|---|
 | 469 |  | 
|---|
 | 470 |     void Fighter::rotateLeft(float rotateLeft) { | 
|---|
 | 471 |         rotateLeft_ = rotateLeft; | 
|---|
 | 472 |     } | 
|---|
 | 473 |  | 
|---|
 | 474 |     void Fighter::rotateRight(float rotateRight) { | 
|---|
 | 475 |         rotateRight_ = rotateRight; | 
|---|
 | 476 |     } | 
|---|
 | 477 |  | 
|---|
 | 478 |     void Fighter::loopLeft(float loopLeft) { | 
|---|
 | 479 |         loopLeft_ = loopLeft; | 
|---|
 | 480 |     } | 
|---|
 | 481 |  | 
|---|
 | 482 |     void Fighter::loopRight(float loopRight) { | 
|---|
 | 483 |         loopRight_ = loopRight; | 
|---|
 | 484 |     } | 
|---|
 | 485 |  | 
|---|
 | 486 |     void Fighter::brakeForward(float brakeForward) { | 
|---|
 | 487 |         brakeForward_ = brakeForward; | 
|---|
 | 488 |     } | 
|---|
 | 489 |  | 
|---|
 | 490 |     void Fighter::brakeRotate(float brakeRotate) { | 
|---|
 | 491 |         brakeRotate_ = brakeRotate; | 
|---|
 | 492 |     } | 
|---|
 | 493 |  | 
|---|
 | 494 |     void Fighter::brakeLoop(float brakeLoop) { | 
|---|
 | 495 |         brakeLoop_ = brakeLoop; | 
|---|
 | 496 |     } | 
|---|
 | 497 |  | 
|---|
 | 498 |     void Fighter::maxSpeedForward(float maxSpeedForward) { | 
|---|
 | 499 |         maxSpeedForward_ = maxSpeedForward; | 
|---|
 | 500 |     } | 
|---|
 | 501 |  | 
|---|
 | 502 |     void Fighter::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) { | 
|---|
 | 503 |         maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; | 
|---|
 | 504 |     } | 
|---|
 | 505 |  | 
|---|
 | 506 |     void Fighter::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) { | 
|---|
 | 507 |         maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; | 
|---|
 | 508 |     } | 
|---|
 | 509 |  | 
|---|
 | 510 |     void Fighter::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) { | 
|---|
 | 511 |         maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; | 
|---|
 | 512 |     } | 
|---|
 | 513 | } | 
|---|