Example #1
0
    public void Update(KeyboardState keyboardState, MouseState mouseState)
    {
        var rotationScale = 5f;

        if (keyboardState.IsKeyDown(Keys.A))
        {
            cameraState.Position = Vector3.Add(cameraState.Position, new Vector3(-1f, 0f, 0f));
            cameraState.Target   = Vector3.Add(cameraState.Target, new Vector3(-1f, 0f, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.D))
        {
            cameraState.Position = Vector3.Add(cameraState.Position, new Vector3(1f, 0f, 0f));
            cameraState.Target   = Vector3.Add(cameraState.Target, new Vector3(1f, 0f, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.W))
        {
            cameraState.Position = Vector3.Add(cameraState.Position, new Vector3(0f, -1f, 0f));
            cameraState.Target   = Vector3.Add(cameraState.Target, new Vector3(0f, -1f, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.S))
        {
            cameraState.Position = Vector3.Add(cameraState.Position, new Vector3(0f, 1f, 0f));
            cameraState.Target   = Vector3.Add(cameraState.Target, new Vector3(0f, 1f, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.Left))
        {
            cameraState.Target = Vector3.Add(cameraState.Target, new Vector3(-rotationScale, 0f, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.Right))
        {
            cameraState.Target = Vector3.Add(cameraState.Target, new Vector3(rotationScale, 0f, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.Up))
        {
            cameraState.Target = Vector3.Add(cameraState.Target, new Vector3(0f, -rotationScale, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.Down))
        {
            cameraState.Target = Vector3.Add(cameraState.Target, new Vector3(0f, rotationScale, 0f));
        }
        if (keyboardState.IsKeyDown(Keys.OemPlus))
        {
            cameraState.Position = Vector3.Add(cameraState.Position, new Vector3(0f, 0f, 20f));
        }
        if (keyboardState.IsKeyDown(Keys.OemMinus))
        {
            cameraState.Position = Vector3.Add(cameraState.Position, new Vector3(0f, 0f, -20f));
        }

        cameraState.RefreshViewMatrix();
    }