rendered paste bodyfloat leftrightRot = MathHelper.PiOver2;
float updownRot = -MathHelper.Pi / 10.0f;
protected override void Update(GameTime gameTime)
{
Vector3 moveVector = new Vector3(0, 0, 0);
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Escape))
this.Exit();
if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.W))
moveVector += new Vector3(0, 0, -1);
if (keyState.IsKeyDown(Keys.Down) || keyState.IsKeyDown(Keys.S))
moveVector += new Vector3(0, 0, 1);
if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.D))
moveVector += new Vector3(1, 0, 0);
if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.A))
moveVector += new Vector3(-1, 0, 0);
if (keyState.IsKeyDown(Keys.Q))
moveVector += new Vector3(0, 1, 0);
if (keyState.IsKeyDown(Keys.Z))
moveVector += new Vector3(0, -1, 0);
cameraRotationNonFly = Matrix.CreateRotationY(leftrightRot);
rotatedVector = Vector3.Transform(moveVector, cameraRotationNonFly); // fly mode.
cameraPosition += moveSpeed * rotatedVector * (float)(gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f);
currentMouseState = Mouse.GetState();
Vector3 ScreenCenter = new Vector3(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
float xDifference = currentMouseState.X - ScreenCenter.X;
float yDifference = currentMouseState.Y - ScreenCenter.Y;
Mouse.SetPosition(ScreenCenter.X, ScreenCenter.Y);
leftrightRot -= rotationSpeed * xDifference * (float)(gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f);
updownRot -= rotationSpeed * yDifference * (float)(gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f);
if (updownRot < -1)
updownRot = -1;
if (updownRot > 2)
updownRot = 2;
cameraRotation = Matrix.CreateRotationX(updownRot) * Matrix.CreateRotationY(leftrightRot);
cameraRotatedTarget = Vector3.Transform(cameraOriginalTarget, cameraRotation);
cameraFinalTarget = cameraPosition + cameraRotatedTarget;
cameraLookat = cameraPosition + cameraRotatedTarget;
cameraRotatedUpVector = Vector3.Transform(cameraOriginalUpVector, cameraRotation);
view = Matrix.CreateLookAt(cameraPosition, cameraLookat, cameraRotatedUpVector);
base.Update(gameTime);
}