Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5964 in orxonox.OLD


Ignore:
Timestamp:
Dec 7, 2005, 3:43:01 PM (19 years ago)
Author:
bknecht
Message:

Mousecontrol implemented! Mousesensitivity implemented! Mouse is grabbed! Control works fine

Location:
branches/spaceshipcontrol/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/spaceshipcontrol/src/lib/event/event_handler.cc

    r5786 r5964  
    4747  this->flush(ES_ALL);
    4848  this->withUNICODE(false);
     49  this->grabEvents(false);
    4950
    5051  this->state = ES_GAME;
     
    255256}
    256257
     258void EventHandler::grabEvents(bool grabEvents)
     259{
     260     this->eventsGrabbed = grabEvents;
     261     if(!grabEvents)
     262      SDL_WM_GrabInput(SDL_GRAB_OFF);
     263     else
     264      SDL_WM_GrabInput(SDL_GRAB_ON);
     265}
    257266
    258267/**
  • branches/spaceshipcontrol/src/lib/event/event_handler.h

    r5786 r5964  
    4343
    4444  void withUNICODE(bool enableUNICODE);
     45  void grabEvents(bool grabEvents);
    4546
    4647  void process();
     
    6263
    6364  bool                       bUNICODE;                        //!< If unicode should be enabled.
     65  bool                       eventsGrabbed;                   //!< If the events should be grabbed
    6466};
    6567
  • branches/spaceshipcontrol/src/world_entities/space_ships/space_ship.cc

    r5928 r5964  
    3131#include "key_mapper.h"
    3232#include "event_handler.h"
     33
     34#include "graphics_engine.h"
    3335
    3436using namespace std;
     
    110112  PRINTF(4)("SPACESHIP INIT\n");
    111113
    112 
    113   bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     114  EventHandler::getInstance()->grabEvents(true);
     115
     116  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    114117  bFire = false;
     118  xMouse = yMouse = 0;
     119  mouseSensitivity = 0.001;
     120 
     121 
     122 
    115123
    116124  travelSpeed = 15.0;
     
    124132
    125133  //add events to the eventlist
    126   registerEvent(KeyMapper::PEV_UP);
    127   registerEvent(KeyMapper::PEV_DOWN);
    128   registerEvent(KeyMapper::PEV_LEFT);
    129   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);
    130140  registerEvent(KeyMapper::PEV_FIRE1);
    131141  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     
    262272 
    263273  // this is the air friction (necessary for a smooth control)
    264   if(velocity.len() != 0) velocity -= velocity*0.005;
    265  
    266   this->shiftDir(Quaternion(-M_PI/4*xMouse*time/5, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*time/5, Vector(0,0,1)));
     274  if(velocity.len() != 0) velocity -= velocity*0.01;
     275 
     276  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    267277
    268278  this->shiftCoor (move);
     
    288298   {
    289299     //this->shiftCoor(this->getAbsDirX());
    290       accel += this->getAbsDirX();
     300      accel += (this->getAbsDirX())*2;
    291301   }
    292302
     
    294304   {
    295305     //this->shiftCoor((this->getAbsDirX())*-1);
    296      accel -= this->getAbsDirX();
     306     accel -= (this->getAbsDirX())*2;
    297307   }
    298308
     
    308318  {
    309319    this->shiftDir(Quaternion(-time, Vector(0,1,0)));
     320
     321    //    accel += rightDirection;
     322    //velocityDir.normalize();
     323    //rot += Vector(1,0,0);
     324    //rotVal += .4;
     325  }
     326 
     327  if( this->bRollL /* > -this->getRelCoor().z*2*/)
     328  {
     329    this->shiftDir(Quaternion(-time, Vector(1,0,0)));
     330//    accel -= rightDirection;
     331    //velocityDir.normalize();
     332    //rot +=Vector(1,0,0);
     333    //rotVal -= .4;
     334  }
     335  if( this->bRollR /* > this->getRelCoor().z*2*/)
     336  {
     337    this->shiftDir(Quaternion(time, Vector(1,0,0)));
    310338
    311339    //    accel += rightDirection;
     
    354382void SpaceShip::process(const Event &event)
    355383{
    356   if( event.type == KeyMapper::PEV_UP)
    357       this->bUp = event.bPressed;
    358   else if( event.type == KeyMapper::PEV_DOWN)
    359       this->bDown = event.bPressed;
    360   else if( event.type == KeyMapper::PEV_RIGHT)
    361       this->bRight= event.bPressed;
    362   else if( event.type == KeyMapper::PEV_LEFT)
    363       this->bLeft = event.bPressed;
     384 
     385 
     386  if( event.type == SDLK_a)
     387      this->bRollL = event.bPressed;
     388  else if( event.type == SDLK_d)
     389      this->bRollR = event.bPressed;
    364390  else if( event.type == KeyMapper::PEV_FIRE1)
    365391      this->bFire = event.bPressed;
     
    369395    this->getWeaponManager()->previousWeaponConfig();
    370396
    371   else if( event.type == SDLK_PAGEUP)
    372     this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
    373   else if( event.type == SDLK_PAGEDOWN)
    374     this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
     397  else if( event.type == SDLK_w)
     398    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
     399  else if( event.type == SDLK_s)
     400    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
    375401  else if( event.type == EV_MOUSE_MOTION)
    376402  {
    377403    this->xMouse = event.xRel;
    378404    this->yMouse = event.yRel;
     405    this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));
    379406  }
    380407}
  • branches/spaceshipcontrol/src/world_entities/space_ships/space_ship.h

    r5921 r5964  
    5555    bool                  bDescend;           //!< descend button presses.
    5656    bool                  bFire;              //!< fire button pressed.
     57    bool                  bRollL;             //!< rolling button pressed (left)
     58    bool                  bRollR;             //!< rolling button pressed (right)
    5759   
    5860    float                 xMouse;             //!< mouse moved in x-Direction
    5961    float                 yMouse;             //!< mouse moved in y-Direction
     62    float                 mouseSensitivity;   //!< the mouse sensitivity
    6063
    6164    Vector                velocity;           //!< the velocity of the player.
  • branches/spaceshipcontrol/src/world_entities/weapons/crosshair.cc

    r5921 r5964  
    122122  if  (event.type == EV_MOUSE_MOTION)
    123123  {
    124     this->setAbsCoor2D(event.x, event.y);
     124    //this->setAbsCoor2D(event.x, event.y);
    125125  }
    126126}
     
    157157               &objZ );
    158158
    159   this->setAbsCoor(objX, objY, objZ);
     159  //this->setAbsCoor(objX, objY, objZ);
    160160}
    161161
Note: See TracChangeset for help on using the changeset viewer.