public void processInput(KeyboardState kb, MouseDevice md) { MouseState m = md.GetState(); // Regulates the speed of which key/mouse presses have influence on rotation, position or FOV of the camera. float rotateSpeed = .02f * MathHelper.Pi; float mouseRotateSpeed = 0.0005f * MathHelper.Pi; float moveSpeed = .1f; float fovSpeed = .05f; // Modify the anti-aliasing if (kb[Key.R] && !lkb[Key.R]) { rt.IncreaseAntiAliasing(); } if (kb[Key.F] && !lkb[Key.F]) { rt.DecreaseAntiAliasing(); } // Modify the speed up if ((kb[Key.KeypadPlus] || kb[Key.Plus]) && !(lkb[Key.KeypadPlus] || lkb[Key.Plus])) { rt.IncreaseSpeedUp(); } if ((kb[Key.KeypadMinus] || kb[Key.Minus]) && !(lkb[Key.KeypadMinus] || lkb[Key.Minus])) { rt.DecreaseSpeedUp(); } // Set the speed up to a specific value: number n -> SpeedUp = 2^{n-1} int speedUp = 1; for (Key k = Key.Number1; k <= Key.Number9; k++, speedUp *= 2) { if (!kb[k] || lkb[k]) { continue; } rt.SetSpeedUp(speedUp); break; } // Rotate up, down absolute Vector3 dirY = Vector3.UnitY; if (kb[Key.Left]) { Rotation = Quaternion.FromAxisAngle(dirY, rotateSpeed) * Rotation; } if (kb[Key.Right]) { Rotation = Quaternion.FromAxisAngle(dirY, -rotateSpeed) * Rotation; } // Rotate left, right relative to the current rotation Vector3 dirX = Rotation * Vector3.UnitX; if (kb[Key.Up]) { Rotation = Quaternion.FromAxisAngle(dirX, rotateSpeed) * Rotation; } if (kb[Key.Down]) { Rotation = Quaternion.FromAxisAngle(dirX, -rotateSpeed) * Rotation; } // Move the location of the camera Vector3 delta = Vector3.Zero; if (kb[Key.A]) { delta -= Vector3.UnitX; } if (kb[Key.D]) { delta += Vector3.UnitX; } if (kb[Key.W]) { delta -= Vector3.UnitZ; } if (kb[Key.S]) { delta += Vector3.UnitZ; } if (kb[Key.Q]) { delta -= Vector3.UnitY; } if (kb[Key.E]) { delta += Vector3.UnitY; } // Adjust to the basis of the camera Position += Rotation * delta * moveSpeed; // Adjust FOV if (kb[Key.PageUp]) { FOV += fovSpeed; } if (kb[Key.PageDown]) { FOV = Math.Max(FOV - fovSpeed, 0f); } // Let the camera point in a direction determined by the position of the click: if (m.IsButtonDown(MouseButton.Right) && !lm.IsButtonDown(MouseButton.Right) && 0 <= md.X && md.X < 512) { Ray r = getDirection(md.X, md.Y); // Call the setter: this.Direction = r.direction; } else if (m.IsButtonDown(MouseButton.Left) && lm.IsButtonDown(MouseButton.Left)) { // Rotate proportional to the movement of the mouse int dx = m.X - lm.X, dy = m.Y - lm.Y; // Rotate up, down absolute dirY = Vector3.UnitY; Rotation = Quaternion.FromAxisAngle(dirY, mouseRotateSpeed * dx) * Rotation; // Rotate left, right relative to the current rotation dirX = Rotation * Vector3.UnitX; Rotation = Quaternion.FromAxisAngle(dirX, mouseRotateSpeed * dy) * Rotation; } // Set the state to the last state so we can compare with this state the next time: lkb = kb; lm = m; }