[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 | |
---|
| 19 | #include "helicopter.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 "factory.h" |
---|
| 27 | #include "key_mapper.h" |
---|
| 28 | #include "event_handler.h" |
---|
| 29 | #include "state.h" |
---|
| 30 | |
---|
| 31 | #include "graphics_engine.h" |
---|
| 32 | |
---|
| 33 | using namespace std; |
---|
| 34 | |
---|
| 35 | CREATE_FACTORY(Helicopter, CL_HELICOPTER); |
---|
| 36 | |
---|
| 37 | /** |
---|
[6724] | 38 | * creates the controlable Helicopter |
---|
[6443] | 39 | */ |
---|
| 40 | Helicopter::Helicopter() |
---|
| 41 | { |
---|
| 42 | this->init(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
[6724] | 46 | * destructs the helicopter, deletes alocated memory |
---|
[6443] | 47 | */ |
---|
| 48 | Helicopter::~Helicopter () |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
[6724] | 53 | * loads a Helicopter information from a specified file. |
---|
| 54 | * @param fileName the name of the File to load the helicopter from (absolute path) |
---|
[6443] | 55 | */ |
---|
| 56 | Helicopter::Helicopter(const char* fileName) |
---|
| 57 | { |
---|
| 58 | this->init(); |
---|
| 59 | TiXmlDocument doc(fileName); |
---|
| 60 | |
---|
| 61 | if(!doc.LoadFile()) |
---|
| 62 | { |
---|
| 63 | PRINTF(2)("Loading file %s failed for Helicopter.\n", fileName); |
---|
| 64 | return; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | this->loadParams(doc.RootElement()); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * creates a new Spaceship from Xml Data |
---|
| 72 | * @param root the xml element containing spaceship data |
---|
| 73 | |
---|
| 74 | @todo add more parameters to load |
---|
| 75 | */ |
---|
| 76 | Helicopter::Helicopter(const TiXmlElement* root) |
---|
| 77 | { |
---|
| 78 | this->init(); |
---|
| 79 | if (root != NULL) |
---|
| 80 | this->loadParams(root); |
---|
| 81 | |
---|
| 82 | //weapons: |
---|
| 83 | Weapon* wpRight = new TestGun(0); |
---|
| 84 | wpRight->setName("testGun Right"); |
---|
| 85 | Weapon* wpLeft = new TestGun(1); |
---|
| 86 | wpLeft->setName("testGun Left"); |
---|
| 87 | Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON)); |
---|
| 88 | |
---|
| 89 | cannon->setName("BFG"); |
---|
| 90 | |
---|
| 91 | this->addWeapon(wpLeft, 1, 0); |
---|
| 92 | this->addWeapon(wpRight,1 ,1); |
---|
| 93 | this->addWeapon(cannon, 0, 6); |
---|
| 94 | |
---|
| 95 | //this->addWeapon(turret, 3, 0); |
---|
| 96 | |
---|
| 97 | this->getWeaponManager()->changeWeaponConfig(1); |
---|
| 98 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * initializes a Helicopter |
---|
| 104 | */ |
---|
| 105 | void Helicopter::init() |
---|
| 106 | { |
---|
| 107 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 108 | this->setClassID(CL_HELICOPTER, "Helicopter"); |
---|
| 109 | |
---|
[6724] | 110 | PRINTF(4)("HELICOPTER INIT\n"); |
---|
[6443] | 111 | |
---|
| 112 | this->loadModel("models/ships/helicopter_#.obj", 1.0); |
---|
| 113 | |
---|
| 114 | EventHandler::getInstance()->grabEvents(true); |
---|
| 115 | |
---|
| 116 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; |
---|
| 117 | bFire = false; |
---|
| 118 | xMouse = yMouse = 0; |
---|
[6637] | 119 | mouseSensitivity = 0.05; |
---|
[6724] | 120 | controlVelocityX = 100; |
---|
| 121 | controlVelocityY = 100; |
---|
[6637] | 122 | //rotorspeed = 1; |
---|
| 123 | //tailrotorspeed = 0; |
---|
[6443] | 124 | |
---|
[6637] | 125 | //cycle = 0.0; |
---|
[6804] | 126 | |
---|
[6724] | 127 | // cameraissue |
---|
| 128 | this->cameraNode.setParent(this); |
---|
| 129 | this->cameraNode.setParentMode(PNODE_ALL); |
---|
[6804] | 130 | |
---|
| 131 | |
---|
[6724] | 132 | // rotors |
---|
| 133 | this->topRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 134 | this->tailRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6804] | 135 | |
---|
[6724] | 136 | this->topRotor.setParent(this); |
---|
| 137 | this->tailRotor.setParent(this); |
---|
[6804] | 138 | |
---|
[6724] | 139 | this->topRotor.setRelCoor(Vector(-0.877,0.627,0)); |
---|
| 140 | this->tailRotor.setRelCoor(Vector(-4.43,0.297,0.068)); |
---|
| 141 | this->tailRotor.setAbsDir(Quaternion(M_PI_2,Vector(1,0,0))); |
---|
[6804] | 142 | |
---|
[6724] | 143 | this->loadModel("models/ships/rotor.obj",1.0,3); |
---|
| 144 | this->loadModel("models/ships/rotor.obj",0.2,4); |
---|
[6443] | 145 | |
---|
| 146 | |
---|
[6637] | 147 | //travelSpeed = 15.0; |
---|
[6443] | 148 | this->velocity = Vector(0.0,0.0,0.0); |
---|
| 149 | this->velocityDir = Vector(1.0,0.0,0.0); |
---|
| 150 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 151 | // button->show(); |
---|
| 152 | // button->setLabel("orxonox"); |
---|
| 153 | // button->setBindNode(this); |
---|
| 154 | |
---|
| 155 | //add events to the eventlist |
---|
[6637] | 156 | registerEvent(KeyMapper::PEV_UP); |
---|
| 157 | registerEvent(KeyMapper::PEV_DOWN); |
---|
| 158 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 159 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 160 | //registerEvent(SDLK_q); |
---|
[6443] | 161 | registerEvent(SDLK_e); |
---|
| 162 | registerEvent(SDLK_c); |
---|
| 163 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 164 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 165 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
[6637] | 166 | //registerEvent(SDLK_PAGEUP); |
---|
| 167 | //registerEvent(SDLK_PAGEDOWN); |
---|
[6443] | 168 | registerEvent(EV_MOUSE_MOTION); |
---|
| 169 | |
---|
| 170 | this->getWeaponManager()->setSlotCount(7); |
---|
| 171 | |
---|
| 172 | this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 173 | this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 174 | |
---|
| 175 | this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 176 | this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 177 | |
---|
| 178 | this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 179 | this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 180 | |
---|
| 181 | this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 182 | this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 183 | |
---|
| 184 | this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 185 | this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 186 | |
---|
| 187 | this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 188 | this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
| 189 | // |
---|
| 190 | this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0)); |
---|
| 191 | this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 192 | // |
---|
| 193 | // this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 194 | // this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 195 | // |
---|
| 196 | // this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 197 | // this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
| 198 | |
---|
[6724] | 199 | this->getWeaponManager()->getFixedTarget()->setParent(&(this->cameraNode)); |
---|
| 200 | this->getWeaponManager()->getFixedTarget()->setRelCoor(0,0,0); |
---|
[6443] | 201 | |
---|
| 202 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
| 203 | |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | /** |
---|
| 207 | * loads the Settings of a Helicopter from an XML-element. |
---|
| 208 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 209 | */ |
---|
| 210 | void Helicopter::loadParams(const TiXmlElement* root) |
---|
| 211 | { |
---|
[6512] | 212 | WorldEntity::loadParams(root); |
---|
[6443] | 213 | } |
---|
| 214 | |
---|
[6871] | 215 | void Helicopter::enter() |
---|
[6724] | 216 | { |
---|
[6871] | 217 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true); |
---|
[6724] | 218 | State::getCamera()->setParentSoft(this->getWeaponManager()->getFixedTarget()); |
---|
| 219 | State::getCameraTarget()->setParentSoft(this->getWeaponManager()->getFixedTarget()); |
---|
| 220 | } |
---|
[6443] | 221 | |
---|
| 222 | void Helicopter::leave() |
---|
| 223 | { |
---|
| 224 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
| 225 | this->detachCamera(); |
---|
| 226 | |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | /** |
---|
| 231 | * effect that occurs after the Helicopter is spawned |
---|
| 232 | */ |
---|
| 233 | void Helicopter::postSpawn () |
---|
| 234 | { |
---|
| 235 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | /** |
---|
[6724] | 239 | * the action occuring if the helicopter left the game |
---|
[6443] | 240 | */ |
---|
| 241 | void Helicopter::leftWorld () |
---|
| 242 | {} |
---|
| 243 | |
---|
| 244 | /** |
---|
| 245 | * this function is called, when two entities collide |
---|
| 246 | * @param entity: the world entity with whom it collides |
---|
| 247 | * |
---|
| 248 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 249 | */ |
---|
| 250 | void Helicopter::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 251 | { |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | /** |
---|
| 257 | * the function called for each passing timeSnap |
---|
| 258 | * @param time The timespan passed since last update |
---|
| 259 | */ |
---|
| 260 | void Helicopter::tick (float time) |
---|
| 261 | { |
---|
[6804] | 262 | Playable::tick(time); |
---|
| 263 | |
---|
[6724] | 264 | if( xMouse != 0 || yMouse != 0) |
---|
| 265 | { |
---|
| 266 | if (xMouse > controlVelocityX) xMouse = controlVelocityX; |
---|
| 267 | else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; |
---|
| 268 | if (yMouse > controlVelocityY) yMouse = controlVelocityY; |
---|
| 269 | else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; |
---|
| 270 | } |
---|
[6804] | 271 | |
---|
[6724] | 272 | // rotorrotation |
---|
| 273 | this->topRotor.shiftDir(Quaternion(time*10, Vector(0,1,0))); |
---|
| 274 | this->tailRotor.shiftDir(Quaternion(time*10, Vector(0,1,0))); |
---|
[6804] | 275 | |
---|
[6443] | 276 | // spaceship controlled movement |
---|
| 277 | this->calculateVelocity(time); |
---|
| 278 | |
---|
[6637] | 279 | Vector move = (velocity)*time; |
---|
[6443] | 280 | |
---|
| 281 | // this is the air friction (necessary for a smooth control) |
---|
| 282 | if(velocity.len() != 0) velocity -= velocity*0.1; |
---|
[6804] | 283 | |
---|
[6637] | 284 | //travelSpeed = velocity.len(); |
---|
[6443] | 285 | |
---|
| 286 | //physics: Gravity |
---|
[6637] | 287 | /*this->shiftCoor(Vector(0,-1,0)); |
---|
[6443] | 288 | |
---|
| 289 | this->shiftCoor(getAbsDirY()*rotorspeed); |
---|
[6637] | 290 | */ |
---|
[6804] | 291 | |
---|
[6637] | 292 | /* |
---|
[6443] | 293 | //hoover effect |
---|
| 294 | cycle += time; |
---|
| 295 | this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
[6637] | 296 | */ |
---|
[6443] | 297 | |
---|
| 298 | //readjust |
---|
| 299 | // if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 300 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 301 | |
---|
| 302 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
| 303 | |
---|
| 304 | this->shiftCoor (move); |
---|
[6637] | 305 | //this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0))); |
---|
[6443] | 306 | } |
---|
| 307 | |
---|
| 308 | /** |
---|
| 309 | * calculate the velocity |
---|
| 310 | * @param time the timeslice since the last frame |
---|
| 311 | */ |
---|
| 312 | void Helicopter::calculateVelocity (float time) |
---|
| 313 | { |
---|
| 314 | Vector accel(0.0, 0.0, 0.0); |
---|
[6637] | 315 | float rotValX = 0.0; |
---|
| 316 | float rotValZ = 0.0; |
---|
[6443] | 317 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
| 318 | /* calculate the direction in which the craft is heading */ |
---|
| 319 | |
---|
| 320 | if( this->bUp ) |
---|
| 321 | { |
---|
| 322 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 323 | //accel -= this->getAbsDirY(); |
---|
[6804] | 324 | |
---|
[6637] | 325 | accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); |
---|
| 326 | if((this->getAbsDirX()).y >= -0.1) rotValZ -= time; |
---|
[6443] | 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
[6637] | 330 | if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
[6443] | 331 | } |
---|
| 332 | |
---|
| 333 | if( this->bDown ) |
---|
| 334 | { |
---|
| 335 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 336 | //accel -= this->getAbsDirY(); |
---|
[6804] | 337 | |
---|
[6637] | 338 | accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); |
---|
| 339 | rotValZ += time; |
---|
[6443] | 340 | } |
---|
| 341 | else |
---|
| 342 | { |
---|
[6637] | 343 | if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
[6443] | 344 | } |
---|
| 345 | |
---|
| 346 | if( this->bLeft /* > -this->getRelCoor().z*2*/) |
---|
| 347 | { |
---|
| 348 | //this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 349 | //accel -= this->getAbsDirY(); |
---|
| 350 | //velocityDir.normalize(); |
---|
[6804] | 351 | |
---|
[6637] | 352 | accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); |
---|
| 353 | rotValX -= time; |
---|
[6443] | 354 | } |
---|
| 355 | else |
---|
| 356 | { |
---|
[6637] | 357 | if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time, Vector(1,0,0))); |
---|
[6443] | 358 | } |
---|
| 359 | |
---|
| 360 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 361 | { |
---|
| 362 | //this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
[6637] | 363 | //accel += this->getAbsDirY(); |
---|
[6443] | 364 | //velocityDir.normalize(); |
---|
[6804] | 365 | |
---|
[6637] | 366 | accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); |
---|
| 367 | rotValX += time; |
---|
[6443] | 368 | } |
---|
| 369 | else |
---|
| 370 | { |
---|
[6637] | 371 | if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time, Vector(1,0,0))); |
---|
[6443] | 372 | } |
---|
| 373 | |
---|
| 374 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 375 | { |
---|
| 376 | this->shiftDir(Quaternion(-time, Vector(1,0,0))); |
---|
| 377 | //accel -= rightDirection; |
---|
| 378 | //velocityDir.normalize(); |
---|
| 379 | //rot +=Vector(1,0,0); |
---|
| 380 | //rotVal -= .4; |
---|
| 381 | } |
---|
| 382 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 383 | { |
---|
| 384 | this->shiftDir(Quaternion(time, Vector(1,0,0))); |
---|
| 385 | |
---|
| 386 | //accel += rightDirection; |
---|
| 387 | //velocityDir.normalize(); |
---|
| 388 | //rot += Vector(1,0,0); |
---|
| 389 | //rotVal += .4; |
---|
| 390 | } |
---|
| 391 | if (this->bAscend ) |
---|
| 392 | { |
---|
| 393 | //this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 394 | |
---|
[6637] | 395 | accel += this->getAbsDirY(); |
---|
| 396 | //rotorspeed += 0.05; |
---|
| 397 | //if (rotorspeed >= 2) rotorspeed = 2; |
---|
[6443] | 398 | //velocityDir.normalize(); |
---|
| 399 | //rot += Vector(0,0,1); |
---|
| 400 | //rotVal += .4; |
---|
| 401 | } |
---|
| 402 | else |
---|
| 403 | { |
---|
[6637] | 404 | //if(rotorspeed >= 1.05) rotorspeed -= 0.05; |
---|
[6443] | 405 | } |
---|
| 406 | |
---|
| 407 | if (this->bDescend ) |
---|
| 408 | { |
---|
| 409 | //this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 410 | |
---|
[6637] | 411 | accel -= this->getAbsDirY(); |
---|
| 412 | //rotorspeed -= 0.05; |
---|
| 413 | //if (rotorspeed <= 0) rotorspeed = 0; |
---|
[6443] | 414 | //velocityDir.normalize(); |
---|
| 415 | //rot += Vector(0,0,1); |
---|
| 416 | //rotVal -= .4; |
---|
| 417 | } |
---|
| 418 | else |
---|
| 419 | { |
---|
[6637] | 420 | //if(rotorspeed <= 0.05) rotorspeed += 0.05; |
---|
[6443] | 421 | } |
---|
| 422 | |
---|
[6637] | 423 | velocity += accel*3; |
---|
| 424 | if((this->getAbsDirX()).y <= 0.3 && (this->getAbsDirX()).y >= -0.3) this->shiftDir(Quaternion(rotValZ, Vector(0,0,1))); |
---|
| 425 | if((this->getAbsDirZ()).y <= 0.3 && (this->getAbsDirZ()).y >= -0.3) this->shiftDir(Quaternion(rotValX, Vector(1,0,0))); |
---|
[6443] | 426 | } |
---|
| 427 | |
---|
| 428 | |
---|
| 429 | void Helicopter::draw() const |
---|
| 430 | { |
---|
| 431 | WorldEntity::draw(); |
---|
[6804] | 432 | |
---|
[6724] | 433 | glMatrixMode(GL_MODELVIEW); |
---|
| 434 | glPushMatrix(); |
---|
[6443] | 435 | |
---|
[6724] | 436 | /* translate */ |
---|
| 437 | glTranslatef (this->topRotor.getAbsCoor ().x, |
---|
| 438 | this->topRotor.getAbsCoor ().y, |
---|
| 439 | this->topRotor.getAbsCoor ().z); |
---|
| 440 | Vector tmpRot = this->topRotor.getAbsDir().getSpacialAxis(); |
---|
| 441 | glRotatef (this->topRotor.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 442 | this->getModel(3)->draw(); |
---|
| 443 | |
---|
| 444 | glPopMatrix (); |
---|
| 445 | glPushMatrix(); |
---|
| 446 | |
---|
| 447 | /* translate */ |
---|
| 448 | glTranslatef (this->tailRotor.getAbsCoor ().x, |
---|
| 449 | this->tailRotor.getAbsCoor ().y, |
---|
| 450 | this->tailRotor.getAbsCoor ().z); |
---|
| 451 | tmpRot = this->tailRotor.getAbsDir().getSpacialAxis(); |
---|
| 452 | glRotatef (this->tailRotor.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 453 | this->getModel(4)->draw(); |
---|
| 454 | |
---|
| 455 | glPopMatrix (); |
---|
[6443] | 456 | } |
---|
| 457 | |
---|
| 458 | /** |
---|
| 459 | * @todo switch statement ?? |
---|
| 460 | */ |
---|
| 461 | void Helicopter::process(const Event &event) |
---|
| 462 | { |
---|
[6804] | 463 | Playable::process(event); |
---|
[6443] | 464 | |
---|
[6637] | 465 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[6443] | 466 | this->bLeft = event.bPressed; |
---|
[6637] | 467 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[6443] | 468 | this->bRight = event.bPressed; |
---|
| 469 | else if( event.type == SDLK_e) |
---|
| 470 | this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
| 471 | else if( event.type == SDLK_c) |
---|
| 472 | this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6637] | 473 | else if( event.type == KeyMapper::PEV_UP) |
---|
[6443] | 474 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6637] | 475 | else if( event.type == KeyMapper::PEV_DOWN) |
---|
[6443] | 476 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
| 477 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 478 | { |
---|
| 479 | this->xMouse = event.xRel*mouseSensitivity; |
---|
| 480 | this->yMouse = event.yRel*mouseSensitivity; |
---|
| 481 | |
---|
[6724] | 482 | this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))); |
---|
[6804] | 483 | |
---|
[6724] | 484 | Quaternion yDir = Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)); |
---|
| 485 | |
---|
[6804] | 486 | |
---|
[6724] | 487 | if ((this->cameraNode.getAbsDirY()).y < 0.5) |
---|
| 488 | { |
---|
| 489 | if((this->cameraNode.getAbsDirX()).y > 0) |
---|
| 490 | { |
---|
| 491 | if(yMouse > 0) this->cameraNode.shiftDir(yDir); |
---|
| 492 | } |
---|
| 493 | else |
---|
| 494 | { |
---|
| 495 | if(yMouse < 0) this->cameraNode.shiftDir(yDir); |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | else this->cameraNode.shiftDir(yDir);; |
---|
| 499 | } |
---|
[6443] | 500 | } |
---|