[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 | /** |
---|
[6699] | 38 | * creates the controlable Helicopter |
---|
[6443] | 39 | */ |
---|
| 40 | Helicopter::Helicopter() |
---|
| 41 | { |
---|
| 42 | this->init(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
[6699] | 46 | * destructs the helicopter, deletes alocated memory |
---|
[6443] | 47 | */ |
---|
| 48 | Helicopter::~Helicopter () |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
[6699] | 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 | |
---|
[6699] | 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; |
---|
[6699] | 120 | controlVelocityX = 100; |
---|
| 121 | controlVelocityY = 100; |
---|
[6637] | 122 | //rotorspeed = 1; |
---|
| 123 | //tailrotorspeed = 0; |
---|
[6443] | 124 | |
---|
[6637] | 125 | //cycle = 0.0; |
---|
[6699] | 126 | |
---|
| 127 | |
---|
| 128 | // rotors |
---|
| 129 | this->topRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 130 | this->tailRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 131 | |
---|
| 132 | this->topRotor.setParent(this); |
---|
| 133 | this->tailRotor.setParent(this); |
---|
| 134 | |
---|
| 135 | this->topRotor.setRelCoor(Vector(-0.877,0.627,0)); |
---|
| 136 | this->tailRotor.setRelCoor(Vector(-4.43,0.297,0.068)); |
---|
| 137 | this->tailRotor.setAbsDir(Quaternion(M_PI_2,Vector(1,0,0))); |
---|
| 138 | |
---|
| 139 | this->loadModel("models/ships/rotor.obj",1.0,3); |
---|
| 140 | this->loadModel("models/ships/rotor.obj",0.15,4); |
---|
[6443] | 141 | |
---|
| 142 | |
---|
[6637] | 143 | //travelSpeed = 15.0; |
---|
[6443] | 144 | this->velocity = Vector(0.0,0.0,0.0); |
---|
| 145 | this->velocityDir = Vector(1.0,0.0,0.0); |
---|
| 146 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 147 | // button->show(); |
---|
| 148 | // button->setLabel("orxonox"); |
---|
| 149 | // button->setBindNode(this); |
---|
| 150 | |
---|
| 151 | //add events to the eventlist |
---|
[6637] | 152 | registerEvent(KeyMapper::PEV_UP); |
---|
| 153 | registerEvent(KeyMapper::PEV_DOWN); |
---|
| 154 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 155 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 156 | //registerEvent(SDLK_q); |
---|
[6443] | 157 | registerEvent(SDLK_e); |
---|
| 158 | registerEvent(SDLK_c); |
---|
| 159 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 160 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 161 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
[6637] | 162 | //registerEvent(SDLK_PAGEUP); |
---|
| 163 | //registerEvent(SDLK_PAGEDOWN); |
---|
[6443] | 164 | registerEvent(EV_MOUSE_MOTION); |
---|
| 165 | |
---|
| 166 | this->getWeaponManager()->setSlotCount(7); |
---|
| 167 | |
---|
| 168 | this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 169 | this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 170 | |
---|
| 171 | this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 172 | this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 173 | |
---|
| 174 | this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 175 | this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 176 | |
---|
| 177 | this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 178 | this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 179 | |
---|
| 180 | this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 181 | this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 182 | |
---|
| 183 | this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 184 | this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
| 185 | // |
---|
| 186 | this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0)); |
---|
| 187 | this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 188 | // |
---|
| 189 | // this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 190 | // this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 191 | // |
---|
| 192 | // this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 193 | // this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
| 194 | |
---|
| 195 | this->getWeaponManager()->getFixedTarget()->setParent(this); |
---|
| 196 | this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0); |
---|
| 197 | |
---|
| 198 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
| 199 | |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | /** |
---|
| 203 | * loads the Settings of a Helicopter from an XML-element. |
---|
| 204 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 205 | */ |
---|
| 206 | void Helicopter::loadParams(const TiXmlElement* root) |
---|
| 207 | { |
---|
[6512] | 208 | WorldEntity::loadParams(root); |
---|
[6443] | 209 | } |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | void Helicopter::enter() |
---|
| 215 | { |
---|
| 216 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true); |
---|
| 217 | this->attachCamera(); |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | } |
---|
| 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 | /** |
---|
[6699] | 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 | if (entity->isA(CL_TURRET_POWER_UP)) |
---|
| 253 | { |
---|
| 254 | this->ADDWEAPON(); |
---|
| 255 | } |
---|
| 256 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | /** |
---|
| 262 | * the function called for each passing timeSnap |
---|
| 263 | * @param time The timespan passed since last update |
---|
| 264 | */ |
---|
| 265 | void Helicopter::tick (float time) |
---|
| 266 | { |
---|
[6699] | 267 | if( xMouse != 0 || yMouse != 0) |
---|
| 268 | { |
---|
| 269 | if (xMouse > controlVelocityX) xMouse = controlVelocityX; |
---|
| 270 | else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; |
---|
| 271 | if (yMouse > controlVelocityY) yMouse = controlVelocityY; |
---|
| 272 | else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; |
---|
| 273 | } |
---|
| 274 | // rotorrotation |
---|
| 275 | this->topRotor.shiftDir(Quaternion(time*10, Vector(0,1,0))); |
---|
| 276 | this->tailRotor.shiftDir(Quaternion(time*10, Vector(0,1,0))); |
---|
[6637] | 277 | |
---|
[6443] | 278 | // spaceship controlled movement |
---|
| 279 | this->calculateVelocity(time); |
---|
| 280 | |
---|
[6637] | 281 | Vector move = (velocity)*time; |
---|
[6443] | 282 | |
---|
| 283 | // this is the air friction (necessary for a smooth control) |
---|
| 284 | if(velocity.len() != 0) velocity -= velocity*0.1; |
---|
[6637] | 285 | |
---|
| 286 | //travelSpeed = velocity.len(); |
---|
[6443] | 287 | |
---|
| 288 | //physics: Gravity |
---|
[6637] | 289 | /*this->shiftCoor(Vector(0,-1,0)); |
---|
[6443] | 290 | |
---|
| 291 | this->shiftCoor(getAbsDirY()*rotorspeed); |
---|
[6637] | 292 | */ |
---|
| 293 | |
---|
| 294 | /* |
---|
[6443] | 295 | //hoover effect |
---|
| 296 | cycle += time; |
---|
| 297 | this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
[6637] | 298 | */ |
---|
[6443] | 299 | |
---|
| 300 | //readjust |
---|
| 301 | // if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 302 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 303 | |
---|
| 304 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
| 305 | |
---|
| 306 | this->shiftCoor (move); |
---|
[6637] | 307 | //this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0))); |
---|
[6443] | 308 | |
---|
| 309 | this->getWeaponManager()->tick(time); |
---|
| 310 | // weapon system manipulation |
---|
| 311 | this->weaponAction(); |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | /** |
---|
| 315 | * calculate the velocity |
---|
| 316 | * @param time the timeslice since the last frame |
---|
| 317 | */ |
---|
| 318 | void Helicopter::calculateVelocity (float time) |
---|
| 319 | { |
---|
| 320 | Vector accel(0.0, 0.0, 0.0); |
---|
[6637] | 321 | float rotValX = 0.0; |
---|
| 322 | float rotValZ = 0.0; |
---|
[6443] | 323 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
| 324 | /* calculate the direction in which the craft is heading */ |
---|
| 325 | |
---|
| 326 | if( this->bUp ) |
---|
| 327 | { |
---|
| 328 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 329 | //accel -= this->getAbsDirY(); |
---|
[6637] | 330 | |
---|
| 331 | accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); |
---|
| 332 | if((this->getAbsDirX()).y >= -0.1) rotValZ -= time; |
---|
[6443] | 333 | } |
---|
| 334 | else |
---|
| 335 | { |
---|
[6637] | 336 | if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
[6443] | 337 | } |
---|
| 338 | |
---|
| 339 | if( this->bDown ) |
---|
| 340 | { |
---|
| 341 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 342 | //accel -= this->getAbsDirY(); |
---|
[6637] | 343 | |
---|
| 344 | accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); |
---|
| 345 | rotValZ += time; |
---|
[6443] | 346 | } |
---|
| 347 | else |
---|
| 348 | { |
---|
[6637] | 349 | if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
[6443] | 350 | } |
---|
| 351 | |
---|
| 352 | if( this->bLeft /* > -this->getRelCoor().z*2*/) |
---|
| 353 | { |
---|
| 354 | //this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 355 | //accel -= this->getAbsDirY(); |
---|
| 356 | //velocityDir.normalize(); |
---|
[6637] | 357 | |
---|
| 358 | accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); |
---|
| 359 | rotValX -= time; |
---|
[6443] | 360 | } |
---|
| 361 | else |
---|
| 362 | { |
---|
[6637] | 363 | if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time, Vector(1,0,0))); |
---|
[6443] | 364 | } |
---|
| 365 | |
---|
| 366 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 367 | { |
---|
| 368 | //this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
[6637] | 369 | //accel += this->getAbsDirY(); |
---|
[6443] | 370 | //velocityDir.normalize(); |
---|
[6637] | 371 | |
---|
| 372 | accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); |
---|
| 373 | rotValX += time; |
---|
[6443] | 374 | } |
---|
| 375 | else |
---|
| 376 | { |
---|
[6637] | 377 | if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time, Vector(1,0,0))); |
---|
[6443] | 378 | } |
---|
| 379 | |
---|
| 380 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 381 | { |
---|
| 382 | this->shiftDir(Quaternion(-time, Vector(1,0,0))); |
---|
| 383 | //accel -= rightDirection; |
---|
| 384 | //velocityDir.normalize(); |
---|
| 385 | //rot +=Vector(1,0,0); |
---|
| 386 | //rotVal -= .4; |
---|
| 387 | } |
---|
| 388 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 389 | { |
---|
| 390 | this->shiftDir(Quaternion(time, Vector(1,0,0))); |
---|
| 391 | |
---|
| 392 | //accel += rightDirection; |
---|
| 393 | //velocityDir.normalize(); |
---|
| 394 | //rot += Vector(1,0,0); |
---|
| 395 | //rotVal += .4; |
---|
| 396 | } |
---|
| 397 | if (this->bAscend ) |
---|
| 398 | { |
---|
| 399 | //this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 400 | |
---|
[6637] | 401 | accel += this->getAbsDirY(); |
---|
| 402 | //rotorspeed += 0.05; |
---|
| 403 | //if (rotorspeed >= 2) rotorspeed = 2; |
---|
[6443] | 404 | //velocityDir.normalize(); |
---|
| 405 | //rot += Vector(0,0,1); |
---|
| 406 | //rotVal += .4; |
---|
| 407 | } |
---|
| 408 | else |
---|
| 409 | { |
---|
[6637] | 410 | //if(rotorspeed >= 1.05) rotorspeed -= 0.05; |
---|
[6443] | 411 | } |
---|
| 412 | |
---|
| 413 | if (this->bDescend ) |
---|
| 414 | { |
---|
| 415 | //this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 416 | |
---|
[6637] | 417 | accel -= this->getAbsDirY(); |
---|
| 418 | //rotorspeed -= 0.05; |
---|
| 419 | //if (rotorspeed <= 0) rotorspeed = 0; |
---|
[6443] | 420 | //velocityDir.normalize(); |
---|
| 421 | //rot += Vector(0,0,1); |
---|
| 422 | //rotVal -= .4; |
---|
| 423 | } |
---|
| 424 | else |
---|
| 425 | { |
---|
[6637] | 426 | //if(rotorspeed <= 0.05) rotorspeed += 0.05; |
---|
[6443] | 427 | } |
---|
| 428 | |
---|
[6637] | 429 | velocity += accel*3; |
---|
| 430 | if((this->getAbsDirX()).y <= 0.3 && (this->getAbsDirX()).y >= -0.3) this->shiftDir(Quaternion(rotValZ, Vector(0,0,1))); |
---|
| 431 | if((this->getAbsDirZ()).y <= 0.3 && (this->getAbsDirZ()).y >= -0.3) this->shiftDir(Quaternion(rotValX, Vector(1,0,0))); |
---|
[6443] | 432 | } |
---|
| 433 | |
---|
| 434 | |
---|
| 435 | void Helicopter::draw() const |
---|
| 436 | { |
---|
| 437 | WorldEntity::draw(); |
---|
[6699] | 438 | |
---|
| 439 | glMatrixMode(GL_MODELVIEW); |
---|
| 440 | glPushMatrix(); |
---|
[6443] | 441 | |
---|
[6699] | 442 | /* translate */ |
---|
| 443 | glTranslatef (this->topRotor.getAbsCoor ().x, |
---|
| 444 | this->topRotor.getAbsCoor ().y, |
---|
| 445 | this->topRotor.getAbsCoor ().z); |
---|
| 446 | Vector tmpRot = this->topRotor.getAbsDir().getSpacialAxis(); |
---|
| 447 | glRotatef (this->topRotor.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 448 | this->getModel(3)->draw(); |
---|
| 449 | |
---|
| 450 | glPopMatrix (); |
---|
| 451 | glPushMatrix(); |
---|
| 452 | |
---|
| 453 | /* translate */ |
---|
| 454 | glTranslatef (this->tailRotor.getAbsCoor ().x, |
---|
| 455 | this->tailRotor.getAbsCoor ().y, |
---|
| 456 | this->tailRotor.getAbsCoor ().z); |
---|
| 457 | tmpRot = this->tailRotor.getAbsDir().getSpacialAxis(); |
---|
| 458 | glRotatef (this->tailRotor.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 459 | this->getModel(4)->draw(); |
---|
| 460 | |
---|
| 461 | glPopMatrix (); |
---|
| 462 | |
---|
[6443] | 463 | this->getWeaponManager()->draw(); |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | |
---|
| 467 | /** |
---|
| 468 | * weapon manipulation by the player |
---|
| 469 | */ |
---|
| 470 | void Helicopter::weaponAction() |
---|
| 471 | { |
---|
| 472 | if( this->bFire) |
---|
| 473 | { |
---|
| 474 | this->getWeaponManager()->fire(); |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | /** |
---|
| 479 | * @todo switch statement ?? |
---|
| 480 | */ |
---|
| 481 | void Helicopter::process(const Event &event) |
---|
| 482 | { |
---|
| 483 | |
---|
| 484 | |
---|
[6637] | 485 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[6443] | 486 | this->bLeft = event.bPressed; |
---|
[6637] | 487 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[6443] | 488 | this->bRight = event.bPressed; |
---|
| 489 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
| 490 | this->bFire = event.bPressed; |
---|
| 491 | else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed) |
---|
| 492 | this->getWeaponManager()->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange; |
---|
| 493 | else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) |
---|
| 494 | this->getWeaponManager()->previousWeaponConfig(); |
---|
| 495 | else if( event.type == SDLK_e) |
---|
| 496 | this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
| 497 | else if( event.type == SDLK_c) |
---|
| 498 | this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6637] | 499 | else if( event.type == KeyMapper::PEV_UP) |
---|
[6443] | 500 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6637] | 501 | else if( event.type == KeyMapper::PEV_DOWN) |
---|
[6443] | 502 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
| 503 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 504 | { |
---|
| 505 | this->xMouse = event.xRel*mouseSensitivity; |
---|
| 506 | this->yMouse = event.yRel*mouseSensitivity; |
---|
| 507 | |
---|
[6637] | 508 | this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))/*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))*/); |
---|
[6443] | 509 | } |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | #include "weapons/aiming_turret.h" |
---|
| 513 | // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG |
---|
| 514 | void Helicopter::ADDWEAPON() |
---|
| 515 | { |
---|
| 516 | Weapon* turret = NULL; |
---|
| 517 | |
---|
| 518 | if ((float)rand()/RAND_MAX < .1) |
---|
| 519 | { |
---|
| 520 | //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET)) |
---|
| 521 | { |
---|
| 522 | turret = new Turret(); |
---|
| 523 | this->addWeapon(turret, 2); |
---|
| 524 | this->getWeaponManager()->changeWeaponConfig(2); |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
| 529 | //if (this->getWeaponManager()->hasFreeSlot(3)) |
---|
| 530 | { |
---|
| 531 | turret = new AimingTurret(); |
---|
| 532 | this->addWeapon(turret, 3); |
---|
| 533 | |
---|
| 534 | this->getWeaponManager()->changeWeaponConfig(3); |
---|
| 535 | } |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | if(turret != NULL) |
---|
| 539 | { |
---|
| 540 | turret->setName("Turret"); |
---|
| 541 | turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1); |
---|
| 542 | } |
---|
| 543 | } |
---|