Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private void picJoystick_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int x, y;
                x = Math.Min(picJoystick.Width, Math.Max(e.X, 0));
                y = Math.Min(picJoystick.Height, Math.Max(e.Y, 0));

                x = x * 2000 / picJoystick.Width - 1000;
                y = y * 2000 / picJoystick.Height - 1000;

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

                UpdateJoystickAxes(axes);
            }
        }
Exemplo n.º 3
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 = x * 2000.0 / driveCanvas.ActualWidth - 1000.0;
                y = y * 2000.0 / driveCanvas.ActualHeight - 1000.0;

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

                UpdateJoystickAxes(axes);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handle movements over the Track Ball
        /// </summary>
        /// <param name="sender">The Track Ball</param>
        /// <param name="e">The Mouse event arguments</param>
        private void JoystickPictureMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int x, y;
                x = Math.Min(this.JoystickPicture.Width, Math.Max(e.X, 0));
                y = Math.Min(this.JoystickPicture.Height, Math.Max(e.Y, 0));

                // Convert the values so that they are in the range -1000 to +1000
                x = ((x * 2000) / this.JoystickPicture.Width) - 1000;
                y = ((y * 2000) / this.JoystickPicture.Height) - 1000;

                // Simulate a message from the Xbox Controller
                joystick.Axes axes = new joystick.Axes();
                axes.X = x;
                axes.Y = y;
                this.UpdateJoystickAxes(axes);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// From SimpleDashboard sample
        /// </summary>
        /// <param name="axes"></param>
        public void UpdateJoystickAxes(game.Axes axes)
        {
            DrawJoystick(axes.X, -axes.Y);

            double left;
            double right;

            if (axes.Y < 0)
            {
                left  = (-axes.Y + axes.X / 2) / 1000.0;
                right = (-axes.Y - axes.X / 2) / 1000.0;
            }
            else
            {
                left  = (-axes.Y + axes.X / 2) / 1000.0;
                right = (-axes.Y - axes.X / 2) / 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));
        }
Exemplo n.º 6
0
        public void UpdateJoystickAxes(game.Axes axes)
        {
            int x = axes.X;
            int y = -axes.Y;

            lblX.Text = x.ToString();
            lblY.Text = y.ToString();
            lblZ.Text = axes.Z.ToString();


            DrawJoystick(x, y);

            if (!chkStop.Checked)
            {
                int left;
                int right;

                if (chkDrive.Checked == true)
                {
                    if (y > -100)
                    {
                        left  = y + axes.X / 4;
                        right = y - axes.X / 4;
                    }
                    else
                    {
                        left  = y - axes.X / 4;
                        right = y + axes.X / 4;
                    }
                }
                else
                {
                    left = right = 0;
                }
                _eventsPort.Post(new OnMove(this, left, right));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handle updates to the joystick position
        /// </summary>
        /// <param name="axes">The new Axis values</param>
        public void UpdateJoystickAxes(joystick.Axes axes)
        {
            int x = axes.X;
            int y = -axes.Y;

            this.lastAxes  = axes;
            this.lblX.Text = x.ToString();
            this.lblY.Text = y.ToString();
            this.lblZ.Text = axes.Z.ToString();

            this.DrawJoystick(x, y);

            // Only send a drive reqeust if not stopped and enabled
            if (this.StopCheckBox.Checked == false)
            {
                double left;
                double right;

                if (this.DriveCheckBox.Checked == true)
                {
                    // This is the raw length of the vector
                    double magnitude = Math.Sqrt((x * x) + (y * y));

                    // Check for the "dead zone"
                    // Adjust the speed values so that they do not
                    // suddenly jump after leaving the Dead Zone
                    if (Math.Abs(x) < this.options.DeadZoneX)
                    {
                        x = 0;
                    }
                    else
                    {
                        // Subtract off the dead zone value so that the
                        // coord starts from zero
                        if (x > 0)
                        {
                            // Remove the Dead Zone and rescale
                            int temp = x - (int)this.options.DeadZoneX;
                            x = temp * 1000 / (1000 - (int)this.options.DeadZoneX);
                        }
                        else
                        {
                            // Remove the Dead Zone and rescale
                            int temp = x + (int)this.options.DeadZoneX;
                            x = temp * 1000 / (1000 - (int)this.options.DeadZoneX);
                        }
                    }

                    if (Math.Abs(y) < this.options.DeadZoneY)
                    {
                        y = 0;
                    }
                    else
                    {
                        if (y > 0)
                        {
                            // Remove the Dead Zone and rescale
                            int temp = y - (int)this.options.DeadZoneY;
                            y = temp * 1000 / (1000 - (int)this.options.DeadZoneY);
                        }
                        else
                        {
                            // Remove the Dead Zone and rescale
                            int temp = y + (int)this.options.DeadZoneY;
                            y = temp * 1000 / (1000 - (int)this.options.DeadZoneY);
                        }
                    }

                    if (x == 0 && y == 0)
                    {
                        // Totally dead in the middle!
                        left = right = 0;
                    }
                    else
                    {
                        // Angle of the vector
                        double theta = Math.Atan2(y, x);

                        // This is the maximum magnitude for a given angle
                        // double maxMag;
                        double scaledMag = 1.0;

                        // A scaled down magnitude according to above
                        // double scaledMag = magnitude * 1000 / maxMag;
                        scaledMag = magnitude;

                        // Decompose the vector into motor components
                        left = ((scaledMag * this.options.TranslateScaleFactor) * Math.Sin(theta)) +
                               ((scaledMag * this.options.RotateScaleFactor) * Math.Cos(theta));
                        right = ((scaledMag * this.options.TranslateScaleFactor) * Math.Sin(theta)) -
                                ((scaledMag * this.options.RotateScaleFactor) * Math.Cos(theta));
                    }
                }
                else
                {
                    left = right = 0;
                }

                // Cap at 1000
                left  = Math.Min(left, 1000);
                right = Math.Min(right, 1000);
                left  = Math.Max(left, -1000);
                right = Math.Max(right, -1000);

                // Quick and dirty way to display results for debugging -
                // Uncomment the two lines below
                ////Console.WriteLine("Joy: " + data.X + ", " + data.Y
                ////        + " => " + left + ", " + right);

                this.eventsPort.Post(new OnMove(this, (int)Math.Round(left), (int)Math.Round(right)));
            }
        }
Exemplo n.º 8
0
        private void picJoystick_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int x, y;
                x = Math.Min(picJoystick.Width, Math.Max(e.X, 0));
                y = Math.Min(picJoystick.Height, Math.Max(e.Y, 0));

                x = x * 2000 / picJoystick.Width - 1000;
                y = y * 2000 / picJoystick.Height - 1000;

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

                UpdateJoystickAxes(axes);
            }
        }
