Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2005, 5:51:54 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk:
merged spaceshipcontrol back to the trunk
merged with command:
svn merge -r5915:HEAD spaceshipcontrol/ ../trunk/
no conflicts (nice work guys :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/space_ships/space_ship.cc

    r5915 r5978  
    3030#include "factory.h"
    3131#include "key_mapper.h"
     32#include "event_handler.h"
     33
     34#include "graphics_engine.h"
    3235
    3336using namespace std;
     
    109112  PRINTF(4)("SPACESHIP INIT\n");
    110113
    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;
    113117  bFire = false;
     118  xMouse = yMouse = 0;
     119  mouseSensitivity = 0.001;
     120 
     121  cycle = 0.0;
     122 
    114123
    115124  travelSpeed = 15.0;
     
    123132
    124133  //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);
    129140  registerEvent(KeyMapper::PEV_FIRE1);
    130141  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     
    132143  registerEvent(SDLK_PAGEUP);
    133144  registerEvent(SDLK_PAGEDOWN);
     145  registerEvent(EV_MOUSE_MOTION);
    134146
    135147  this->getWeaponManager()->setSlotCount(7);
     
    252264void SpaceShip::tick (float time)
    253265{
     266     cycle += time;
    254267  // spaceship controlled movement
    255268  this->calculateVelocity(time);
     
    258271
    259272  //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);
    260280
    261281  this->shiftCoor (move);
     
    280300  if( this->bUp )
    281301   {
    282      this->shiftCoor(this->getAbsDirX());
    283       //if(travelSpeed <= 5000)  travelSpeed += 10;
     302     //this->shiftCoor(this->getAbsDirX());
     303      accel += (this->getAbsDirX())*2;
    284304   }
    285305
    286306  if( this->bDown )
    287307   {
    288      this->shiftCoor(Vector()-this->getAbsDirX());
    289      //if(travelSpeed >= 10) travelSpeed -= 10;
     308     //this->shiftCoor((this->getAbsDirX())*-1);
     309     accel -= (this->getAbsDirX())*2;
    290310   }
    291311
     
    307327    //rotVal += .4;
    308328  }
     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  }
    309347  if (this->bAscend )
    310348  {
     
    326364  }
    327365
    328   velocity += accel*(time);
     366  velocity += accel;
    329367  //rot.normalize();
    330368  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
     
    347385void SpaceShip::process(const Event &event)
    348386{
    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;
    357393  else if( event.type == KeyMapper::PEV_FIRE1)
    358394      this->bFire = event.bPressed;
     
    362398    this->getWeaponManager()->previousWeaponConfig();
    363399
    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  }
    368410}
    369411
Note: See TracChangeset for help on using the changeset viewer.