コード例 #1
0
        private void Window_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {
                //PointerPoint point = e.GetCurrentPoint(LayoutRoot);
                //Debug.WriteLine("Released: " + point.Position.X + ", " + point.Position.Y);

                if (calibrationStickkMoving)
                {
                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (CalibrationReleased != null)
                    {
                        CalibrationReleased(args);
                    }
                }


                if (mainStickkMoving)
                {
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Released != null)
                    {
                        Released(args);
                    }
                }

                newX  = 0;
                newY  = 0;
                angle = 0;
                normalizedDistance = 0;

                MoveJoystick(newX, newY);



                if (calibrationStickkMoving)
                {
                    ReplaceCalibrationStick();
                }

                // Reinit calibration rotation
                rotationTransform.Rotation = 135;



                calibrationStickkMoving = false;
                mainStickkMoving        = false;
                idPointer = 0;
            }
        }
コード例 #2
0
        private void Window_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == 0)
            {
                PointerPoint point             = e.GetCurrentPoint(LayoutRoot);
                PointerPoint point_Calibration = e.GetCurrentPoint(CalibrationPath);
                center = new Point(sensor.ActualWidth / 2, sensor.ActualHeight / 2);

                if (point_Calibration.Position.X > 0 &&
                    point_Calibration.Position.X < CalibrationPath.ActualWidth &&
                    point_Calibration.Position.Y > 0 &&
                    point_Calibration.Position.Y < CalibrationPath.ActualHeight)
                {
                    // Calibrage
                    calibrationStickkMoving = true;
                    mainStickkMoving        = false;

                    idPointer = e.Pointer.PointerId;
                    Refresh(point.Position, center);
                }
                else if (point.Position.X > 0 && point.Position.X < LayoutRoot.ActualWidth && point.Position.Y > 0 && point.Position.Y < LayoutRoot.ActualHeight)
                {
                    calibrationStickkMoving = false;
                    mainStickkMoving        = true;

                    // Stick principal
                    idPointer = e.Pointer.PointerId;

                    Refresh(point.Position, center);

                    MoveJoystick(newX, newY);

                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Moving != null)
                    {
                        Moving(args);
                    }

                    //Debug.WriteLine("Started: " + point.Position.X + ", " + point.Position.Y);
                }
            }
        }
コード例 #3
0
        private void Window_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {
                PointerPoint point = e.GetCurrentPoint(mainStickContainer);
                Refresh(point.Position, center);

                Debug.WriteLine("X : {0}, Y : {1}", point.Position.X, point.Position.Y);

                if (mainStickkMoving)
                {
                    MoveJoystick(newX, newY);

                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Moving != null)
                    {
                        Moving(args);
                    }
                }
                else if (calibrationStickkMoving)
                {
                    rotationTransform.Rotation = basicAngle;

                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (Calibrating != null)
                    {
                        Calibrating(args);
                    }

                    //Debug.WriteLine("Angle : {0}", (int)basicAngle);
                }
            }
        }