Exemplo n.º 9
0
        public void UpdateJoystickAxes(game.Axes axes)
        {
            int x = axes.X;
            int y = -axes.Y;

            lblX.Text = x.ToString();
            lblY.Text = y.ToString();
            lblZ.Text = axes.Z.ToString();


            DrawJoystick(x, y);

            //if (!chkStop.Checked)
            //{
            //    int left;
            //    int right;

            //    if (chkDrive.Checked == true)
            //    {
            //        if (y > -100)
            //        {
            //            left = y + axes.X / 4;
            //            right = y - axes.X / 4;
            //        }
            //        else
            //        {
            //            left = y - axes.X / 4;
            //            right = y + axes.X / 4;
            //        }
            //    }
            //    else
            //    {
            //        left = right = 0;
            //    }
            //    _eventsPort.Post(new OnMove(this, left, right));
            //}
            if (!stopCheck)
            {
                double left;
                double right;

                if (driveCheck == true)
                {
                    //this is the raw length of the vector
                    double magnitude = Math.Sqrt(y * y + x * x);

                    //angle of the vector
                    double theta = Math.Atan2(y, x);

                    //this is the maximum magnitude for a given angle
                    double maxMag;
                    if (Math.Abs(x) > Math.Abs(y))
                    {
                        maxMag = Math.Abs(1000 / Math.Cos(theta));
                    }
                    else
                    {
                        maxMag = Math.Abs(1000 / Math.Sin(theta));
                    }

                    //a scaled down magnitude according to above
                    double scaledMag = magnitude * 1000 / maxMag;

                    //decompose the vector into motor components
                    left  = scaledMag * Math.Sin(theta) + scaledMag * Math.Cos(theta) / 3;
                    right = scaledMag * Math.Sin(theta) - scaledMag * Math.Cos(theta) / 3;
                }
                else
                {
                    left = right = 0;
                }

                //cap at 1000
                left  = Math.Min(left, 1000);
                right = Math.Min(right, 1000);
                left  = Math.Max(left, -1000);
                right = Math.Max(right, -1000);

                //throttle control
                left  *= (double)throttle.Value / 100.0;
                right *= (double)throttle.Value / 100.0;

                _eventsPort.Post(new OnMove(this, (int)Math.Round(left), (int)Math.Round(right)));
            }
        }