| 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 "turbine_hover.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 | #include "dot_emitter.h" |
|---|
| 33 | #include "sprite_particles.h" |
|---|
| 34 | |
|---|
| 35 | using namespace std; |
|---|
| 36 | |
|---|
| 37 | CREATE_FACTORY(TurbineHover, CL_TURBINE_HOVER); |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * destructs the turbine_hover, deletes alocated memory |
|---|
| 41 | */ |
|---|
| 42 | TurbineHover::~TurbineHover () |
|---|
| 43 | { |
|---|
| 44 | this->setPlayer(NULL); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * loads a TurbineHover information from a specified file. |
|---|
| 49 | * @param fileName the name of the File to load the turbine_hover from (absolute path) |
|---|
| 50 | */ |
|---|
| 51 | TurbineHover::TurbineHover(const char* fileName) |
|---|
| 52 | { |
|---|
| 53 | this->init(); |
|---|
| 54 | TiXmlDocument doc(fileName); |
|---|
| 55 | |
|---|
| 56 | if(!doc.LoadFile()) |
|---|
| 57 | { |
|---|
| 58 | PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName); |
|---|
| 59 | return; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | this->loadParams(doc.RootElement()); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * creates a new Spaceship from Xml Data |
|---|
| 67 | * @param root the xml element containing spaceship data |
|---|
| 68 | |
|---|
| 69 | @todo add more parameters to load |
|---|
| 70 | */ |
|---|
| 71 | TurbineHover::TurbineHover(const TiXmlElement* root) |
|---|
| 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"); |
|---|
| 82 | Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_HYPERBLASTER)); |
|---|
| 83 | |
|---|
| 84 | cannon->setName("BFG"); |
|---|
| 85 | |
|---|
| 86 | this->addWeapon(wpLeft, 1, 0); |
|---|
| 87 | this->addWeapon(wpRight,1 ,1); |
|---|
| 88 | this->addWeapon(cannon, 0, 2); |
|---|
| 89 | |
|---|
| 90 | this->getWeaponManager()->changeWeaponConfig(1); |
|---|
| 91 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
|---|
| 92 | |
|---|
| 93 | this->loadModel("models/ships/hoverglider_mainbody.obj"); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * initializes a TurbineHover |
|---|
| 99 | */ |
|---|
| 100 | void TurbineHover::init() |
|---|
| 101 | { |
|---|
| 102 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
|---|
| 103 | this->setClassID(CL_TURBINE_HOVER, "TurbineHover"); |
|---|
| 104 | |
|---|
| 105 | this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3); |
|---|
| 106 | this->loadModel("models/ships/hoverglider_turbine.obj", 1.0f, 4); |
|---|
| 107 | this->loadModel("models/ships/hoverglider_turbine_rotors.obj", 1.0f, 5); |
|---|
| 108 | |
|---|
| 109 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = false; |
|---|
| 110 | mouseSensitivity = 0.005; |
|---|
| 111 | |
|---|
| 112 | this->rotorSpeed = 1000.0f; |
|---|
| 113 | this->rotorCycle = 0.0f; |
|---|
| 114 | this->cameraLook = 0.0f; |
|---|
| 115 | this->rotation = 0.0f; |
|---|
| 116 | this->acceleration = 10.0f; |
|---|
| 117 | this->airFriction = 2.0f; |
|---|
| 118 | |
|---|
| 119 | this->setHealthMax(100); |
|---|
| 120 | this->setHealth(100); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | // camera - issue |
|---|
| 124 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
|---|
| 125 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
|---|
| 126 | //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); |
|---|
| 127 | //this->cameraNode.setParent(this); |
|---|
| 128 | |
|---|
| 129 | // rotors |
|---|
| 130 | this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT ); |
|---|
| 131 | this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
|---|
| 132 | this->wingNodeLeft.setParent(this); |
|---|
| 133 | this->wingNodeLeft.setRelCoor(-1.5, -.3, -1.0); |
|---|
| 134 | this->rotorNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
|---|
| 135 | this->rotorNodeLeft.setParent(&this->wingNodeLeft); |
|---|
| 136 | this->rotorNodeLeft.setRelCoor(0, 1.0, -2.3); |
|---|
| 137 | |
|---|
| 138 | this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
|---|
| 139 | this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
|---|
| 140 | this->wingNodeRight.setParent(this); |
|---|
| 141 | this->wingNodeRight.setRelCoor(-1.5, -0.3, 1.0); |
|---|
| 142 | this->rotorNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
|---|
| 143 | this->rotorNodeRight.setParent(&this->wingNodeRight); |
|---|
| 144 | this->rotorNodeRight.setRelCoor(0, 1.0, 2.3); |
|---|
| 145 | |
|---|
| 146 | // PARTICLES |
|---|
| 147 | this->burstEmitter[0] = new DotEmitter(200, 5.0, .01); |
|---|
| 148 | this->burstEmitter[0]->setParent(&this->rotorNodeLeft); |
|---|
| 149 | this->burstEmitter[0]->setRelCoor(0, -0.7, 0); |
|---|
| 150 | this->burstEmitter[0]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); |
|---|
| 151 | this->burstEmitter[0]->setName("TurbineHover_Burst_emitter_Left"); |
|---|
| 152 | |
|---|
| 153 | this->burstEmitter[1] = new DotEmitter(200, 5.0, .01); |
|---|
| 154 | this->burstEmitter[1]->setParent(&this->rotorNodeRight); |
|---|
| 155 | this->burstEmitter[1]->setRelCoor(0, -0.7, 0); |
|---|
| 156 | this->burstEmitter[1]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); |
|---|
| 157 | this->burstEmitter[1]->setName("TurbineHover_Burst_emitter_Right"); |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | this->burstSystem = new SpriteParticles(1000); |
|---|
| 161 | this->burstSystem->addEmitter(this->burstEmitter[0]); |
|---|
| 162 | this->burstSystem->addEmitter(this->burstEmitter[1]); |
|---|
| 163 | this->burstSystem->setName("SpaceShip_Burst_System"); |
|---|
| 164 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
|---|
| 165 | this->burstSystem->setLifeSpan(1.0, .3); |
|---|
| 166 | this->burstSystem->setRadius(0.0, 1.5); |
|---|
| 167 | this->burstSystem->setRadius(0.05, 1.8); |
|---|
| 168 | this->burstSystem->setRadius(.5, .8); |
|---|
| 169 | this->burstSystem->setRadius(1.0, 0); |
|---|
| 170 | this->burstSystem->setColor(0.0, .7,.7,1,.5); |
|---|
| 171 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
|---|
| 172 | this->burstSystem->setColor(0.5, .5,.5,.8,.3); |
|---|
| 173 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | //add events to the eventlist |
|---|
| 177 | registerEvent(KeyMapper::PEV_FORWARD); |
|---|
| 178 | registerEvent(KeyMapper::PEV_BACKWARD); |
|---|
| 179 | registerEvent(KeyMapper::PEV_LEFT); |
|---|
| 180 | registerEvent(KeyMapper::PEV_RIGHT); |
|---|
| 181 | registerEvent(KeyMapper::PEV_UP); |
|---|
| 182 | registerEvent(KeyMapper::PEV_DOWN); |
|---|
| 183 | registerEvent(KeyMapper::PEV_FIRE1); |
|---|
| 184 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
|---|
| 185 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
|---|
| 186 | registerEvent(EV_MOUSE_MOTION); |
|---|
| 187 | |
|---|
| 188 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
|---|
| 189 | |
|---|
| 190 | // WEAPON_MANAGER configuration |
|---|
| 191 | this->getWeaponManager()->setSlotCount(5); |
|---|
| 192 | |
|---|
| 193 | this->getWeaponManager()->setSlotPosition(0, Vector(-0.28, 1.186, -2.750), &this->wingNodeLeft); |
|---|
| 194 | this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
|---|
| 195 | |
|---|
| 196 | this->getWeaponManager()->setSlotPosition(1, Vector(-0.28, 1.186, 2.750), &this->wingNodeRight); |
|---|
| 197 | this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
|---|
| 198 | |
|---|
| 199 | this->getWeaponManager()->setSlotPosition(2, Vector(-1.63, .809, -.003)); |
|---|
| 200 | this->getWeaponManager()->setSlotCapability(2, WTYPE_HEAVY); |
|---|
| 201 | |
|---|
| 202 | /// TODO: THESE ARE TOO MUCH |
|---|
| 203 | this->getWeaponManager()->setSlotPosition(3, Vector(-1.63, .678, -.652)); |
|---|
| 204 | this->getWeaponManager()->setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0))); |
|---|
| 205 | |
|---|
| 206 | this->getWeaponManager()->setSlotPosition(4, Vector(-1.63, .678, .652)); |
|---|
| 207 | this->getWeaponManager()->setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); |
|---|
| 208 | |
|---|
| 209 | this->cameraNode.setRelCoor(1,5,0); |
|---|
| 210 | this->getWeaponManager()->getFixedTarget()->setParent(&this->cameraNode); |
|---|
| 211 | this->getWeaponManager()->getFixedTarget()->setRelCoor(1000,0,0); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | /** |
|---|
| 215 | * loads the Settings of a TurbineHover from an XML-element. |
|---|
| 216 | * @param root the XML-element to load the Spaceship's properties from |
|---|
| 217 | */ |
|---|
| 218 | void TurbineHover::loadParams(const TiXmlElement* root) |
|---|
| 219 | { |
|---|
| 220 | WorldEntity::loadParams(root); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | void TurbineHover::enter() |
|---|
| 225 | { |
|---|
| 226 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true); |
|---|
| 227 | |
|---|
| 228 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
|---|
| 229 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
|---|
| 230 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | void TurbineHover::leave() |
|---|
| 234 | { |
|---|
| 235 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
|---|
| 236 | this->detachCamera(); |
|---|
| 237 | |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | /** |
|---|
| 242 | * effect that occurs after the TurbineHover is spawned |
|---|
| 243 | */ |
|---|
| 244 | void TurbineHover::postSpawn () |
|---|
| 245 | { |
|---|
| 246 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | /** |
|---|
| 250 | * the action occuring if the turbine_hover left the game |
|---|
| 251 | */ |
|---|
| 252 | void TurbineHover::leftWorld () |
|---|
| 253 | {} |
|---|
| 254 | |
|---|
| 255 | /** |
|---|
| 256 | * this function is called, when two entities collide |
|---|
| 257 | * @param entity: the world entity with whom it collides |
|---|
| 258 | * |
|---|
| 259 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
|---|
| 260 | */ |
|---|
| 261 | void TurbineHover::collidesWith(WorldEntity* entity, const Vector& location) |
|---|
| 262 | { |
|---|
| 263 | Playable::collidesWith(entity, location); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | /** |
|---|
| 269 | * the function called for each passing timeSnap |
|---|
| 270 | * @param time The timespan passed since last update |
|---|
| 271 | */ |
|---|
| 272 | void TurbineHover::tick (float dt) |
|---|
| 273 | { |
|---|
| 274 | this->debugNode(1); |
|---|
| 275 | Playable::tick(dt); |
|---|
| 276 | |
|---|
| 277 | // spaceship controlled movement |
|---|
| 278 | this->movement(dt); |
|---|
| 279 | this->rotorCycle += this->rotorSpeed * dt; |
|---|
| 280 | |
|---|
| 281 | // TRYING TO FIX PNode. |
|---|
| 282 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
|---|
| 283 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * calculate the velocity |
|---|
| 288 | * @param time the timeslice since the last frame |
|---|
| 289 | */ |
|---|
| 290 | void TurbineHover::movement (float dt) |
|---|
| 291 | { |
|---|
| 292 | Vector accel(0.0, 0.0, 0.0); |
|---|
| 293 | float rotSpeed = .3; |
|---|
| 294 | |
|---|
| 295 | if( this->bForward ) |
|---|
| 296 | { |
|---|
| 297 | accel += Vector(this->acceleration, 0, 0); |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | if( this->bBackward ) |
|---|
| 301 | { |
|---|
| 302 | accel -= Vector(this->acceleration, 0, 0); |
|---|
| 303 | } |
|---|
| 304 | if( this->bLeft) |
|---|
| 305 | { |
|---|
| 306 | accel -= Vector(0, 0, this->acceleration); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | if( this->bRight) |
|---|
| 310 | { |
|---|
| 311 | accel += Vector(0, 0, this->acceleration); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | if (this->bAscend ) |
|---|
| 315 | { |
|---|
| 316 | accel += Vector(0, this->acceleration, 0); |
|---|
| 317 | } |
|---|
| 318 | if (this->bDescend ) |
|---|
| 319 | { |
|---|
| 320 | accel -= Vector(0, this->acceleration, 0); |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
|---|
| 324 | |
|---|
| 325 | // this is the air friction (necessary for a smooth control) |
|---|
| 326 | Vector damping = (this->velocity * this->airFriction); |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | this->velocity += (accelerationDir - damping)* dt; |
|---|
| 330 | |
|---|
| 331 | this->shiftCoor (this->velocity * dt); |
|---|
| 332 | this->rotation = 0.0f; |
|---|
| 333 | |
|---|
| 334 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
|---|
| 335 | |
|---|
| 336 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
|---|
| 337 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); |
|---|
| 338 | |
|---|
| 339 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
|---|
| 340 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | void TurbineHover::draw() const |
|---|
| 345 | { |
|---|
| 346 | Vector tmpRot; |
|---|
| 347 | WorldEntity::draw(); |
|---|
| 348 | |
|---|
| 349 | glPushMatrix(); |
|---|
| 350 | /// LEFT SIDE |
|---|
| 351 | glTranslatef (this->wingNodeLeft.getAbsCoor ().x, |
|---|
| 352 | this->wingNodeLeft.getAbsCoor ().y, |
|---|
| 353 | this->wingNodeLeft.getAbsCoor ().z); |
|---|
| 354 | tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis(); |
|---|
| 355 | glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 356 | this->getModel(3)->draw(); |
|---|
| 357 | glPopMatrix (); |
|---|
| 358 | |
|---|
| 359 | glPushMatrix(); |
|---|
| 360 | glTranslatef (this->rotorNodeLeft.getAbsCoor ().x, |
|---|
| 361 | this->rotorNodeLeft.getAbsCoor ().y, |
|---|
| 362 | this->rotorNodeLeft.getAbsCoor ().z); |
|---|
| 363 | tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis(); |
|---|
| 364 | glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 365 | this->getModel(4)->draw(); |
|---|
| 366 | glRotatef(this->rotorCycle, 0,1,0); |
|---|
| 367 | this->getModel(5)->draw(); |
|---|
| 368 | glPopMatrix (); |
|---|
| 369 | |
|---|
| 370 | /// RIGHT SIDE |
|---|
| 371 | glPushMatrix(); |
|---|
| 372 | glTranslatef (this->wingNodeRight.getAbsCoor ().x, |
|---|
| 373 | this->wingNodeRight.getAbsCoor ().y, |
|---|
| 374 | this->wingNodeRight.getAbsCoor ().z); |
|---|
| 375 | tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis(); |
|---|
| 376 | glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 377 | glScalef(1,1,-1); |
|---|
| 378 | this->getModel(3)->draw(); |
|---|
| 379 | glPopMatrix (); |
|---|
| 380 | |
|---|
| 381 | glPushMatrix(); |
|---|
| 382 | glTranslatef (this->rotorNodeRight.getAbsCoor ().x, |
|---|
| 383 | this->rotorNodeRight.getAbsCoor ().y, |
|---|
| 384 | this->rotorNodeRight.getAbsCoor ().z); |
|---|
| 385 | tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis(); |
|---|
| 386 | glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 387 | glScalef(1,1,-1); |
|---|
| 388 | this->getModel(4)->draw(); |
|---|
| 389 | glRotatef(this->rotorCycle, 0,1,0); |
|---|
| 390 | this->getModel(5)->draw(); |
|---|
| 391 | glPopMatrix (); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | /** |
|---|
| 395 | * @todo switch statement ?? |
|---|
| 396 | */ |
|---|
| 397 | void TurbineHover::process(const Event &event) |
|---|
| 398 | { |
|---|
| 399 | Playable::process(event); |
|---|
| 400 | |
|---|
| 401 | if( event.type == KeyMapper::PEV_LEFT) |
|---|
| 402 | this->bLeft = event.bPressed; |
|---|
| 403 | else if( event.type == KeyMapper::PEV_RIGHT) |
|---|
| 404 | this->bRight = event.bPressed; |
|---|
| 405 | else if( event.type == KeyMapper::PEV_UP) |
|---|
| 406 | this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); |
|---|
| 407 | else if( event.type == KeyMapper::PEV_DOWN) |
|---|
| 408 | this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); |
|---|
| 409 | else if( event.type == KeyMapper::PEV_FORWARD) |
|---|
| 410 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
|---|
| 411 | else if( event.type == KeyMapper::PEV_BACKWARD) |
|---|
| 412 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
|---|
| 413 | else if( event.type == EV_MOUSE_MOTION) |
|---|
| 414 | { |
|---|
| 415 | float xMouse, yMouse; |
|---|
| 416 | xMouse = event.xRel*mouseSensitivity; |
|---|
| 417 | yMouse = event.yRel*mouseSensitivity; |
|---|
| 418 | |
|---|
| 419 | // rotate the Player around the y-axis |
|---|
| 420 | this->direction *= Quaternion(-M_PI/4.0*xMouse, Vector(0,1,0)); |
|---|
| 421 | this->rotation += xMouse; |
|---|
| 422 | |
|---|
| 423 | this->cameraLook += yMouse; |
|---|
| 424 | // rotate the Camera around the z-axis |
|---|
| 425 | if (cameraLook > M_PI_4) |
|---|
| 426 | cameraLook = M_PI_4; |
|---|
| 427 | else if (cameraLook < -M_PI_4) |
|---|
| 428 | cameraLook = -M_PI_4; |
|---|
| 429 | //this->cameraNode.setRelDirSoft(this->direction,10); |
|---|
| 430 | } |
|---|
| 431 | } |
|---|