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