Ejemplo n.º 1
0
        private void DrawMouse(OpenGL gl)
        {
            Point  p  = oc.PointToClient(MousePosition);
            double d1 = (double)oc.Width / ((double)ScaleX * 2);
            double d2 = (double)oc.Height / ((double)ScaleY * 2);
            double g1 = (double)p.X / d1;
            double g2 = (double)p.Y / d2;
            double h1 = g1 - ScaleX;
            double h2 = ScaleY - g2;

            gl.Color(0.5f, 0.5f, 0.5f);
            gl.Vertex(h1, -ScaleY);
            gl.Vertex(h1, ScaleY);
            gl.Vertex(-ScaleX, h2);
            gl.Vertex(ScaleX, h2);
            gl.End();
            DrawText(gl, (float)(h1 + (double)ScaleX / 30), (float)(h2 - (double)ScaleY / 25), 15, "(" + h1.ToString("f2") + "," + h2.ToString("f2") + ")");
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1f, 1f, 1f);
        }
Ejemplo n.º 2
0
        private void Update(OpenGLControl control)
        {
            if (!Host.CurrentApplicationIsActive)
            {
                return;
            }

            if (control.ClientRectangle.Contains(control.PointToClient(Cursor.Position)))
            {
                var delta = new vec2(Cursor.Position.X, Cursor.Position.Y) - LastMousePosition;

                // Rotate camera
                if (Control.MouseButtons.HasFlag(MouseButtons.Middle))
                {
                    MainCamera.Rotate(delta);
                }

                // Rotate shape
                if (Control.MouseButtons.HasFlag(MouseButtons.Left))
                {
                    ShapeRotationAngle += new vec2(delta.y, delta.x);
                }
            }

            // Move camera
            var moveDelta = new vec3(0.0f, 0.0f, 0.0f);

            if (Keyboard.IsKeyDown(Key.W))
            {
                moveDelta.z -= 1.0f;
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                moveDelta.z += 1.0f;
            }
            if (Keyboard.IsKeyDown(Key.A))
            {
                moveDelta.x -= 1.0f;
            }
            if (Keyboard.IsKeyDown(Key.D))
            {
                moveDelta.x += 1.0f;
            }
            if (Control.MouseButtons.HasFlag(MouseButtons.XButton1))
            {
                moveDelta.y -= 1.0f;
            }
            if (Control.MouseButtons.HasFlag(MouseButtons.XButton2))
            {
                moveDelta.y += 1.0f;
            }

            ShapeScale += Scroll / 10.0f;
            Scroll      = 0.0f;

            MainCamera.Move(moveDelta);

            // Arrows
            var keyLeft  = Keyboard.IsKeyDown(Key.Left);
            var keyRight = Keyboard.IsKeyDown(Key.Right);

            if (!LastKeyLeft && keyLeft)
            {
                Voltages.Back();
            }
            if (!LastKeyRight && keyRight)
            {
                Voltages.Forward();
            }
            if (Keyboard.IsKeyDown(Key.Up))
            {
                ElectrodeMaxDistance += 0.25f;
            }
            if (Keyboard.IsKeyDown(Key.Down))
            {
                ElectrodeMaxDistance -= 0.25f;
            }
            LastKeyLeft  = keyLeft;
            LastKeyRight = keyRight;
        }