Exemplo n.º 1
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            base.OnKeyDown(e);
            switch (e.Key)
            {
            case Key.Escape:
            case Key.F4 when e.Modifiers.HasFlag(KeyModifiers.Alt):
            case Key.Q when e.Modifiers.HasFlag(KeyModifiers.Control):
            case Key.W when e.Modifiers.HasFlag(KeyModifiers.Control):
            case Key.X when e.Modifiers.HasFlag(KeyModifiers.Control):
                Close();

                return;

            case Key.Up:
            case Key.W:
                m_cuboid.Translate(0f, 0f, .1f);
                break;

            case Key.Down:
            case Key.S:
                m_cuboid.Translate(0f, 0f, -.1f);
                break;

            case Key.Left:
            case Key.A:
                m_cuboid.Translate(-.1f, 0f, 0f);
                break;

            case Key.Right:
            case Key.D:
                m_cuboid.Translate(.1f, 0f, 0f);
                break;

            case Key.Q:
                m_cuboid.Translate(0f, .1f, 0f);
                break;

            case Key.Z:
                m_cuboid.Translate(0f, -.1f, 0f);
                break;

            case Key.KeypadAdd when e.Modifiers.HasFlag(KeyModifiers.Shift):
                m_cuboid.Scale += new Vector3(0.1f);

                break;

            case Key.KeypadSubtract when e.Modifiers.HasFlag(KeyModifiers.Shift):
                m_cuboid.Scale -= new Vector3(0.1f);

                break;

            case Key.KeypadAdd:
                m_view3D.Scale += new Vector3(0.1f);
                break;

            case Key.KeypadSubtract:
                m_view3D.Scale -= new Vector3(0.1f);
                break;

            case Key.Keypad4 when e.Modifiers.HasFlag(KeyModifiers.Alt):
                m_cuboid.RotateAround(new Vector3(0f, 1f, 0f), 1f * (MathF.PI / 180f));

                break;

            case Key.Keypad6 when e.Modifiers.HasFlag(KeyModifiers.Alt):
                m_cuboid.RotateAround(new Vector3(0f, 1f, 0f), -1f * (MathF.PI / 180f));

                break;

            case Key.Keypad2 when e.Modifiers.HasFlag(KeyModifiers.Alt):
                m_cuboid.RotateAround(new Vector3(1f, 0f, 0f), -1f * (MathF.PI / 180f));

                break;

            case Key.Keypad8 when e.Modifiers.HasFlag(KeyModifiers.Alt):
                m_cuboid.RotateAround(new Vector3(1f, 0f, 0f), 1f * (MathF.PI / 180f));

                break;

            case Key.Keypad7 when e.Modifiers.HasFlag(KeyModifiers.Alt):
                m_cuboid.RotateAround(new Vector3(0f, 0f, 1f), 1f * (MathF.PI / 180f));

                break;

            case Key.Keypad9 when e.Modifiers.HasFlag(KeyModifiers.Alt):
                m_cuboid.RotateAround(new Vector3(0f, 0f, 1f), -1f * (MathF.PI / 180f));

                break;

            case Key.Keypad4:
                m_cuboid.RotateAroundGlobal(new Vector3(0f, 1f, 0f), -1f * (MathF.PI / 180f));
                break;

            case Key.Keypad6:
                m_cuboid.RotateAroundGlobal(new Vector3(0f, 1f, 0f), 1f * (MathF.PI / 180f));
                break;

            case Key.Keypad2:
                m_cuboid.RotateAroundGlobal(new Vector3(1f, 0f, 0f), -1f * (MathF.PI / 180f));
                break;

            case Key.Keypad8:
                m_cuboid.RotateAroundGlobal(new Vector3(1f, 0f, 0f), 1f * (MathF.PI / 180f));
                break;

            case Key.Keypad7:
                m_cuboid.RotateAroundGlobal(new Vector3(0f, 0f, 1f), 1f * (MathF.PI / 180f));
                break;

            case Key.Keypad9:
                m_cuboid.RotateAroundGlobal(new Vector3(0f, 0f, 1f), -1f * (MathF.PI / 180f));
                break;

            default: return;
            }

            Console.WriteLine($"Key: {e.Key} Modifiers: {e.Modifiers}");
            m_cuboid.Rotation.ToAxisAngle(out var axis, out var angle);
            Console.WriteLine($"Cuboid position: {m_cuboid.Translation}");
            Console.WriteLine($"Cuboid rotation: {axis} by {angle}");
        }