Changeset 5978 in orxonox.OLD for trunk/src/world_entities/space_ships
- Timestamp:
- Dec 7, 2005, 5:51:54 PM (19 years ago)
- Location:
- trunk/src/world_entities/space_ships
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/space_ships/space_ship.cc
r5915 r5978 30 30 #include "factory.h" 31 31 #include "key_mapper.h" 32 #include "event_handler.h" 33 34 #include "graphics_engine.h" 32 35 33 36 using namespace std; … … 109 112 PRINTF(4)("SPACESHIP INIT\n"); 110 113 111 112 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 114 EventHandler::getInstance()->grabEvents(true); 115 116 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; 113 117 bFire = false; 118 xMouse = yMouse = 0; 119 mouseSensitivity = 0.001; 120 121 cycle = 0.0; 122 114 123 115 124 travelSpeed = 15.0; … … 123 132 124 133 //add events to the eventlist 125 registerEvent(KeyMapper::PEV_UP); 126 registerEvent(KeyMapper::PEV_DOWN); 127 registerEvent(KeyMapper::PEV_LEFT); 128 registerEvent(KeyMapper::PEV_RIGHT); 134 registerEvent(SDLK_w); 135 registerEvent(SDLK_s); 136 registerEvent(SDLK_a); 137 registerEvent(SDLK_d); 138 registerEvent(SDLK_q); 139 registerEvent(SDLK_e); 129 140 registerEvent(KeyMapper::PEV_FIRE1); 130 141 registerEvent(KeyMapper::PEV_NEXT_WEAPON); … … 132 143 registerEvent(SDLK_PAGEUP); 133 144 registerEvent(SDLK_PAGEDOWN); 145 registerEvent(EV_MOUSE_MOTION); 134 146 135 147 this->getWeaponManager()->setSlotCount(7); … … 252 264 void SpaceShip::tick (float time) 253 265 { 266 cycle += time; 254 267 // spaceship controlled movement 255 268 this->calculateVelocity(time); … … 258 271 259 272 //orient the spaceship model in the direction of movement. 273 274 // this is the air friction (necessary for a smooth control) 275 if(velocity.len() != 0) velocity -= velocity*0.01; 276 277 this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); 278 279 //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); 260 280 261 281 this->shiftCoor (move); … … 280 300 if( this->bUp ) 281 301 { 282 this->shiftCoor(this->getAbsDirX());283 //if(travelSpeed <= 5000) travelSpeed += 10;302 //this->shiftCoor(this->getAbsDirX()); 303 accel += (this->getAbsDirX())*2; 284 304 } 285 305 286 306 if( this->bDown ) 287 307 { 288 this->shiftCoor(Vector()-this->getAbsDirX());289 //if(travelSpeed >= 10) travelSpeed -= 10;308 //this->shiftCoor((this->getAbsDirX())*-1); 309 accel -= (this->getAbsDirX())*2; 290 310 } 291 311 … … 307 327 //rotVal += .4; 308 328 } 329 330 if( this->bRollL /* > -this->getRelCoor().z*2*/) 331 { 332 this->shiftDir(Quaternion(-time, Vector(1,0,0))); 333 // accel -= rightDirection; 334 //velocityDir.normalize(); 335 //rot +=Vector(1,0,0); 336 //rotVal -= .4; 337 } 338 if( this->bRollR /* > this->getRelCoor().z*2*/) 339 { 340 this->shiftDir(Quaternion(time, Vector(1,0,0))); 341 342 // accel += rightDirection; 343 //velocityDir.normalize(); 344 //rot += Vector(1,0,0); 345 //rotVal += .4; 346 } 309 347 if (this->bAscend ) 310 348 { … … 326 364 } 327 365 328 velocity += accel *(time);366 velocity += accel; 329 367 //rot.normalize(); 330 368 //this->setRelDirSoft(Quaternion(rotVal, rot), 5); … … 347 385 void SpaceShip::process(const Event &event) 348 386 { 349 if( event.type == KeyMapper::PEV_UP) 350 this->bUp = event.bPressed; 351 else if( event.type == KeyMapper::PEV_DOWN) 352 this->bDown = event.bPressed; 353 else if( event.type == KeyMapper::PEV_RIGHT) 354 this->bRight= event.bPressed; 355 else if( event.type == KeyMapper::PEV_LEFT) 356 this->bLeft = event.bPressed; 387 388 389 if( event.type == SDLK_a) 390 this->bRollL = event.bPressed; 391 else if( event.type == SDLK_d) 392 this->bRollR = event.bPressed; 357 393 else if( event.type == KeyMapper::PEV_FIRE1) 358 394 this->bFire = event.bPressed; … … 362 398 this->getWeaponManager()->previousWeaponConfig(); 363 399 364 else if( event.type == SDLK_PAGEUP) 365 this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); 366 else if( event.type == SDLK_PAGEDOWN) 367 this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); 400 else if( event.type == SDLK_w) 401 this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); 402 else if( event.type == SDLK_s) 403 this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); 404 else if( event.type == EV_MOUSE_MOTION) 405 { 406 this->xMouse = event.xRel; 407 this->yMouse = event.yRel; 408 this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); 409 } 368 410 } 369 411 -
trunk/src/world_entities/space_ships/space_ship.h
r5915 r5978 55 55 bool bDescend; //!< descend button presses. 56 56 bool bFire; //!< fire button pressed. 57 bool bRollL; //!< rolling button pressed (left) 58 bool bRollR; //!< rolling button pressed (right) 59 60 float xMouse; //!< mouse moved in x-Direction 61 float yMouse; //!< mouse moved in y-Direction 62 float mouseSensitivity; //!< the mouse sensitivity 63 float cycle; //!< hovercycle 57 64 58 65 Vector velocity; //!< the velocity of the player.
Note: See TracChangeset
for help on using the changeset viewer.