/// <summary> /// Update the camera. /// </summary> public static void Update(GameTime gameTime) { // if we don't have any input, don't bother if (inputState == null) { return; } // Calculate the camera's current position. if (inputState.ResetCamera) { Reset(aspectRatio); } float totalMilliseconds = (float)gameTime.ElapsedGameTime.TotalMilliseconds; // check for input to rotate the camera up and down around the model if (inputState.IsKeyPress(Keys.Up)) { cameraArc += totalMilliseconds * 0.1f; } else if (inputState.IsKeyPress(Keys.Down)) { cameraArc -= totalMilliseconds * 0.1f; } cameraArc += inputState.CurrentGamePadStates[0].ThumbSticks.Right.Y * totalMilliseconds * 0.25f; // limit the arc movement if (cameraArc > 90.0f) { cameraArc = 90.0f; } else if (cameraArc < -90.0f) { cameraArc = -90.0f; } // check for input to rotate the camera around the model if (inputState.IsKeyPress(Keys.Right)) { cameraRotation += totalMilliseconds * 0.1f; } else if (inputState.IsKeyPress(Keys.Left)) { cameraRotation -= totalMilliseconds * 0.1f; } cameraRotation += inputState.CurrentGamePadStates[0].ThumbSticks.Right.X * totalMilliseconds * 0.25f; // limit camera to one rotation while (cameraRotation > 360f) { cameraRotation -= 360f; } while (cameraRotation < 0f) { cameraRotation += 360f; } // Check for input to zoom camera in and out if (inputState.IsKeyPress(Keys.Z)) { cameraDistance += totalMilliseconds; } else if (inputState.IsKeyPress(Keys.X)) { cameraDistance -= totalMilliseconds; } cameraDistance += inputState.CurrentGamePadStates[0].Triggers.Left * totalMilliseconds; cameraDistance -= inputState.CurrentGamePadStates[0].Triggers.Right * totalMilliseconds; // limit the camera distance. if (cameraDistance > 5000.0f) { cameraDistance = 5000.0f; } else if (cameraDistance < 350.0f) { cameraDistance = 350.0f; } // recreate the view matrix view = Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation)) * Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) * Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance), Vector3.Zero, Vector3.Up); }