Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 28, 2006, 2:57:27 PM (18 years ago)
Author:
bensch
Message:

trunk: hover optimize

File:
1 edited

Legend:

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

    r6806 r6807  
    9999  this->setClassID(CL_HOVER, "Hover");
    100100
    101   PRINTF(4)("HOVER INIT\n");
    102 
    103   this->loadModel("models/ships/hover_#.obj", 1.0);
    104 
    105   EventHandler::getInstance()->grabEvents(true);
     101  this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3);
     102  this->loadModel("models/ships/hoverglider_rotor.obj", 1.0f, 4);
     103  this->loadModel("models/ships/rotor.obj", .45f, 5);
    106104
    107105  bForward = bBackward = bLeft = bRight = bAscend = bDescend = false;
    108   xMouse = yMouse = 0;
    109   mouseSensitivity = 0.05;
    110   controlVelocityX = 100;
    111   controlVelocityY = 100;
     106  mouseSensitivity = 0.005;
    112107
    113108  this->rotorSpeed = 1000.0f;
    114109  this->rotorCycle = 0.0f;
     110  this->cameraLook = 0.0f;
     111  this->rotation = 0.0f;
    115112
    116113  // camera - issue
     
    138135  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
    139136
    140   this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3);
    141   this->loadModel("models/ships/hoverglider_rotor.obj", 1.0f, 4);
    142   this->loadModel("models/ships/rotor.obj", .45f, 5);
    143137
    144138  //add events to the eventlist
     
    177171  this->getWeaponManager()->setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0)));
    178172
    179   this->getWeaponManager()->getFixedTarget()->setParent(&(this->cameraNode));
     173  this->cameraNode.setRelCoor(1,5,0);
     174  this->getWeaponManager()->getFixedTarget()->setParent(&this->cameraNode);
     175  this->getWeaponManager()->getFixedTarget()->setRelCoor(1000,0,0);
    180176}
    181177
     
    192188{
    193189  State::getCamera()->setParentSoft(&this->cameraNode);
    194   State::getCameraTarget()->setParentSoft(this->getWeaponManager()->getFixedTarget());
    195 
     190  State::getCamera()->setRelCoorSoft(-10, 0,0);
     191  State::getCameraTarget()->setParentSoft(&this->cameraNode);
    196192}
    197193
     
    234230 */
    235231void Hover::collidesWith(WorldEntity* entity, const Vector& location)
    236 {
    237 }
     232{}
    238233
    239234
     
    246241{
    247242  Playable::tick(dt);
    248 
    249   if( xMouse != 0 || yMouse != 0)
    250   {
    251     if (xMouse > controlVelocityX) xMouse = controlVelocityX;
    252     else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
    253     if (yMouse > controlVelocityY) yMouse = controlVelocityY;
    254     else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
    255   }
    256243
    257244  // spaceship controlled movement
     
    262249
    263250  // this is the air friction (necessary for a smooth control)
    264   if(velocity.len() != 0) velocity -= velocity*0.1;
    265     this->shiftCoor (move);
    266 
     251  if(velocity.len() != 0)
     252    velocity -= velocity*0.1;
     253  this->shiftCoor (move);
     254
     255  this->rotation = 0.0f;
    267256}
    268257
     
    276265  float rotVal = .3;
    277266
    278   if( this->bForward )  {
     267  if( this->bForward ) {
    279268    accel += Vector(rotVal, 0, 0);
    280269  }
    281270
    282271  if( this->bBackward ) {
    283       accel -= Vector(rotVal,0,0);
     272    accel -= Vector(rotVal,0,0);
    284273  }
    285274  if( this->bLeft) {
    286275    accel -= Vector(0,0,rotVal);
    287276  }
     277
    288278  if( this->bRight) {
    289279    accel += Vector(0,0,rotVal);
     
    293283    accel += Vector(0,rotVal,0);
    294284  }
    295   if (this->bDescend )
    296     accel -= Vector(0,rotVal,0);
     285  if (this->bDescend ) {
     286       accel -= Vector(0,rotVal,0);
     287  }
    297288
    298289  velocity += accel * 3.0;
     
    300291  this->setRelDirSoft(this->direction * Quaternion(-accel.x, Vector(0,0,1)) * Quaternion(accel.z, Vector(1,0,0)), 5);
    301292
    302   this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z, Vector(1,0,0)), 10);
    303   this->rotorNodeLeft.setRelDirSoft(Quaternion(-2.0*accel.x, Vector(0,0,1)), 10);
    304 
    305   this->wingNodeRight.setRelDirSoft(Quaternion(accel.z, Vector(1,0,0)), 10);
    306   this->rotorNodeRight.setRelDirSoft(Quaternion(-2.0*accel.x, Vector(0,0,1)), 10);
     293  this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z+this->rotation, Vector(1,0,0)), 10);
     294  this->rotorNodeLeft.setRelDirSoft(Quaternion(-2.0*accel.x+this->rotation, Vector(0,0,1)), 10);
     295
     296  this->wingNodeRight.setRelDirSoft(Quaternion(accel.z+this->rotation, Vector(1,0,0)), 10);
     297  this->rotorNodeRight.setRelDirSoft(Quaternion(-2.0*accel.x-this->rotation, Vector(0,0,1)), 10);
    307298}
    308299
     
    381372  else if( event.type == EV_MOUSE_MOTION)
    382373  {
    383     this->xMouse = event.xRel*mouseSensitivity;
    384     this->yMouse = event.yRel*mouseSensitivity;
     374    float xMouse, yMouse;
     375    xMouse = event.xRel*mouseSensitivity;
     376    yMouse = event.yRel*mouseSensitivity;
    385377
    386378    // rotate the Player around the y-axis
    387     this->direction *= Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0));
    388 
     379    this->direction *= Quaternion(-M_PI/4.0*xMouse, Vector(0,1,0));
     380    this->rotation += xMouse;
     381
     382    this->cameraLook += yMouse;
    389383    // rotate the Camera around the z-axis
    390     Quaternion yDir = Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1));
    391     if ((this->cameraNode.getAbsDirY()).y < 0.5)
    392     {
    393       if((this->cameraNode.getAbsDirX()).y > 0)
    394       {
    395         if(yMouse > 0) this->cameraNode.shiftDir(yDir);
    396       }
    397       else
    398       {
    399         if(yMouse < 0) this->cameraNode.shiftDir(yDir);
    400       }
    401     }
    402     else this->cameraNode.shiftDir(yDir);
    403   }
    404 }
     384    if (cameraLook > M_PI_4)
     385      cameraLook = M_PI_4;
     386    else if (cameraLook < -M_PI_2)
     387      cameraLook = -M_PI_2;
     388    this->cameraNode.setRelDirSoft(Quaternion(-cameraLook, Vector(0,0,1)),5);
     389  }
     390}
Note: See TracChangeset for help on using the changeset viewer.