[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 "event_handler.h" |
---|
| 29 | #include "state.h" |
---|
| 30 | |
---|
| 31 | #include "graphics_engine.h" |
---|
[7001] | 32 | #include "dot_emitter.h" |
---|
| 33 | #include "sprite_particles.h" |
---|
[6443] | 34 | |
---|
| 35 | using namespace std; |
---|
| 36 | |
---|
[7000] | 37 | CREATE_FACTORY(TurbineHover, CL_TURBINE_HOVER); |
---|
[6443] | 38 | |
---|
| 39 | /** |
---|
[7000] | 40 | * destructs the turbine_hover, deletes alocated memory |
---|
[6443] | 41 | */ |
---|
[7000] | 42 | TurbineHover::~TurbineHover () |
---|
[6986] | 43 | { |
---|
| 44 | this->setPlayer(NULL); |
---|
| 45 | } |
---|
[6443] | 46 | |
---|
| 47 | /** |
---|
[7339] | 48 | * @brief loads a TurbineHover information from a specified file. |
---|
[7000] | 49 | * @param fileName the name of the File to load the turbine_hover from (absolute path) |
---|
[6443] | 50 | */ |
---|
[7221] | 51 | TurbineHover::TurbineHover(const std::string& fileName) |
---|
[6443] | 52 | { |
---|
| 53 | this->init(); |
---|
| 54 | TiXmlDocument doc(fileName); |
---|
| 55 | |
---|
| 56 | if(!doc.LoadFile()) |
---|
| 57 | { |
---|
[7221] | 58 | PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName.c_str()); |
---|
[6443] | 59 | return; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | this->loadParams(doc.RootElement()); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
[7339] | 66 | * @brief creates a new Spaceship from Xml Data |
---|
[6443] | 67 | * @param root the xml element containing spaceship data |
---|
| 68 | |
---|
| 69 | @todo add more parameters to load |
---|
| 70 | */ |
---|
[7000] | 71 | TurbineHover::TurbineHover(const TiXmlElement* root) |
---|
[6443] | 72 | { |
---|
| 73 | this->init(); |
---|
| 74 | if (root != NULL) |
---|
| 75 | this->loadParams(root); |
---|
| 76 | |
---|
| 77 | //weapons: |
---|
| 78 | Weapon* wpRight = new TestGun(0); |
---|
| 79 | wpRight->setName("testGun Right"); |
---|
| 80 | Weapon* wpLeft = new TestGun(1); |
---|
| 81 | wpLeft->setName("testGun Left"); |
---|
[7126] | 82 | //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_HYPERBLASTER)); |
---|
[6443] | 83 | |
---|
[7126] | 84 | // cannon->setName("BFG"); |
---|
[6443] | 85 | |
---|
| 86 | this->addWeapon(wpLeft, 1, 0); |
---|
| 87 | this->addWeapon(wpRight,1 ,1); |
---|
[7126] | 88 | //this->addWeapon(cannon, 0, 2); |
---|
[6443] | 89 | |
---|
[7337] | 90 | this->getWeaponManager().changeWeaponConfig(1); |
---|
| 91 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6800] | 92 | |
---|
| 93 | this->loadModel("models/ships/hoverglider_mainbody.obj"); |
---|
[6443] | 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | /** |
---|
[7339] | 98 | * @brief initializes a TurbineHover |
---|
[6443] | 99 | */ |
---|
[7000] | 100 | void TurbineHover::init() |
---|
[6443] | 101 | { |
---|
[6805] | 102 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
[7000] | 103 | this->setClassID(CL_TURBINE_HOVER, "TurbineHover"); |
---|
[6443] | 104 | |
---|
[7346] | 105 | this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal | Playable::Vertical); |
---|
[7339] | 106 | |
---|
[6807] | 107 | this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3); |
---|
[7000] | 108 | this->loadModel("models/ships/hoverglider_turbine.obj", 1.0f, 4); |
---|
| 109 | this->loadModel("models/ships/hoverglider_turbine_rotors.obj", 1.0f, 5); |
---|
[6443] | 110 | |
---|
[6805] | 111 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = false; |
---|
[6807] | 112 | mouseSensitivity = 0.005; |
---|
[6443] | 113 | |
---|
[6806] | 114 | this->rotorSpeed = 1000.0f; |
---|
| 115 | this->rotorCycle = 0.0f; |
---|
[6807] | 116 | this->cameraLook = 0.0f; |
---|
| 117 | this->rotation = 0.0f; |
---|
[7001] | 118 | this->acceleration = 10.0f; |
---|
| 119 | this->airFriction = 2.0f; |
---|
[6799] | 120 | |
---|
[7072] | 121 | this->setHealthMax(100); |
---|
| 122 | this->setHealth(100); |
---|
| 123 | |
---|
| 124 | |
---|
[6806] | 125 | // camera - issue |
---|
[6800] | 126 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6806] | 127 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
[6880] | 128 | //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); |
---|
[7003] | 129 | //this->cameraNode.setParent(this); |
---|
[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 | |
---|
[6443] | 178 | //add events to the eventlist |
---|
[6997] | 179 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 180 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
[6637] | 181 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 182 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
[6998] | 183 | registerEvent(KeyMapper::PEV_UP); |
---|
| 184 | registerEvent(KeyMapper::PEV_DOWN); |
---|
[6443] | 185 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 186 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 187 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 188 | registerEvent(EV_MOUSE_MOTION); |
---|
| 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); |
---|
[6443] | 214 | } |
---|
| 215 | |
---|
| 216 | /** |
---|
[7345] | 217 | * @brief loads the Settings of a TurbineHover from an XML-element. |
---|
[6443] | 218 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 219 | */ |
---|
[7000] | 220 | void TurbineHover::loadParams(const TiXmlElement* root) |
---|
[6443] | 221 | { |
---|
[7348] | 222 | Playable::loadParams(root); |
---|
[6443] | 223 | } |
---|
| 224 | |
---|
[7348] | 225 | void TurbineHover::setPlayDirection(const Quaternion& rot, float speed) |
---|
| 226 | { |
---|
| 227 | this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
| 228 | } |
---|
[6443] | 229 | |
---|
[7000] | 230 | void TurbineHover::enter() |
---|
[6443] | 231 | { |
---|
[7337] | 232 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
[6443] | 233 | |
---|
[7125] | 234 | if (State::getCameraNode != NULL) |
---|
| 235 | { |
---|
| 236 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
| 237 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
| 238 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
| 239 | } |
---|
[6443] | 240 | } |
---|
| 241 | |
---|
[7000] | 242 | void TurbineHover::leave() |
---|
[6443] | 243 | { |
---|
[7337] | 244 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6443] | 245 | this->detachCamera(); |
---|
| 246 | |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | /** |
---|
[7345] | 251 | * @brief effect that occurs after the TurbineHover is spawned |
---|
[6443] | 252 | */ |
---|
[7000] | 253 | void TurbineHover::postSpawn () |
---|
[6443] | 254 | { |
---|
| 255 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | /** |
---|
[7345] | 259 | * @brief the action occuring if the turbine_hover left the game |
---|
[6443] | 260 | */ |
---|
[7000] | 261 | void TurbineHover::leftWorld () |
---|
[6443] | 262 | {} |
---|
| 263 | |
---|
| 264 | /** |
---|
[7345] | 265 | * @brief this function is called, when two entities collide |
---|
[6443] | 266 | * @param entity: the world entity with whom it collides |
---|
| 267 | * |
---|
| 268 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 269 | */ |
---|
[7000] | 270 | void TurbineHover::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[7072] | 271 | { |
---|
| 272 | Playable::collidesWith(entity, location); |
---|
| 273 | } |
---|
[6443] | 274 | |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | /** |
---|
[7345] | 278 | * @brief the function called for each passing timeSnap |
---|
[6443] | 279 | * @param time The timespan passed since last update |
---|
| 280 | */ |
---|
[7000] | 281 | void TurbineHover::tick (float dt) |
---|
[6443] | 282 | { |
---|
[7339] | 283 | // this->debugNode(1); |
---|
[6804] | 284 | Playable::tick(dt); |
---|
| 285 | |
---|
[6443] | 286 | // spaceship controlled movement |
---|
[6805] | 287 | this->movement(dt); |
---|
[6806] | 288 | this->rotorCycle += this->rotorSpeed * dt; |
---|
[7001] | 289 | |
---|
| 290 | // TRYING TO FIX PNode. |
---|
[7003] | 291 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
---|
| 292 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
---|
[6443] | 293 | } |
---|
| 294 | |
---|
| 295 | /** |
---|
[7345] | 296 | * @brief calculate the velocity |
---|
[6443] | 297 | * @param time the timeslice since the last frame |
---|
| 298 | */ |
---|
[7000] | 299 | void TurbineHover::movement (float dt) |
---|
[6443] | 300 | { |
---|
| 301 | Vector accel(0.0, 0.0, 0.0); |
---|
[6879] | 302 | float rotSpeed = .3; |
---|
[6443] | 303 | |
---|
[6814] | 304 | if( this->bForward ) |
---|
| 305 | { |
---|
[6879] | 306 | accel += Vector(this->acceleration, 0, 0); |
---|
[6443] | 307 | } |
---|
| 308 | |
---|
[6814] | 309 | if( this->bBackward ) |
---|
| 310 | { |
---|
[6879] | 311 | accel -= Vector(this->acceleration, 0, 0); |
---|
[6443] | 312 | } |
---|
[6814] | 313 | if( this->bLeft) |
---|
| 314 | { |
---|
[6879] | 315 | accel -= Vector(0, 0, this->acceleration); |
---|
[6443] | 316 | } |
---|
[6807] | 317 | |
---|
[6814] | 318 | if( this->bRight) |
---|
| 319 | { |
---|
[6879] | 320 | accel += Vector(0, 0, this->acceleration); |
---|
[6443] | 321 | } |
---|
| 322 | |
---|
[6814] | 323 | if (this->bAscend ) |
---|
| 324 | { |
---|
[6879] | 325 | accel += Vector(0, this->acceleration, 0); |
---|
[6443] | 326 | } |
---|
[6814] | 327 | if (this->bDescend ) |
---|
| 328 | { |
---|
[6879] | 329 | accel -= Vector(0, this->acceleration, 0); |
---|
[6807] | 330 | } |
---|
[6443] | 331 | |
---|
[7339] | 332 | switch(this->getPlaymode()) |
---|
| 333 | { |
---|
| 334 | case Playable::Full3D: |
---|
| 335 | { |
---|
| 336 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
[6814] | 337 | |
---|
[7339] | 338 | // this is the air friction (necessary for a smooth control) |
---|
| 339 | Vector damping = (this->velocity * this->airFriction); |
---|
[6999] | 340 | |
---|
| 341 | |
---|
[7339] | 342 | this->velocity += (accelerationDir - damping)* dt; |
---|
| 343 | this->shiftCoor (this->velocity * dt); |
---|
[6879] | 344 | |
---|
[7339] | 345 | // limit the maximum rotation speed. |
---|
| 346 | if (this->rotation != 0.0f) |
---|
| 347 | { |
---|
| 348 | float maxRot = 10.0 * dt; |
---|
| 349 | if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; |
---|
| 350 | if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; |
---|
| 351 | this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); |
---|
[7326] | 352 | |
---|
[7339] | 353 | this->rotation = 0.0f; |
---|
| 354 | } |
---|
[7326] | 355 | |
---|
[7339] | 356 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
[6805] | 357 | |
---|
[7339] | 358 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
| 359 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
[6805] | 360 | |
---|
[7339] | 361 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
| 362 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
| 363 | } |
---|
| 364 | break; |
---|
| 365 | |
---|
| 366 | case Playable::Horizontal: |
---|
| 367 | { |
---|
[7345] | 368 | accel.y = 0.0; |
---|
[7339] | 369 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
[7345] | 370 | accelerationDir.y = 0.0; |
---|
[7339] | 371 | |
---|
| 372 | // this is the air friction (necessary for a smooth control) |
---|
| 373 | Vector damping = (this->velocity * this->airFriction); |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | this->velocity += (accelerationDir - damping)* dt; |
---|
| 377 | this->shiftCoor (this->velocity * dt); |
---|
| 378 | |
---|
| 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)); |
---|
| 386 | |
---|
| 387 | this->rotation = 0.0f; |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | this->setRelDirSoft(this->direction, 5); |
---|
| 391 | |
---|
| 392 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
| 393 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation, Vector(0,0,1)), 5); |
---|
| 394 | |
---|
| 395 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
| 396 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation, Vector(0,0,1)), 5); |
---|
| 397 | } |
---|
| 398 | break; |
---|
[7346] | 399 | |
---|
| 400 | case Playable::Vertical: |
---|
| 401 | { |
---|
| 402 | accel.z = 0; |
---|
| 403 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
| 404 | accelerationDir.z=0; |
---|
| 405 | |
---|
| 406 | // this is the air friction (necessary for a smooth control) |
---|
| 407 | Vector damping = (this->velocity * this->airFriction); |
---|
| 408 | |
---|
| 409 | this->velocity += (accelerationDir - damping)* dt; |
---|
| 410 | this->shiftCoor (this->velocity * dt); |
---|
| 411 | |
---|
| 412 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
| 413 | |
---|
| 414 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
| 415 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
| 416 | |
---|
| 417 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
| 418 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
| 419 | } |
---|
| 420 | break; |
---|
[7339] | 421 | } |
---|
[6443] | 422 | } |
---|
| 423 | |
---|
| 424 | |
---|
[7000] | 425 | void TurbineHover::draw() const |
---|
[6443] | 426 | { |
---|
[6801] | 427 | Vector tmpRot; |
---|
[6443] | 428 | WorldEntity::draw(); |
---|
[6799] | 429 | |
---|
[6801] | 430 | glPushMatrix(); |
---|
| 431 | /// LEFT SIDE |
---|
| 432 | glTranslatef (this->wingNodeLeft.getAbsCoor ().x, |
---|
| 433 | this->wingNodeLeft.getAbsCoor ().y, |
---|
| 434 | this->wingNodeLeft.getAbsCoor ().z); |
---|
| 435 | tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis(); |
---|
| 436 | glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 437 | this->getModel(3)->draw(); |
---|
| 438 | glPopMatrix (); |
---|
[6443] | 439 | |
---|
[6801] | 440 | glPushMatrix(); |
---|
| 441 | glTranslatef (this->rotorNodeLeft.getAbsCoor ().x, |
---|
| 442 | this->rotorNodeLeft.getAbsCoor ().y, |
---|
| 443 | this->rotorNodeLeft.getAbsCoor ().z); |
---|
| 444 | tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis(); |
---|
| 445 | glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 446 | this->getModel(4)->draw(); |
---|
[6806] | 447 | glRotatef(this->rotorCycle, 0,1,0); |
---|
| 448 | this->getModel(5)->draw(); |
---|
[6801] | 449 | glPopMatrix (); |
---|
[6724] | 450 | |
---|
[6801] | 451 | /// RIGHT SIDE |
---|
| 452 | glPushMatrix(); |
---|
| 453 | glTranslatef (this->wingNodeRight.getAbsCoor ().x, |
---|
| 454 | this->wingNodeRight.getAbsCoor ().y, |
---|
| 455 | this->wingNodeRight.getAbsCoor ().z); |
---|
| 456 | tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis(); |
---|
| 457 | glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 458 | glScalef(1,1,-1); |
---|
| 459 | this->getModel(3)->draw(); |
---|
| 460 | glPopMatrix (); |
---|
[6724] | 461 | |
---|
[6801] | 462 | glPushMatrix(); |
---|
| 463 | glTranslatef (this->rotorNodeRight.getAbsCoor ().x, |
---|
| 464 | this->rotorNodeRight.getAbsCoor ().y, |
---|
| 465 | this->rotorNodeRight.getAbsCoor ().z); |
---|
| 466 | tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis(); |
---|
| 467 | glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 468 | glScalef(1,1,-1); |
---|
| 469 | this->getModel(4)->draw(); |
---|
[6806] | 470 | glRotatef(this->rotorCycle, 0,1,0); |
---|
| 471 | this->getModel(5)->draw(); |
---|
[6801] | 472 | glPopMatrix (); |
---|
[6443] | 473 | } |
---|
| 474 | |
---|
| 475 | /** |
---|
| 476 | * @todo switch statement ?? |
---|
| 477 | */ |
---|
[7000] | 478 | void TurbineHover::process(const Event &event) |
---|
[6443] | 479 | { |
---|
[6804] | 480 | Playable::process(event); |
---|
[6443] | 481 | |
---|
[6637] | 482 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[6805] | 483 | this->bLeft = event.bPressed; |
---|
[6637] | 484 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[6805] | 485 | this->bRight = event.bPressed; |
---|
[6998] | 486 | else if( event.type == KeyMapper::PEV_UP) |
---|
[6443] | 487 | this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6998] | 488 | else if( event.type == KeyMapper::PEV_DOWN) |
---|
[6443] | 489 | this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6997] | 490 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[6805] | 491 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 492 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[6805] | 493 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6443] | 494 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 495 | { |
---|
[6807] | 496 | float xMouse, yMouse; |
---|
| 497 | xMouse = event.xRel*mouseSensitivity; |
---|
| 498 | yMouse = event.yRel*mouseSensitivity; |
---|
[6443] | 499 | |
---|
[6805] | 500 | // rotate the Player around the y-axis |
---|
[6807] | 501 | this->rotation += xMouse; |
---|
[6799] | 502 | |
---|
[6807] | 503 | this->cameraLook += yMouse; |
---|
[6805] | 504 | // rotate the Camera around the z-axis |
---|
[6807] | 505 | if (cameraLook > M_PI_4) |
---|
| 506 | cameraLook = M_PI_4; |
---|
[6880] | 507 | else if (cameraLook < -M_PI_4) |
---|
| 508 | cameraLook = -M_PI_4; |
---|
| 509 | //this->cameraNode.setRelDirSoft(this->direction,10); |
---|
[6805] | 510 | } |
---|
[6443] | 511 | } |
---|