Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2006, 2:19:46 PM (18 years ago)
Author:
patrick
Message:

branches: removed spaceshipcontrol branche

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r6688 r6693  
    128128  this->addWeapon(cannon, 0, 6);
    129129
    130   //this->addWeapon(turret, 3, 0);
    131 
    132130  this->getWeaponManager()->changeWeaponConfig(1);
    133131
     
    137135  bFire = false;
    138136  xMouse = yMouse = 0;
     137  yInvert = 1;
    139138  mouseSensitivity = 0.001;
    140   airViscosity = 1.0;
    141   cycle = 0.0;
     139  airViscosity = 0.05;
     140  controlVelocityX = 25;
     141  controlVelocityY = 150;
     142  shipInertia = 0.5             ;
     143//  cycle = 0.0;
    142144
    143145  this->setMaxEnergy(100);
    144146  this->setEnergy(80);
    145147
    146   travelSpeed = 15.0;
    147   this->velocity = Vector(0.0,0.0,0.0);
     148  travelSpeed = 40.0;
     149  acceleration = 3;
     150  this->velocity = this->getAbsDirX()*travelSpeed;
    148151  this->mouseDir = this->getAbsDir();
     152  this->pitchDir = this->getAbsDir();
    149153
    150154//   GLGuiButton* button = new GLGuiPushButton();
     
    160164
    161165  //add events to the eventlist
    162   registerEvent(SDLK_w);
    163   registerEvent(SDLK_s);
    164   registerEvent(SDLK_a);
    165   registerEvent(SDLK_d);
    166   registerEvent(SDLK_q);
    167   registerEvent(SDLK_e);
     166  registerEvent(KeyMapper::PEV_UP);
     167  registerEvent(KeyMapper::PEV_DOWN);
     168  registerEvent(KeyMapper::PEV_LEFT);
     169  registerEvent(KeyMapper::PEV_RIGHT);
     170  //registerEvent(SDLK_q);
     171  //registerEvent(SDLK_e);
    168172  registerEvent(KeyMapper::PEV_FIRE1);
    169173  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    170174  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
    171   registerEvent(SDLK_PAGEUP);
    172   registerEvent(SDLK_PAGEDOWN);
     175  //registerEvent(SDLK_PAGEUP);
     176  //registerEvent(SDLK_PAGEDOWN);
    173177  registerEvent(EV_MOUSE_MOTION);
    174178
     
    285289  this->weaponAction();
    286290
     291  if( xMouse != 0 || yMouse != 0)
     292   {
     293    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
     294    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
     295    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
     296    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
     297
     298    pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
     299
     300    mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
     301    xMouse = yMouse = 0;
     302   }
     303
     304
    287305//   if( this != State::getPlayer()->getControllable())
    288306//     return;
     
    291309  this->calculateVelocity(time);
    292310
    293   Vector move = (velocity)*time;
     311  Vector move = velocity*time;
    294312
    295313  //orient the velocity in the direction of the spaceship.
     
    299317
    300318  //orient the spaceship in direction of the mouse
    301    rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*3.0);
     319   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*shipInertia);
    302320   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
    303321    this->setAbsDir( rotQuat);
     
    305323
    306324  // this is the air friction (necessary for a smooth control)
    307   if(velocity.len() != 0) velocity -= velocity*0.01;
     325  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
     326  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
     327
     328  //other physics (gravity)
     329  //if(travelSpeed < 120)
     330  //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
    308331
    309332  //hoover effect
     
    312335
    313336  //readjust
    314 
    315   /*
    316     In the game "Yager" the spaceship gets readjusted when the player moves the mouse.
    317     I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox.
    318   */
    319   //if (xMouse != 0 && yMouse != 0)
    320 
    321337  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
    322338  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
     
    324340  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    325341
    326   this->shiftCoor (move);
     342  this->shiftCoor(move);
    327343
    328344
     
    343359  /* calculate the direction in which the craft is heading  */
    344360
    345   Plane plane(Vector(0,1,0), Vector(0,0,0));
     361  //Plane plane(Vector(0,1,0), Vector(0,0,0));
    346362
    347363  if( this->bUp )
    348364   {
    349365     //this->shiftCoor(this->getAbsDirX());
    350       accel += (this->getAbsDirX())*2;
    351 
    352       /* Heli-Steuerung
    353          accel += (this->getAbsDirX()*2;
    354          if(
    355       */
     366      //accel += (this->getAbsDirX())*2;
     367      accel += (this->getAbsDirX())*acceleration;
     368
    356369   }
    357370
     
    359372   {
    360373     //this->shiftCoor((this->getAbsDirX())*-1);
    361      accel -= (this->getAbsDirX())*2;
     374     //accel -= (this->getAbsDirX())*2;
     375     accel -= (this->getAbsDirX())*0.5*acceleration;
    362376   }
    363377
     
    383397  if( this->bRollL /* > -this->getRelCoor().z*2*/)
    384398  {
    385     mouseDir *= Quaternion(-time, Vector(1,0,0));
     399    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
    386400//    accel -= rightDirection;
    387401    //velocityDir.normalize();
     
    391405  if( this->bRollR /* > this->getRelCoor().z*2*/)
    392406  {
    393     mouseDir *= Quaternion(time, Vector(1,0,0));
     407    mouseDir *= Quaternion(time*2, Vector(1,0,0));
    394408
    395409    //    accel += rightDirection;
     
    438452void SpaceShip::process(const Event &event)
    439453{
    440 
    441 
    442   if( event.type == SDLK_a)
     454  if( event.type == KeyMapper::PEV_LEFT)
    443455      this->bRollL = event.bPressed;
    444   else if( event.type == SDLK_d)
     456  else if( event.type == KeyMapper::PEV_RIGHT)
    445457      this->bRollR = event.bPressed;
    446458  else if( event.type == KeyMapper::PEV_FIRE1)
     
    452464  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    453465    this->previousWeaponConfig();
    454   else if( event.type == SDLK_w)
     466  else if( event.type == KeyMapper::PEV_UP)
    455467    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
    456   else if( event.type == SDLK_s)
     468  else if( event.type == KeyMapper::PEV_DOWN)
    457469    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
    458470  else if( event.type == EV_MOUSE_MOTION)
    459471  {
    460     this->xMouse = event.xRel;
    461     this->yMouse = event.yRel;
    462     mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));
    463    // if( xMouse*xMouse + yMouse*yMouse < 0.9)
    464      //this->setAbsDir(mouseDir);
     472    this->xMouse += event.xRel;
     473    this->yMouse += event.yRel;
    465474  }
    466475}
Note: See TracChangeset for help on using the changeset viewer.