Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 21, 2006, 1:27:29 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the SpaceShipControl branche back to the trunk

merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/spaceshipcontrol . -r6482:HEAD

minor conflicts, and added file hover.cc/h to the Makefile.

File:
1 edited

Legend:

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

    r6634 r6637  
    132132  bFire = false;
    133133  xMouse = yMouse = 0;
     134  yInvert = 1;
    134135  mouseSensitivity = 0.001;
    135   airViscosity = 1.0;
    136   cycle = 0.0;
     136  airViscosity = 0.01;
     137  controlVelocityX = 25;
     138  controlVelocityY = 150;
     139  shipInertia = 0.5             ;
     140//  cycle = 0.0;
    137141
    138142  this->setMaxEnergy(100);
    139143  this->setEnergy(80);
    140144
    141   travelSpeed = 15.0;
    142   this->velocity = Vector(0.0,0.0,0.0);
     145  travelSpeed = 40.0;
     146  acceleration = 3;
     147  this->velocity = this->getAbsDirX()*travelSpeed;
    143148  this->mouseDir = this->getAbsDir();
     149  this->pitchDir = this->getAbsDir();
    144150
    145151//   GLGuiButton* button = new GLGuiPushButton();
     
    155161
    156162  //add events to the eventlist
    157   registerEvent(SDLK_w);
    158   registerEvent(SDLK_s);
    159   registerEvent(SDLK_a);
    160   registerEvent(SDLK_d);
    161   registerEvent(SDLK_q);
    162   registerEvent(SDLK_e);
     163  registerEvent(KeyMapper::PEV_UP);
     164  registerEvent(KeyMapper::PEV_DOWN);
     165  registerEvent(KeyMapper::PEV_LEFT);
     166  registerEvent(KeyMapper::PEV_RIGHT);
     167  //registerEvent(SDLK_q);
     168  //registerEvent(SDLK_e);
    163169  registerEvent(KeyMapper::PEV_FIRE1);
    164170  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    165171  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
    166   registerEvent(SDLK_PAGEUP);
    167   registerEvent(SDLK_PAGEDOWN);
     172  //registerEvent(SDLK_PAGEUP);
     173  //registerEvent(SDLK_PAGEDOWN);
    168174  registerEvent(EV_MOUSE_MOTION);
    169175
     
    279285  this->weaponAction();
    280286
     287  if( xMouse != 0 || yMouse != 0)
     288   {
     289    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
     290    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
     291    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
     292    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
     293   
     294    pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
     295   
     296    mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
     297    xMouse = yMouse = 0;
     298   }
     299
     300
    281301//   if( this != State::getPlayer()->getControllable())
    282302//     return;
     
    285305  this->calculateVelocity(time);
    286306
    287   Vector move = (velocity)*time;
    288 
     307  Vector move = velocity*time;
     308 
    289309  //orient the velocity in the direction of the spaceship.
    290310  travelSpeed = velocity.len();
     
    293313
    294314  //orient the spaceship in direction of the mouse
    295    rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*3.0);
     315   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*shipInertia);
    296316   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
    297317    this->setAbsDir( rotQuat);
     
    299319
    300320  // this is the air friction (necessary for a smooth control)
    301   if(velocity.len() != 0) velocity -= velocity*0.01;
    302 
     321  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
     322  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
     323 
     324  //other physics (gravity)
     325  if(travelSpeed < 120)
     326  move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
     327   
    303328  //hoover effect
    304329  //cycle += time;
     
    306331
    307332  //readjust
    308 
    309   /*
    310     In the game "Yager" the spaceship gets readjusted when the player moves the mouse.
    311     I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox.
    312   */
    313   //if (xMouse != 0 && yMouse != 0)
    314 
    315333  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
    316334  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
     
    318336  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    319337
    320   this->shiftCoor (move);
     338  this->shiftCoor(move);
    321339
    322340
     
    337355  /* calculate the direction in which the craft is heading  */
    338356
    339   Plane plane(Vector(0,1,0), Vector(0,0,0));
     357  //Plane plane(Vector(0,1,0), Vector(0,0,0));
    340358
    341359  if( this->bUp )
    342360   {
    343361     //this->shiftCoor(this->getAbsDirX());
    344       accel += (this->getAbsDirX())*2;
    345 
    346       /* Heli-Steuerung
    347          accel += (this->getAbsDirX()*2;
    348          if(
    349       */
     362      //accel += (this->getAbsDirX())*2;
     363      accel += (this->getAbsDirX())*acceleration;
     364
    350365   }
    351366
     
    353368   {
    354369     //this->shiftCoor((this->getAbsDirX())*-1);
    355      accel -= (this->getAbsDirX())*2;
     370     //accel -= (this->getAbsDirX())*2;
     371     accel -= (this->getAbsDirX())*0.5*acceleration;
    356372   }
    357373
     
    377393  if( this->bRollL /* > -this->getRelCoor().z*2*/)
    378394  {
    379     mouseDir *= Quaternion(-time, Vector(1,0,0));
     395    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
    380396//    accel -= rightDirection;
    381397    //velocityDir.normalize();
     
    385401  if( this->bRollR /* > this->getRelCoor().z*2*/)
    386402  {
    387     mouseDir *= Quaternion(time, Vector(1,0,0));
     403    mouseDir *= Quaternion(time*2, Vector(1,0,0));
    388404
    389405    //    accel += rightDirection;
     
    432448void SpaceShip::process(const Event &event)
    433449{
    434 
    435 
    436   if( event.type == SDLK_a)
     450  if( event.type == KeyMapper::PEV_LEFT)
    437451      this->bRollL = event.bPressed;
    438   else if( event.type == SDLK_d)
     452  else if( event.type == KeyMapper::PEV_RIGHT)
    439453      this->bRollR = event.bPressed;
    440454  else if( event.type == KeyMapper::PEV_FIRE1)
     
    446460  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    447461    this->previousWeaponConfig();
    448   else if( event.type == SDLK_w)
     462  else if( event.type == KeyMapper::PEV_UP)
    449463    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
    450   else if( event.type == SDLK_s)
     464  else if( event.type == KeyMapper::PEV_DOWN)
    451465    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
    452466  else if( event.type == EV_MOUSE_MOTION)
    453467  {
    454     this->xMouse = event.xRel;
    455     this->yMouse = event.yRel;
    456     mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));
    457    // if( xMouse*xMouse + yMouse*yMouse < 0.9)
    458      //this->setAbsDir(mouseDir);
     468    this->xMouse += event.xRel;
     469    this->yMouse += event.yRel;
    459470  }
    460471}
Note: See TracChangeset for help on using the changeset viewer.