// Numpad 8+2+4+6, TGQE with none or shift // Numpad 9+3 tilt camera private bool CameraKeyboard(KeyboardMonitor kbd, float angle) { Vector3 cameraActionRotation = Vector3.Zero; if (kbd.Shift) { angle *= 2.0F; } bool movelookat = kbd.Ctrl == false; if (kbd.IsCurrentlyPressed(Keys.NumPad8, Keys.T) != null) // pitch up, { cameraActionRotation.X = -angle; } else if (kbd.IsCurrentlyPressed(Keys.NumPad2, Keys.G) != null) // pitch down { cameraActionRotation.X = angle; } if (kbd.IsCurrentlyPressed(Keys.NumPad4, Keys.Q) != null) // turn left { cameraActionRotation.Y = -angle; } else if (kbd.IsCurrentlyPressed(Keys.NumPad6, Keys.E) != null) // turn right { cameraActionRotation.Y = angle; } if (kbd.IsCurrentlyPressed(Keys.NumPad9) != null) { cameraActionRotation.Z = angle; } if (kbd.IsCurrentlyPressed(Keys.NumPad3) != null) { cameraActionRotation.Z = -angle; } //System.Diagnostics.Debug.WriteLine($"Cam rot {cameraActionRotation} {movelookat}"); if (cameraActionRotation.LengthSquared > 0) { RotateCamera(new Vector2(cameraActionRotation.X, cameraActionRotation.Y), cameraActionRotation.Z, movelookat); return(true); } else { return(false); } }
// 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); } }
// Keys MN, Ctrl1-9 private bool ZoomKeyboard(KeyboardMonitor kbd, float adjustment) { bool changed = false; if (kbd.IsCurrentlyPressed(KeyboardMonitor.ShiftState.None, Keys.Add, Keys.M) >= 0) { ZoomBy(adjustment); changed = true; } if (kbd.IsCurrentlyPressed(KeyboardMonitor.ShiftState.None, Keys.Subtract, Keys.N) >= 0) { ZoomBy(1.0f / adjustment); changed = true; } float newzoom = 0; float dist = ZoomMax - ZoomMin; float div = 2048; float pow = 3; if (kbd.HasBeenPressed(Keys.D1, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMax; } if (kbd.HasBeenPressed(Keys.D2, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(7, pow) / div); } if (kbd.HasBeenPressed(Keys.D3, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(6, pow) / div); } if (kbd.HasBeenPressed(Keys.D4, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(5, pow) / div); } if (kbd.HasBeenPressed(Keys.D5, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(4, pow) / div); } if (kbd.HasBeenPressed(Keys.D6, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(3, pow) / div); } if (kbd.HasBeenPressed(Keys.D7, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(2, pow) / div); } if (kbd.HasBeenPressed(Keys.D8, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin + dist * (float)(Math.Pow(1, pow) / div); } if (kbd.HasBeenPressed(Keys.D9, KeyboardMonitor.ShiftState.Ctrl)) { newzoom = ZoomMin; } if (newzoom != 0) { GoToZoom(newzoom, -1); changed = true; } return(changed); }