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