| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 4 |    Copyright (C) 2004 orx | 
|---|
| 5 |  | 
|---|
| 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 7 |    it under the terms of the GNU General Public License as published by | 
|---|
| 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 9 |    any later version. | 
|---|
| 10 |  | 
|---|
| 11 | ### File Specific: | 
|---|
| 12 |    main-programmer: Benjamin Grauer | 
|---|
| 13 |    co-programmer: ... | 
|---|
| 14 |  | 
|---|
| 15 | */ | 
|---|
| 16 |  | 
|---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY | 
|---|
| 18 |  | 
|---|
| 19 | #include "turbine_hover.h" | 
|---|
| 20 |  | 
|---|
| 21 | #include "weapons/weapon_manager.h" | 
|---|
| 22 | #include "weapons/test_gun.h" | 
|---|
| 23 | #include "weapons/turret.h" | 
|---|
| 24 | #include "weapons/cannon.h" | 
|---|
| 25 |  | 
|---|
| 26 | #include "util/loading/factory.h" | 
|---|
| 27 | #include "key_mapper.h" | 
|---|
| 28 | #include "state.h" | 
|---|
| 29 |  | 
|---|
| 30 | #include "graphics_engine.h" | 
|---|
| 31 | #include "dot_emitter.h" | 
|---|
| 32 | #include "sprite_particles.h" | 
|---|
| 33 |  | 
|---|
| 34 | #include "debug.h" | 
|---|
| 35 |  | 
|---|
| 36 | CREATE_FACTORY(TurbineHover, CL_TURBINE_HOVER); | 
|---|
| 37 |  | 
|---|
| 38 | /** | 
|---|
| 39 |  *  destructs the turbine_hover, deletes alocated memory | 
|---|
| 40 |  */ | 
|---|
| 41 | TurbineHover::~TurbineHover () | 
|---|
| 42 | { | 
|---|
| 43 |   this->setPlayer(NULL); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | /** | 
|---|
| 47 |  * @brief loads a TurbineHover information from a specified file. | 
|---|
| 48 |  * @param fileName the name of the File to load the turbine_hover from (absolute path) | 
|---|
| 49 |  */ | 
|---|
| 50 | TurbineHover::TurbineHover(const std::string& fileName) | 
|---|
| 51 | { | 
|---|
| 52 |   this->init(); | 
|---|
| 53 |   TiXmlDocument doc(fileName); | 
|---|
| 54 |  | 
|---|
| 55 |   if(!doc.LoadFile()) | 
|---|
| 56 |   { | 
|---|
| 57 |     PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName.c_str()); | 
|---|
| 58 |     return; | 
|---|
| 59 |   } | 
|---|
| 60 |  | 
|---|
| 61 |   this->loadParams(doc.RootElement()); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | /** | 
|---|
| 65 |  * @brief creates a new Spaceship from Xml Data | 
|---|
| 66 |  * @param root the xml element containing spaceship data | 
|---|
| 67 |  | 
|---|
| 68 |    @todo add more parameters to load | 
|---|
| 69 | */ | 
|---|
| 70 | TurbineHover::TurbineHover(const TiXmlElement* root) | 
|---|
| 71 | { | 
|---|
| 72 |   this->init(); | 
|---|
| 73 |   if (root != NULL) | 
|---|
| 74 |     this->loadParams(root); | 
|---|
| 75 |  | 
|---|
| 76 |   //weapons: | 
|---|
| 77 |   Weapon* wpRight = new TestGun(0); | 
|---|
| 78 |   wpRight->setName("testGun Right"); | 
|---|
| 79 |   Weapon* wpLeft = new TestGun(1); | 
|---|
| 80 |   wpLeft->setName("testGun Left"); | 
|---|
| 81 |   //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_HYPERBLASTER)); | 
|---|
| 82 |  | 
|---|
| 83 |   //  cannon->setName("BFG"); | 
|---|
| 84 |  | 
|---|
| 85 |   this->addWeapon(wpLeft, 1, 0); | 
|---|
| 86 |   this->addWeapon(wpRight,1 ,1); | 
|---|
| 87 |   //this->addWeapon(cannon, 0, 2); | 
|---|
| 88 |  | 
|---|
| 89 |   this->getWeaponManager().changeWeaponConfig(1); | 
|---|
| 90 |   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); | 
|---|
| 91 |  | 
|---|
| 92 |   this->loadModel("models/ships/hoverglider_mainbody.obj"); | 
|---|
| 93 |  | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | /** | 
|---|
| 98 |  * @brief initializes a TurbineHover | 
|---|
| 99 |  */ | 
|---|
| 100 | void TurbineHover::init() | 
|---|
| 101 | { | 
|---|
| 102 |   //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); | 
|---|
| 103 |   this->setClassID(CL_TURBINE_HOVER, "TurbineHover"); | 
|---|
| 104 |  | 
|---|
| 105 |   this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal | Playable::Vertical); | 
|---|
| 106 |  | 
|---|
| 107 |   this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3); | 
|---|
| 108 |   this->loadModel("models/ships/hoverglider_turbine.obj", 1.0f, 4); | 
|---|
| 109 |   this->loadModel("models/ships/hoverglider_turbine_rotors.obj", 1.0f, 5); | 
|---|
| 110 |  | 
|---|
| 111 |   bForward = bBackward = bLeft = bRight = bAscend = bDescend = false; | 
|---|
| 112 |   mouseSensitivity = 0.005; | 
|---|
| 113 |  | 
|---|
| 114 |   this->rotorSpeed = 1000.0f; | 
|---|
| 115 |   this->rotorCycle = 0.0f; | 
|---|
| 116 |   this->cameraLook = 0.0f; | 
|---|
| 117 |   this->rotation = 0.0f; | 
|---|
| 118 |   this->acceleration = 10.0f; | 
|---|
| 119 |   this->airFriction = 2.0f; | 
|---|
| 120 |  | 
|---|
| 121 |   this->setHealthMax(100); | 
|---|
| 122 |   this->setHealth(100); | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 |   // camera - issue | 
|---|
| 126 |   this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); | 
|---|
| 127 |   this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); | 
|---|
| 128 |   //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); | 
|---|
| 129 |   this->cameraNode.setParent(this); | 
|---|
| 130 |   this->cameraNode.setRelCoor(0,5,0); | 
|---|
| 131 |  | 
|---|
| 132 |   // rotors | 
|---|
| 133 |   this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT ); | 
|---|
| 134 |   this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); | 
|---|
| 135 |   this->wingNodeLeft.setParent(this); | 
|---|
| 136 |   this->wingNodeLeft.setRelCoor(-1.5, -.3, -1.0); | 
|---|
| 137 |   this->rotorNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); | 
|---|
| 138 |   this->rotorNodeLeft.setParent(&this->wingNodeLeft); | 
|---|
| 139 |   this->rotorNodeLeft.setRelCoor(0, 1.0, -2.3); | 
|---|
| 140 |  | 
|---|
| 141 |   this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); | 
|---|
| 142 |   this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); | 
|---|
| 143 |   this->wingNodeRight.setParent(this); | 
|---|
| 144 |   this->wingNodeRight.setRelCoor(-1.5, -0.3, 1.0); | 
|---|
| 145 |   this->rotorNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); | 
|---|
| 146 |   this->rotorNodeRight.setParent(&this->wingNodeRight); | 
|---|
| 147 |   this->rotorNodeRight.setRelCoor(0, 1.0, 2.3); | 
|---|
| 148 |  | 
|---|
| 149 |   // PARTICLES | 
|---|
| 150 |   this->burstEmitter[0] = new DotEmitter(200, 5.0, .01); | 
|---|
| 151 |   this->burstEmitter[0]->setParent(&this->rotorNodeLeft); | 
|---|
| 152 |   this->burstEmitter[0]->setRelCoor(0, -0.7, 0); | 
|---|
| 153 |   this->burstEmitter[0]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); | 
|---|
| 154 |   this->burstEmitter[0]->setName("TurbineHover_Burst_emitter_Left"); | 
|---|
| 155 |  | 
|---|
| 156 |   this->burstEmitter[1] = new DotEmitter(200, 5.0, .01); | 
|---|
| 157 |   this->burstEmitter[1]->setParent(&this->rotorNodeRight); | 
|---|
| 158 |   this->burstEmitter[1]->setRelCoor(0, -0.7, 0); | 
|---|
| 159 |   this->burstEmitter[1]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); | 
|---|
| 160 |   this->burstEmitter[1]->setName("TurbineHover_Burst_emitter_Right"); | 
|---|
| 161 |  | 
|---|
| 162 |  | 
|---|
| 163 |   this->burstSystem = new SpriteParticles(1000); | 
|---|
| 164 |   this->burstSystem->addEmitter(this->burstEmitter[0]); | 
|---|
| 165 |   this->burstSystem->addEmitter(this->burstEmitter[1]); | 
|---|
| 166 |   this->burstSystem->setName("SpaceShip_Burst_System"); | 
|---|
| 167 |   ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); | 
|---|
| 168 |   this->burstSystem->setLifeSpan(1.0, .3); | 
|---|
| 169 |   this->burstSystem->setRadius(0.0, 1.5); | 
|---|
| 170 |   this->burstSystem->setRadius(0.05, 1.8); | 
|---|
| 171 |   this->burstSystem->setRadius(.5, .8); | 
|---|
| 172 |   this->burstSystem->setRadius(1.0, 0); | 
|---|
| 173 |   this->burstSystem->setColor(0.0, .7,.7,1,.5); | 
|---|
| 174 |   this->burstSystem->setColor(0.2, 0,0,0.8,.5); | 
|---|
| 175 |   this->burstSystem->setColor(0.5, .5,.5,.8,.3); | 
|---|
| 176 |   this->burstSystem->setColor(1.0, .8,.8,.8,.0); | 
|---|
| 177 |  | 
|---|
| 178 |  | 
|---|
| 179 |   //add events to the eventlist of the Playable | 
|---|
| 180 |   this->registerEvent(KeyMapper::PEV_FORWARD); | 
|---|
| 181 |   this->registerEvent(KeyMapper::PEV_BACKWARD); | 
|---|
| 182 |   this->registerEvent(KeyMapper::PEV_LEFT); | 
|---|
| 183 |   this->registerEvent(KeyMapper::PEV_RIGHT); | 
|---|
| 184 |   this->registerEvent(KeyMapper::PEV_UP); | 
|---|
| 185 |   this->registerEvent(KeyMapper::PEV_DOWN); | 
|---|
| 186 |   this->registerEvent(KeyMapper::PEV_FIRE1); | 
|---|
| 187 |   this->registerEvent(KeyMapper::PEV_NEXT_WEAPON); | 
|---|
| 188 |   this->registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); | 
|---|
| 189 |   this->registerEvent(EV_MOUSE_MOTION); | 
|---|
| 190 |  | 
|---|
| 191 |   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); | 
|---|
| 192 |  | 
|---|
| 193 |   // WEAPON_MANAGER configuration | 
|---|
| 194 |   this->getWeaponManager().setSlotCount(5); | 
|---|
| 195 |  | 
|---|
| 196 |   this->getWeaponManager().setSlotPosition(0, Vector(-0.28, 1.186, -2.750), &this->wingNodeLeft); | 
|---|
| 197 |   this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); | 
|---|
| 198 |  | 
|---|
| 199 |   this->getWeaponManager().setSlotPosition(1, Vector(-0.28, 1.186, 2.750), &this->wingNodeRight); | 
|---|
| 200 |   this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); | 
|---|
| 201 |  | 
|---|
| 202 |   this->getWeaponManager().setSlotPosition(2, Vector(-1.63, .809, -.003)); | 
|---|
| 203 |   this->getWeaponManager().setSlotCapability(2, WTYPE_HEAVY); | 
|---|
| 204 |  | 
|---|
| 205 |   /// TODO: THESE ARE TOO MUCH | 
|---|
| 206 |   this->getWeaponManager().setSlotPosition(3, Vector(-1.63, .678, -.652)); | 
|---|
| 207 |   this->getWeaponManager().setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0))); | 
|---|
| 208 |  | 
|---|
| 209 |   this->getWeaponManager().setSlotPosition(4, Vector(-1.63, .678, .652)); | 
|---|
| 210 |   this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); | 
|---|
| 211 |  | 
|---|
| 212 |   this->cameraNode.setRelCoor(1,5,0); | 
|---|
| 213 |   this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); | 
|---|
| 214 |   this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); | 
|---|
| 215 |  | 
|---|
| 216 |   registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); | 
|---|
| 217 |   registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); | 
|---|
| 218 |   registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); | 
|---|
| 219 |   registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); | 
|---|
| 220 |   registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); | 
|---|
| 221 |   registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); | 
|---|
| 222 |   registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) ); | 
|---|
| 223 |   registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); | 
|---|
| 224 |   registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); | 
|---|
| 225 |  | 
|---|
| 226 |   if( State::isOnline()) | 
|---|
| 227 |     toList( OM_PLAYERS ); | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | /** | 
|---|
| 231 |  * @brief loads the Settings of a TurbineHover from an XML-element. | 
|---|
| 232 |  * @param root the XML-element to load the Spaceship's properties from | 
|---|
| 233 |  */ | 
|---|
| 234 | void TurbineHover::loadParams(const TiXmlElement* root) | 
|---|
| 235 | { | 
|---|
| 236 |   Playable::loadParams(root); | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 |  | 
|---|
| 240 | void TurbineHover::setBoostColor(const Color& color) | 
|---|
| 241 | { | 
|---|
| 242 |   this->burstSystem->setColor(0.0, color); | 
|---|
| 243 |   this->burstSystem->setColor(0.2, color * 0.6); | 
|---|
| 244 |   this->burstSystem->setColor(0.5, color * .3 + Color(0.5, 0.5, 0.8, 0.3)); | 
|---|
| 245 |   this->burstSystem->setColor(1.0, 0.8, 0.8, 0.8, 0.0); | 
|---|
| 246 |  | 
|---|
| 247 |   printf(":::::::::::::::::::::::\n"); | 
|---|
| 248 |   this->burstSystem->debug(); | 
|---|
| 249 | } | 
|---|
| 250 |  | 
|---|
| 251 | void TurbineHover::setPlayDirection(const Quaternion& rot, float speed) | 
|---|
| 252 | { | 
|---|
| 253 |   this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); | 
|---|
| 254 | } | 
|---|
| 255 |  | 
|---|
| 256 | void TurbineHover::enter() | 
|---|
| 257 | { | 
|---|
| 258 |   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); | 
|---|
| 259 |  | 
|---|
| 260 |   if (State::getCameraNode != NULL) | 
|---|
| 261 |   { | 
|---|
| 262 |     State::getCameraNode()->setParentSoft(&this->cameraNode); | 
|---|
| 263 |     State::getCameraNode()->setRelCoorSoft(-10, 0,0); | 
|---|
| 264 |     State::getCameraTargetNode()->setParentSoft(&this->cameraNode); | 
|---|
| 265 |   } | 
|---|
| 266 | } | 
|---|
| 267 |  | 
|---|
| 268 | void TurbineHover::leave() | 
|---|
| 269 | { | 
|---|
| 270 |   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); | 
|---|
| 271 |   this->detachCamera(); | 
|---|
| 272 |  | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | void TurbineHover::setTeam(int teamID) | 
|---|
| 276 | { | 
|---|
| 277 |   printf("::::::::::::::::: TEAM ::: %d\n", teamID); | 
|---|
| 278 |   if (teamID == 0) | 
|---|
| 279 |   { | 
|---|
| 280 |     this->setBoostColor(Color::blue); | 
|---|
| 281 |   } | 
|---|
| 282 |   else if (teamID == 1) | 
|---|
| 283 |   { | 
|---|
| 284 |     this->setBoostColor(Color::red); | 
|---|
| 285 |   } | 
|---|
| 286 |  | 
|---|
| 287 |   ///HACK this is very much hard coded.set the owner of the weapons | 
|---|
| 288 |   this->getWeaponManager().getWeapon(0)->setOwner(this->getOwner()); | 
|---|
| 289 |   this->getWeaponManager().getWeapon(1)->setOwner(this->getOwner()); | 
|---|
| 290 |  | 
|---|
| 291 |   //choose collision list | 
|---|
| 292 |   if( State::isOnline()) | 
|---|
| 293 |   { | 
|---|
| 294 |     if( teamID == 0) | 
|---|
| 295 |       toList( OM_GROUP_00 ); | 
|---|
| 296 |     else if(teamID == 1) | 
|---|
| 297 |       toList( OM_GROUP_01); | 
|---|
| 298 |   } | 
|---|
| 299 |  | 
|---|
| 300 |  | 
|---|
| 301 |   // set the local team id, very important | 
|---|
| 302 |   this->setTeamId(teamID); | 
|---|
| 303 | } | 
|---|
| 304 |  | 
|---|
| 305 |  | 
|---|
| 306 |  | 
|---|
| 307 | /** | 
|---|
| 308 |  * @brief effect that occurs after the TurbineHover is spawned | 
|---|
| 309 | */ | 
|---|
| 310 | void TurbineHover::postSpawn () | 
|---|
| 311 | { | 
|---|
| 312 |   //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); | 
|---|
| 313 | } | 
|---|
| 314 |  | 
|---|
| 315 | /** | 
|---|
| 316 |  * @brief the action occuring if the turbine_hover left the game | 
|---|
| 317 | */ | 
|---|
| 318 | void TurbineHover::leftWorld () | 
|---|
| 319 | {} | 
|---|
| 320 |  | 
|---|
| 321 | /** | 
|---|
| 322 |  * @brief this function is called, when two entities collide | 
|---|
| 323 |  * @param entity: the world entity with whom it collides | 
|---|
| 324 |  * | 
|---|
| 325 |  * Implement behaviour like damage application or other miscellaneous collision stuff in this function | 
|---|
| 326 |  */ | 
|---|
| 327 | void TurbineHover::collidesWith(WorldEntity* entity, const Vector& location) | 
|---|
| 328 | { | 
|---|
| 329 |   Playable::collidesWith(entity, location); | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 |  | 
|---|
| 333 |  | 
|---|
| 334 | /** | 
|---|
| 335 |  * @brief the function called for each passing timeSnap | 
|---|
| 336 |  * @param time The timespan passed since last update | 
|---|
| 337 | */ | 
|---|
| 338 | void TurbineHover::tick (float dt) | 
|---|
| 339 | { | 
|---|
| 340 |   //  this->debugNode(1); | 
|---|
| 341 |   Playable::tick(dt); | 
|---|
| 342 |  | 
|---|
| 343 |   // spaceship controlled movement | 
|---|
| 344 |  | 
|---|
| 345 |   // TRYING TO FIX PNode. | 
|---|
| 346 |   //this->cameraNode.setRelCoor(Vector(0.0f, 5.0f, 0.0f));//, 30.0f); | 
|---|
| 347 |   //this->cameraNode.setRelDir(Quaternion(this->smoothRotator  *10.0, Vector(0,1,0))); | 
|---|
| 348 |  | 
|---|
| 349 |   this->movement(dt); | 
|---|
| 350 |   this->rotorCycle += this->rotorSpeed * dt; | 
|---|
| 351 | } | 
|---|
| 352 |  | 
|---|
| 353 |  | 
|---|
| 354 | #include "shared_network_data.h" | 
|---|
| 355 |  | 
|---|
| 356 | /** | 
|---|
| 357 |  * @brief calculate the velocity | 
|---|
| 358 |  * @param time the timeslice since the last frame | 
|---|
| 359 | */ | 
|---|
| 360 | void TurbineHover::movement (float dt) | 
|---|
| 361 | { | 
|---|
| 362 |   Vector accel(0.0, 0.0, 0.0); | 
|---|
| 363 |  | 
|---|
| 364 |   if( this->bForward ) | 
|---|
| 365 |   { | 
|---|
| 366 |     accel += Vector(this->acceleration, 0, 0); | 
|---|
| 367 |   } | 
|---|
| 368 |  | 
|---|
| 369 |   if( this->bBackward ) | 
|---|
| 370 |   { | 
|---|
| 371 |     accel -= Vector(this->acceleration, 0, 0); | 
|---|
| 372 |   } | 
|---|
| 373 |   if( this->bLeft) | 
|---|
| 374 |   { | 
|---|
| 375 |     accel -= Vector(0, 0, this->acceleration); | 
|---|
| 376 |   } | 
|---|
| 377 |  | 
|---|
| 378 |   if( this->bRight) | 
|---|
| 379 |   { | 
|---|
| 380 |     accel += Vector(0, 0, this->acceleration); | 
|---|
| 381 |   } | 
|---|
| 382 |  | 
|---|
| 383 |   if (this->bAscend ) | 
|---|
| 384 |   { | 
|---|
| 385 |     accel += Vector(0, this->acceleration, 0); | 
|---|
| 386 |   } | 
|---|
| 387 |   if (this->bDescend ) | 
|---|
| 388 |   { | 
|---|
| 389 |     accel -= Vector(0, this->acceleration, 0); | 
|---|
| 390 |   } | 
|---|
| 391 |  | 
|---|
| 392 |   switch(this->getPlaymode()) | 
|---|
| 393 |   { | 
|---|
| 394 |     case Playable::Full3D: | 
|---|
| 395 |       { | 
|---|
| 396 |         Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); | 
|---|
| 397 |  | 
|---|
| 398 |         // this is the air friction (necessary for a smooth control) | 
|---|
| 399 |         Vector damping = (this->velocity * this->airFriction); | 
|---|
| 400 |  | 
|---|
| 401 |  | 
|---|
| 402 |         this->velocity += (accelerationDir - damping)* dt; | 
|---|
| 403 |         //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID()) | 
|---|
| 404 |           this->shiftCoor (this->velocity * dt); | 
|---|
| 405 |  | 
|---|
| 406 |         // limit the maximum rotation speed. | 
|---|
| 407 |         if (this->rotation != 0.0f) | 
|---|
| 408 |         { | 
|---|
| 409 |           float maxRot = 10.0 * dt; | 
|---|
| 410 |           if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; | 
|---|
| 411 |           if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; | 
|---|
| 412 |           this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); | 
|---|
| 413 |  | 
|---|
| 414 |           this->rotation = 0.0f; | 
|---|
| 415 |         } | 
|---|
| 416 |  | 
|---|
| 417 |         //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID()) | 
|---|
| 418 |           this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); | 
|---|
| 419 |  | 
|---|
| 420 |         this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); | 
|---|
| 421 |         this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); | 
|---|
| 422 |  | 
|---|
| 423 |         this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); | 
|---|
| 424 |         this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); | 
|---|
| 425 |       } | 
|---|
| 426 |       break; | 
|---|
| 427 |  | 
|---|
| 428 |     case Playable::Horizontal: | 
|---|
| 429 |       { | 
|---|
| 430 |         accel.y = 0.0; | 
|---|
| 431 |         Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); | 
|---|
| 432 |         accelerationDir.y = 0.0; | 
|---|
| 433 |  | 
|---|
| 434 |         // this is the air friction (necessary for a smooth control) | 
|---|
| 435 |         Vector damping = (this->velocity * this->airFriction); | 
|---|
| 436 |  | 
|---|
| 437 |  | 
|---|
| 438 |         this->velocity += (accelerationDir - damping)* dt; | 
|---|
| 439 |         this->shiftCoor (this->velocity * dt); | 
|---|
| 440 |  | 
|---|
| 441 |         // limit the maximum rotation speed. | 
|---|
| 442 |         if (this->rotation != 0.0f) | 
|---|
| 443 |         { | 
|---|
| 444 |           float maxRot = 10.0 * dt; | 
|---|
| 445 |           if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; | 
|---|
| 446 |           if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; | 
|---|
| 447 |           this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); | 
|---|
| 448 |  | 
|---|
| 449 |           this->rotation = 0.0f; | 
|---|
| 450 |         } | 
|---|
| 451 |  | 
|---|
| 452 |         this->setRelDirSoft(this->direction, 5); | 
|---|
| 453 |  | 
|---|
| 454 |         this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); | 
|---|
| 455 |         this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation, Vector(0,0,1)), 5); | 
|---|
| 456 |  | 
|---|
| 457 |         this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); | 
|---|
| 458 |         this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation, Vector(0,0,1)), 5); | 
|---|
| 459 |       } | 
|---|
| 460 |       break; | 
|---|
| 461 |  | 
|---|
| 462 |     case Playable::Vertical: | 
|---|
| 463 |       { | 
|---|
| 464 |         accel.z = 0; | 
|---|
| 465 |         Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); | 
|---|
| 466 |         accelerationDir.z=0; | 
|---|
| 467 |  | 
|---|
| 468 |         // this is the air friction (necessary for a smooth control) | 
|---|
| 469 |         Vector damping = (this->velocity * this->airFriction); | 
|---|
| 470 |  | 
|---|
| 471 |         this->velocity += (accelerationDir - damping)* dt; | 
|---|
| 472 |         this->shiftCoor (this->velocity * dt); | 
|---|
| 473 |  | 
|---|
| 474 |         this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); | 
|---|
| 475 |  | 
|---|
| 476 |         this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); | 
|---|
| 477 |         this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); | 
|---|
| 478 |  | 
|---|
| 479 |         this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); | 
|---|
| 480 |         this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); | 
|---|
| 481 |       } | 
|---|
| 482 |       break; | 
|---|
| 483 |     default: | 
|---|
| 484 |       PRINTF(2)("Playmode %s Not Implemented\n", Playable::playmodeToString(this->getPlaymode()).c_str()); | 
|---|
| 485 |   } | 
|---|
| 486 | } | 
|---|
| 487 |  | 
|---|
| 488 |  | 
|---|
| 489 | void TurbineHover::draw() const | 
|---|
| 490 | { | 
|---|
| 491 |   Vector tmpRot; | 
|---|
| 492 |   WorldEntity::draw(); | 
|---|
| 493 |  | 
|---|
| 494 |   glPushMatrix(); | 
|---|
| 495 |   /// LEFT SIDE | 
|---|
| 496 |   glTranslatef (this->wingNodeLeft.getAbsCoor ().x, | 
|---|
| 497 |                 this->wingNodeLeft.getAbsCoor ().y, | 
|---|
| 498 |                 this->wingNodeLeft.getAbsCoor ().z); | 
|---|
| 499 |   tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis(); | 
|---|
| 500 |   glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
| 501 |   this->getModel(3)->draw(); | 
|---|
| 502 |   glPopMatrix (); | 
|---|
| 503 |  | 
|---|
| 504 |   glPushMatrix(); | 
|---|
| 505 |   glTranslatef (this->rotorNodeLeft.getAbsCoor ().x, | 
|---|
| 506 |                 this->rotorNodeLeft.getAbsCoor ().y, | 
|---|
| 507 |                 this->rotorNodeLeft.getAbsCoor ().z); | 
|---|
| 508 |   tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis(); | 
|---|
| 509 |   glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
| 510 |   this->getModel(4)->draw(); | 
|---|
| 511 |   glRotatef(this->rotorCycle, 0,1,0); | 
|---|
| 512 |   this->getModel(5)->draw(); | 
|---|
| 513 |   glPopMatrix (); | 
|---|
| 514 |  | 
|---|
| 515 |   /// RIGHT SIDE | 
|---|
| 516 |   glPushMatrix(); | 
|---|
| 517 |   glTranslatef (this->wingNodeRight.getAbsCoor ().x, | 
|---|
| 518 |                 this->wingNodeRight.getAbsCoor ().y, | 
|---|
| 519 |                 this->wingNodeRight.getAbsCoor ().z); | 
|---|
| 520 |   tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis(); | 
|---|
| 521 |   glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
| 522 |   glScalef(1,1,-1); | 
|---|
| 523 |   this->getModel(3)->draw(); | 
|---|
| 524 |   glPopMatrix (); | 
|---|
| 525 |  | 
|---|
| 526 |   glPushMatrix(); | 
|---|
| 527 |   glTranslatef (this->rotorNodeRight.getAbsCoor ().x, | 
|---|
| 528 |                 this->rotorNodeRight.getAbsCoor ().y, | 
|---|
| 529 |                 this->rotorNodeRight.getAbsCoor ().z); | 
|---|
| 530 |   tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis(); | 
|---|
| 531 |   glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
| 532 |   glScalef(1,1,-1); | 
|---|
| 533 |   this->getModel(4)->draw(); | 
|---|
| 534 |   glRotatef(this->rotorCycle, 0,1,0); | 
|---|
| 535 |   this->getModel(5)->draw(); | 
|---|
| 536 |   glPopMatrix (); | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 | /** | 
|---|
| 540 |  * @todo switch statement ?? | 
|---|
| 541 |  */ | 
|---|
| 542 | void TurbineHover::process(const Event &event) | 
|---|
| 543 | { | 
|---|
| 544 |   Playable::process(event); | 
|---|
| 545 |  | 
|---|
| 546 |   if( event.type == KeyMapper::PEV_LEFT) | 
|---|
| 547 |     this->bLeft = event.bPressed; | 
|---|
| 548 |   else if( event.type == KeyMapper::PEV_RIGHT) | 
|---|
| 549 |     this->bRight = event.bPressed; | 
|---|
| 550 |   else if( event.type == KeyMapper::PEV_UP) | 
|---|
| 551 |     this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); | 
|---|
| 552 |   else if( event.type == KeyMapper::PEV_DOWN) | 
|---|
| 553 |     this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); | 
|---|
| 554 |   else if( event.type == KeyMapper::PEV_FORWARD) | 
|---|
| 555 |     this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); | 
|---|
| 556 |   else if( event.type == KeyMapper::PEV_BACKWARD) | 
|---|
| 557 |     this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); | 
|---|
| 558 |   else if( event.type == EV_MOUSE_MOTION) | 
|---|
| 559 |   { | 
|---|
| 560 |     float xMouse, yMouse; | 
|---|
| 561 |     xMouse = event.xRel*mouseSensitivity; | 
|---|
| 562 |     yMouse = event.yRel*mouseSensitivity; | 
|---|
| 563 |  | 
|---|
| 564 |     // rotate the Player around the y-axis | 
|---|
| 565 |     this->rotation += xMouse; | 
|---|
| 566 |  | 
|---|
| 567 |     this->cameraLook += yMouse; | 
|---|
| 568 |     // rotate the Camera around the z-axis | 
|---|
| 569 |     if (cameraLook > M_PI_4) | 
|---|
| 570 |       cameraLook = M_PI_4; | 
|---|
| 571 |     else if (cameraLook < -M_PI_4) | 
|---|
| 572 |       cameraLook = -M_PI_4; | 
|---|
| 573 |     //this->cameraNode.setRelDirSoft(this->direction,10); | 
|---|
| 574 |   } | 
|---|
| 575 | } | 
|---|
| 576 |  | 
|---|
| 577 |  | 
|---|
| 578 | /** | 
|---|
| 579 |  *  respawning function called by the GameRules | 
|---|
| 580 |  */ | 
|---|
| 581 | void TurbineHover::respawn( ) | 
|---|
| 582 | { | 
|---|
| 583 |  | 
|---|
| 584 |   Playable::respawn(); | 
|---|
| 585 | } | 
|---|