Beispiel #1
0
        private void onMouseMove(object sender, MouseEventArgs e)
        {
            if (driveCanvas.IsMouseCaptured)
            {
                double x, y;
                var    pos = e.GetPosition(driveCanvas);
                //x = Math.Min(driveCanvas.ActualWidth, Math.Max(pos.X, 0.0));
                //y = Math.Min(driveCanvas.ActualHeight, Math.Max(pos.Y, 0.0));

                x = pos.X * 2000.0 / driveCanvas.ActualWidth - 1000.0;
                y = pos.Y * 2000.0 / driveCanvas.ActualHeight - 1000.0;

                if (Math.Abs(x) > 1000.0)
                {
                    double f = 1000.0 / Math.Abs(x);
                    x *= f;
                    y *= f;
                }
                if (Math.Abs(y) > 1000.0)
                {
                    double f = 1000.0 / Math.Abs(y);
                    x *= f;
                    y *= f;
                }

                game.Axes axes = new game.Axes();
                axes.X = (int)x;
                axes.Y = (int)y;

                UpdateJoystickAxes(axes);
            }
        }
Beispiel #2
0
        /// <summary>
        /// From SimpleDashboard sample
        /// </summary>
        /// <param name="axes"></param>
        private void UpdateJoystickAxes(game.Axes axes)
        {
            DrawJoystick(axes.X, -axes.Y);

            double left;
            double right;

            if (axes.Y < 0)
            {
                left  = (-axes.Y + axes.X / (-2.0 / 1000.0 * Math.Abs(axes.X) + 3.0)) / 1000.0;
                right = (-axes.Y - axes.X / (-2.0 / 1000.0 * Math.Abs(axes.X) + 3.0)) / 1000.0;
            }
            else
            {
                left  = (-axes.Y + axes.X / (-2.0 / 1000.0 * Math.Abs(axes.X) + 3.0)) / 1000.0;
                right = (-axes.Y - axes.X / (-2.0 / 1000.0 * Math.Abs(axes.X) + 3.0)) / 1000.0;
            }
            if (left > 1.0)
            {
                left = 1.0;
            }
            if (left < -1.0)
            {
                left = -1.0;
            }
            if (right > 1.0)
            {
                right = 1.0;
            }
            if (right < -1.0)
            {
                right = -1.0;
            }

            DrawMotors(left, right);
            drivePort.Post(new Tuple <double, double>(left, right));
        }
        private void onMouseMove(object sender, MouseEventArgs e)
        {
            if (driveCanvas.IsMouseCaptured)
            {
                double x, y;
                var pos = e.GetPosition(driveCanvas);
                //x = Math.Min(driveCanvas.ActualWidth, Math.Max(pos.X, 0.0));
                //y = Math.Min(driveCanvas.ActualHeight, Math.Max(pos.Y, 0.0));

                x = pos.X * 2000.0 / driveCanvas.ActualWidth - 1000.0;
                y = pos.Y * 2000.0 / driveCanvas.ActualHeight - 1000.0;

                if (Math.Abs(x) > 1000.0)
                {
                    double f = 1000.0 / Math.Abs(x);
                    x *= f;
                    y *= f;
                }
                if (Math.Abs(y) > 1000.0)
                {
                    double f = 1000.0 / Math.Abs(y);
                    x *= f;
                    y *= f;
                }

                game.Axes axes = new game.Axes();
                axes.X = (int)x;
                axes.Y = (int)y;

                UpdateJoystickAxes(axes);
            }
        }