Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 2.32 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Weird Issue Quaternion Rotation in XNA Space Simulator
  2. public void MoveShip(List<InputAction> InputActionList, GameTime gameTime)
  3.     {
  4.         float second = (float)gameTime.ElapsedGameTime.TotalSeconds;
  5.         float currentTurningSpeed = second * TurningSpeed;
  6.         float leftRightRotation = 0;
  7.         float upDownRotation = 0;
  8.         float linearLeftRightRotation = 0;
  9.         foreach(InputAction action in InputActionList)
  10.         {
  11.             switch(action)
  12.             {
  13.                 case InputAction.Left:
  14.                     leftRightRotation -= currentTurningSpeed;
  15.                     break;
  16.                 case InputAction.Right:
  17.                     leftRightRotation += currentTurningSpeed;
  18.                     break;
  19.                 case InputAction.Up:
  20.                     upDownRotation += currentTurningSpeed;
  21.                     break;
  22.                 case InputAction.Down:
  23.                     upDownRotation -= currentTurningSpeed;
  24.                     break;
  25.                 case InputAction.IncreaseSpeed:
  26.                     if (ShipSpeed < MaxShipSpeed)
  27.                         ShipSpeed += Acceleration;
  28.                     break;
  29.                 case InputAction.DecreaseSpeed:
  30.                     if (ShipSpeed > MinShipSpeed)
  31.                         ShipSpeed -= Acceleration;
  32.                     break;
  33.                 case InputAction.LinearLeft:
  34.                     linearLeftRightRotation += currentTurningSpeed;
  35.                     break;
  36.                 case InputAction.LinearRight:
  37.                     linearLeftRightRotation -= currentTurningSpeed;
  38.                     break;
  39.                 case InputAction.Fire1:
  40.                     WeaponSystem2D.RequestFire(ShipPosition, ShipRotation);
  41.                     break;
  42.             }
  43.  
  44.         }
  45.  
  46.  
  47.         Quaternion currentRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), leftRightRotation) *
  48.             Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRotation) *
  49.             Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), linearLeftRightRotation);
  50.  
  51.  
  52.         currentRotation.Normalize();
  53.         ShipRotation *= currentRotation;
  54.  
  55.         ShipPosition *= Vector3.Transform(new Vector3(0, 0, 1), ShipRotation) * (ShipSpeed * second);
  56.  
  57.         ShipWorld = Matrix.CreateFromQuaternion(ShipRotation) * Matrix.CreateTranslation(ShipPosition);
  58.  
  59.     }