コード例 #4
0
ファイル: Joystick.xaml.cs プロジェクト: xesf/sphero-sdk
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (Visibility == System.Windows.Visibility.Collapsed)
                return;

            TouchPointCollection points = e.GetTouchPoints(this);
            
            System.Windows.Point center = new System.Windows.Point(joystick.ActualWidth / 2, joystick.ActualHeight / 2);
            for (int i = 0; i < points.Count; i++)
            {
                TouchPoint point = points[i];

                // If Pointer enter on the main stick
                if (IsEnabled && point.Action == TouchAction.Down && XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, mainStickContainer) && idPointer == -1)
                {
                    #region Pointer enter on MainStick
 
                    // Lock stick type
                    calibrationStickMoving = false;
                    mainStickMoving = true;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);

                    // Update mainStick position
                    MoveJoystick(newX, newY);

                    // Prepare event args
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    // Fire event
                    if (Moving != null)
                        Moving(this, args);

                    #endregion
                }
                // Else if pointer enter on calibrationstick
                else if (IsEnabled && point.Action == TouchAction.Down && (XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationPath) || XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationTxt)) && idPointer == -1)
                {
                    // Lock stick type
                    calibrationStickMoving = true;
                    mainStickMoving = false;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);
                }
                // Else if the pointer moving
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Move)
                {
                    // Updating sticks data
                    Refresh(point.Position, center);

                    // If calibrating
                    if (calibrationStickMoving)
                    {
                        // Update angle
                        rotationTransform.Rotation = basicAngle;

                        // Fire event
                        if (Calibrating != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs { Angle = (int)basicAngle };
                            Calibrating(this, args);
                        }

                    }
                    else if (mainStickMoving)
                    {
                        // Update main stick position
                        MoveJoystick(newX, newY);

                        // Fire event
                        if (Moving != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Moving(this, args);
                        }
                    }
                }
                // On pointer released
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Up)
                {
                    // release the pointer Id
                    idPointer = -1;

                    
                    if (mainStickMoving)
                    {
                        // Fire event
                        if (Released != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Released(this, args);
                        }
                    }

                    if(calibrationStickMoving)
                    {
                        // Fire event
                        if (CalibrationReleased != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs { Angle = (int)basicAngle };
                            CalibrationReleased(this, args);
                        }
                    }

                    // Reinit data
                    newX = 0;
                    newY = 0;
                    angle = 0;
                    normalizedDistance = 0;

                    // Update main stick position
                    MoveJoystick(newX, newY);
                    
                    // Reinit calibration rotation
                    rotationTransform.Rotation = 135;

                    // Reinit flags
                    calibrationStickMoving = false;
                    mainStickMoving = false;
                }
            }
        }
コード例 #5
0
ファイル: Joystick.xaml.cs プロジェクト: xesf/sphero-sdk
        private void Window_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {
                PointerPoint point = e.GetCurrentPoint(mainStickContainer);
                Refresh(point.Position, center);

                Debug.WriteLine("X : {0}, Y : {1}", point.Position.X, point.Position.Y);

                if (mainStickkMoving)
                {
                    

                    MoveJoystick(newX, newY);

                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Moving != null)
                        Moving(args);
                }
                else if(calibrationStickkMoving)
                {
                    rotationTransform.Rotation = basicAngle;

                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (Calibrating != null)
                        Calibrating(args);

                    //Debug.WriteLine("Angle : {0}", (int)basicAngle);
                }

            }
        }
コード例 #6
0
ファイル: Joystick.xaml.cs プロジェクト: xesf/sphero-sdk
        private void Window_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {

                //PointerPoint point = e.GetCurrentPoint(LayoutRoot);
                //Debug.WriteLine("Released: " + point.Position.X + ", " + point.Position.Y);

                if (calibrationStickkMoving)
                {
                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (CalibrationReleased != null)
                        CalibrationReleased(args);
                }


                if (mainStickkMoving)
                {
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                        {
                            Angle = (int)angle,
                            Speed = (float)normalizedDistance
                        };

                    if (Released != null)
                        Released(args);
                }

                newX = 0;
                newY = 0;
                angle = 0;
                normalizedDistance = 0;

                MoveJoystick(newX, newY);

                

                if(calibrationStickkMoving)
                {
                    ReplaceCalibrationStick();
                }

                // Reinit calibration rotation
                rotationTransform.Rotation = 135;



                calibrationStickkMoving = false;
                mainStickkMoving = false;
                idPointer = 0;
            }
        }
