private void ColorCanvasPointerMoved(object sender, PointerRoutedEventArgs e) { XYCoordinates.X = e.GetCurrentPoint(ColorMap).Position.X - ColorMap.Width / 2; XYCoordinates.Y = e.GetCurrentPoint(ColorMap).Position.Y - ColorMap.Height / 2; polarCoordinates = XY2RPhi(XYCoordinates.X, XYCoordinates.Y); //textBox1.Text = Convert.ToString(XYCoordinates.X); //textBox2.Text = Convert.ToString(XYCoordinates.Y); //textBox3.Text = Convert.ToString(polarCoordinates.R); //textBox4.Text = Convert.ToString(polarCoordinates.Phi); //Debug.WriteLine("{0} ; {1}", XYCoordinates.X, XYCoordinates.Y); //Debug.WriteLine("{0} ; {1}", polarCoordinates.R, polarCoordinates.Phi); if (polarCoordinates.R < 20) { polarCoordinates.R = 0; XYCoordinates.X = 0; XYCoordinates.Y = 0; } if (polarCoordinates.R > ColorMap.Width / 2 - ColorPicker.Width / 2) { //e.Handled = true; //return; polarCoordinates.R = ColorMap.Width / 2 - ColorPicker.Width / 2; XYCoordinates = RPhi2XY(polarCoordinates.R, polarCoordinates.Phi); } Canvas.SetLeft(ColorPicker, XYCoordinates.X + ColorMap.Width / 2 - ColorPicker.Width / 2); Canvas.SetTop(ColorPicker, XYCoordinates.Y + ColorMap.Height / 2 - ColorPicker.Height / 2); Canvas.SetLeft(HorizontalLine, XYCoordinates.X + ColorMap.Width / 2); Canvas.SetTop(VerticalLine, XYCoordinates.Y + ColorMap.Height / 2); //ctr++; //Debug.WriteLine(ctr); speedsLR = rphi2dc(polarCoordinates.R / (ColorMap.Width / 2 - ColorPicker.Width / 2), polarCoordinates.Phi); //Debug.WriteLine("{0} ; {1}", speedsLR.L, speedsLR.R); //Debug.WriteLine("{0} ; {1}", polarCoordinates.R / (ColorMap.Width / 2 - ColorPicker.Width / 2) * 100, polarCoordinates.Phi / 2 / Math.PI * 360); leftSliderValue = speedsLR.L; rightSliderValue = speedsLR.R; length = Convert.ToByte(polarCoordinates.R / (ColorMap.Width / 2 - ColorPicker.Width / 2) * 100); angle = Convert.ToByte(polarCoordinates.Phi / 2 / Math.PI * 180); debounceCounter = 3; e.Handled = true; }
private RPhi XY2RPhi(double X, double Y) { RPhi tempPolarCoordinates = new RPhi(0, 0); double tempPhi; tempPolarCoordinates.R = Math.Sqrt(X * X + Y * Y); tempPhi = Math.Atan2(-Y, X); if (tempPhi >= 0) { tempPolarCoordinates.Phi = tempPhi; } else { tempPolarCoordinates.Phi = tempPhi + 2 * Math.PI; } return(tempPolarCoordinates); }
private void CanvasPointerMoved(object sender, PointerRoutedEventArgs e) { double joyXCurrentPos, joyYCurrentPos; double x_temp, y_temp; x_temp = e.GetCurrentPoint(CamCanvas).Position.X; y_temp = e.GetCurrentPoint(CamCanvas).Position.Y; //Debug.WriteLine("{0} ; {1}", x_temp, y_temp); if ((y_temp > 220) || ((y_temp < 50) && (x_temp > 230))) { e.Handled = true; return; } if (SwipeButton.IsChecked == false) { //Debug.WriteLine(e.Pointer.PointerDeviceType.ToString()); xPos2 = Convert.ToInt16(e.GetCurrentPoint(CamImage).Position.X); if ((e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) || (pointerIsPressed == true)) { xPos2 = Convert.ToInt16(x_temp); yPos2 = Convert.ToInt16(y_temp); xDelta = xPos2 - xPos1; yDelta = yPos2 - yPos1; xPos1 = xPos2; yPos1 = yPos2; S1.Value = SaturateInteger(Convert.ToInt16(S1.Value - xDelta * 3), 0, 1000); S2.Value = SaturateInteger(Convert.ToInt16(S2.Value + yDelta * 3), 0, 1000); } } else { if ((e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) || (pointerIsPressed == true)) { joyXCurrentPos = x_temp; joyYCurrentPos = y_temp; //S1.Value = SaturateInteger(Convert.ToInt16(S1.Value + (joyXCurrentPos - joyXStartPos) * 0.1), 0, 1000); //S2.Value = SaturateInteger(Convert.ToInt16(S2.Value + (joyYCurrentPos - joyYStartPos) * 0.1), 0, 1000); XYCoordinates.X = joyXCurrentPos - joyXStartPos; XYCoordinates.Y = joyYCurrentPos - joyYStartPos; //Debug.WriteLine(XYCoordinates.X +";"+ XYCoordinates.Y); polarCoordinates = XY2RPhi(XYCoordinates.X, XYCoordinates.Y); if (polarCoordinates.R < 10) { polarCoordinates.R = 0; XYCoordinates.X = 0; XYCoordinates.Y = 0; } if (polarCoordinates.R > SoftJoyBoundary.Width / 2 - SoftJoy.Width / 2) { //e.Handled = true; //return; polarCoordinates.R = SoftJoyBoundary.Width / 2 - SoftJoy.Width / 2; XYCoordinates = RPhi2XY(polarCoordinates.R, polarCoordinates.Phi); } Canvas.SetLeft(SoftJoy, joyXStartPos + XYCoordinates.X - SoftJoy.Width / 2); Canvas.SetTop(SoftJoy, joyYStartPos + XYCoordinates.Y - SoftJoy.Height / 2); //Canvas.SetLeft(SoftJoy, joyXCurrentPos - SoftJoy.Width / 2); //Canvas.SetTop(SoftJoy, joyYCurrentPos - SoftJoy.Width / 2); speedsLR = rphi2dc(polarCoordinates.R / (SoftJoyBoundary.Width / 2 - SoftJoy.Width / 2), polarCoordinates.Phi); //Debug.WriteLine("{0} ; {1}", speedsLR.L, speedsLR.R); LeftDrive.Value = speedsLR.L; RightDrive.Value = speedsLR.R; } } RefreshHorizont(); e.Handled = true; }
private async void ColorCanvasPointerMoved(object sender, PointerRoutedEventArgs e) { XYCoordinates.X = e.GetCurrentPoint(ColorMap).Position.X - ColorMap.Width / 2; XYCoordinates.Y = e.GetCurrentPoint(ColorMap).Position.Y - ColorMap.Height / 2; polarCoordinates = XY2RPhi(XYCoordinates.X, XYCoordinates.Y); //Debug.WriteLine("{0} ; {1}", polarCoordinates.R, polarCoordinates.Phi); if (polarCoordinates.R > ColorMap.Width / 2 - ColorPicker.Width / 2) { e.Handled = true; return; } Canvas.SetLeft(ColorPicker, XYCoordinates.X + ColorMap.Width / 2 - ColorPicker.Width / 2); Canvas.SetTop(ColorPicker, XYCoordinates.Y + ColorMap.Height / 2 - ColorPicker.Height / 2); if ((polarCoordinates.Phi < Rmax) || (polarCoordinates.Phi > Rmin)) { if ((polarCoordinates.Phi >= 4.15) || (polarCoordinates.Phi <= 0.5)) { R = 255; } else if (polarCoordinates.Phi <= Rmax) { R = 255 * (Rmax - polarCoordinates.Phi) / (Rmax - 0.5); } else { R = 255 * (polarCoordinates.Phi - Rmin) / (4.15 - Rmin); } } else { R = 0; } if ((polarCoordinates.Phi <= Bmax) && (polarCoordinates.Phi >= Bmin)) { if ((polarCoordinates.Phi >= 0.5) && (polarCoordinates.Phi <= 2.45)) { B = 255; } else if (polarCoordinates.Phi < 0.5) { B = 255 * (Bmin - polarCoordinates.Phi) / (Bmin - 0.5); } else { B = 255 * (Bmax - polarCoordinates.Phi) / (Bmax - 2.45); } } else { B = 0; } if ((polarCoordinates.Phi <= Gmax) && (polarCoordinates.Phi >= Gmin)) { if ((polarCoordinates.Phi >= 2.45) && (polarCoordinates.Phi <= 4.15)) { G = 255; } else if (polarCoordinates.Phi < 2.45) { G = 255 * (Gmin - polarCoordinates.Phi) / (Gmin - 2.45); } else { G = 255 * (Gmax - polarCoordinates.Phi) / (Gmax - 4.15); } } else { G = 0; } if (polarCoordinates.R < radialLimit) { R += (255 - R) * (polarCoordinates.R - radialLimit) / (-radialLimit); B += (255 - B) * (polarCoordinates.R - radialLimit) / (-radialLimit); G += (255 - G) * (polarCoordinates.R - radialLimit) / (-radialLimit); } color.R = Convert.ToByte(R); color.B = Convert.ToByte(B); color.G = Convert.ToByte(G); color.A = 255; brush = new SolidColorBrush(color); ColorPicker.Fill = brush; if (writer != null) { if (color.R == 13) { color.R = 14; } if (color.G == 13) { color.G = 14; } if (color.B == 13) { color.B = 14; } writer.WriteByte(0x43); writer.WriteByte(color.R); writer.WriteByte(color.G); writer.WriteByte(color.B); writer.WriteByte(0x0D); await writer.StoreAsync(); } e.Handled = true; }