// Keys WASD RF Left/Right/Up/Down/PageUp/Down with none or shift or ctrl private bool PositionKeyboard(KeyboardMonitor kbd, bool inperspectivemode, float movedistance) { Vector3 positionMovement = Vector3.Zero; if (kbd.Shift) { movedistance *= 2.0F; } if (kbd.HasBeenPressed(Keys.M, KeyboardMonitor.ShiftState.Ctrl)) { YHoldMovement = !YHoldMovement; } if (kbd.IsCurrentlyPressed(Keys.Left, Keys.A) != null) // x axis { positionMovement.X = -movedistance; } else if (kbd.IsCurrentlyPressed(Keys.Right, Keys.D) != null) { positionMovement.X = movedistance; } if (kbd.IsCurrentlyPressed(Keys.PageUp, Keys.R) != null) // y axis { positionMovement.Y = movedistance; } else if (kbd.IsCurrentlyPressed(Keys.PageDown, Keys.F) != null) { positionMovement.Y = -movedistance; } if (kbd.IsCurrentlyPressed(Keys.Up, Keys.W) != null) // z axis { positionMovement.Z = movedistance; } else if (kbd.IsCurrentlyPressed(Keys.Down, Keys.S) != null) { positionMovement.Z = -movedistance; } if (positionMovement.LengthSquared > 0) { if (inperspectivemode) { Vector2 cameraDir = CameraDirection; if (YHoldMovement) // Y hold movement means only the camera rotation around the Y axis is taken into account. { var cameramove = Matrix4.CreateTranslation(positionMovement); var rotY = Matrix4.CreateRotationY(cameraDir.Y.Radians()); // rotate by Y, which is rotation around the Y axis, which is where your looking at horizontally cameramove *= rotY; Translate(cameramove.ExtractTranslation()); } else { var cameramove = Matrix4.CreateTranslation(new Vector3(positionMovement.X, positionMovement.Z, -positionMovement.Y)); cameramove *= Matrix4.CreateRotationZ(CameraRotation.Radians()); // rotate the translation by the camera look angle cameramove *= Matrix4.CreateRotationX(cameraDir.X.Radians()); cameramove *= Matrix4.CreateRotationY(cameraDir.Y.Radians()); Translate(cameramove.ExtractTranslation()); } } else { positionMovement.Y = 0; Translate(positionMovement); } return(true); } else { return(false); } }