コード例 #7
0
ファイル: Joystick.xaml.cs プロジェクト: xesf/sphero-sdk
        private void Window_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == 0)
            {
                PointerPoint point = e.GetCurrentPoint(LayoutRoot);
                PointerPoint point_Calibration = e.GetCurrentPoint(CalibrationPath);
                center = new Point(sensor.ActualWidth / 2, sensor.ActualHeight / 2);
                
                if (point_Calibration.Position.X > 0 &&
                    point_Calibration.Position.X < CalibrationPath.ActualWidth &&
                    point_Calibration.Position.Y > 0 &&
                    point_Calibration.Position.Y < CalibrationPath.ActualHeight)
                {
                    // Calibrage
                    calibrationStickkMoving = true;
                    mainStickkMoving = false;

                    idPointer = e.Pointer.PointerId;
                    Refresh(point.Position, center);
                }
                else if (point.Position.X > 0 && point.Position.X < LayoutRoot.ActualWidth && point.Position.Y > 0 && point.Position.Y < LayoutRoot.ActualHeight)
                {
                    calibrationStickkMoving = false;
                    mainStickkMoving = true;

                    // Stick principal
                    idPointer = e.Pointer.PointerId;

                    Refresh(point.Position, center);

                    MoveJoystick(newX, newY);

                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if(Moving != null)
                        Moving(args);

                    //Debug.WriteLine("Started: " + point.Position.X + ", " + point.Position.Y);
                }
            }
        }
コード例 #8
0
ファイル: Joystick.xaml.cs プロジェクト: xesf/sphero-sdk
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (Visibility == System.Windows.Visibility.Collapsed)
            {
                return;
            }

            TouchPointCollection points = e.GetTouchPoints(this);

            System.Windows.Point center = new System.Windows.Point(joystick.ActualWidth / 2, joystick.ActualHeight / 2);
            for (int i = 0; i < points.Count; i++)
            {
                TouchPoint point = points[i];

                // If Pointer enter on the main stick
                if (IsEnabled && point.Action == TouchAction.Down && XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, mainStickContainer) && idPointer == -1)
                {
                    #region Pointer enter on MainStick

                    // Lock stick type
                    calibrationStickMoving = false;
                    mainStickMoving        = true;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);

                    // Update mainStick position
                    MoveJoystick(newX, newY);

                    // Prepare event args
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    // Fire event
                    if (Moving != null)
                    {
                        Moving(this, args);
                    }

                    #endregion
                }
                // Else if pointer enter on calibrationstick
                else if (IsEnabled && point.Action == TouchAction.Down && (XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationPath) || XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationTxt)) && idPointer == -1)
                {
                    // Lock stick type
                    calibrationStickMoving = true;
                    mainStickMoving        = false;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);
                }
                // Else if the pointer moving
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Move)
                {
                    // Updating sticks data
                    Refresh(point.Position, center);

                    // If calibrating
                    if (calibrationStickMoving)
                    {
                        // Update angle
                        rotationTransform.Rotation = basicAngle;

                        // Fire event
                        if (Calibrating != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs {
                                Angle = (int)basicAngle
                            };
                            Calibrating(this, args);
                        }
                    }
                    else if (mainStickMoving)
                    {
                        // Update main stick position
                        MoveJoystick(newX, newY);

                        // Fire event
                        if (Moving != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Moving(this, args);
                        }
                    }
                }
                // On pointer released
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Up)
                {
                    // release the pointer Id
                    idPointer = -1;


                    if (mainStickMoving)
                    {
                        // Fire event
                        if (Released != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Released(this, args);
                        }
                    }

                    if (calibrationStickMoving)
                    {
                        // Fire event
                        if (CalibrationReleased != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs {
                                Angle = (int)basicAngle
                            };
                            CalibrationReleased(this, args);
                        }
                    }

                    // Reinit data
                    newX  = 0;
                    newY  = 0;
                    angle = 0;
                    normalizedDistance = 0;

                    // Update main stick position
                    MoveJoystick(newX, newY);

                    // Reinit calibration rotation
                    rotationTransform.Rotation = 135;

                    // Reinit flags
                    calibrationStickMoving = false;
                    mainStickMoving        = false;
                }
            }
        }