/// <summary> /// Draw Ball Vector Method /// </summary> /// <param name="center"></param> /// <param name="vector"></param> /// <param name="type">Type of coordinates provided. Note: only FoosbotWorld and Frame are supported</param> /// <param name="color">Color of vector [Default will be set as Brushes.Aqua]</param> public void DrawBallVector(Point center, Point vector, eCoordinatesType type = eCoordinatesType.FoosbotWorld, SolidColorBrush color = null) { VerifyCoordinatesTypeSupported(MethodBase.GetCurrentMethod(), type, eCoordinatesType.FoosbotWorld, eCoordinatesType.Frame); //calculate line end point Point end = new Point(center.X + vector.X, center.Y + vector.Y); //Data provided as foosbot coordinates convert to frame coordinates if (type == eCoordinatesType.FoosbotWorld) { center = TransformAgent.Data.InvertTransform(center); end = TransformAgent.Data.InvertTransform(end); } _dispatcher.Invoke(() => { _screen.Element<Line>(eMarks.BallVectorArrow).StrokeThickness = 2; _screen.Element<Line>(eMarks.BallVectorArrow).Stroke = (color == null) ? Brushes.Aqua : color; _screen.Element<Line>(eMarks.BallVectorArrow).X1 = _screen.FrameToScreenCoordinates(center).X; _screen.Element<Line>(eMarks.BallVectorArrow).Y1 = _screen.FrameToScreenCoordinates(center).Y; _screen.Element<Line>(eMarks.BallVectorArrow).X2 = _screen.FrameToScreenCoordinates(end).X; _screen.Element<Line>(eMarks.BallVectorArrow).Y2 = _screen.FrameToScreenCoordinates(end).Y; _screen.Draw(eMarks.BallVectorArrow, 0, 0, eCoordinatesType.Screen); }); }
/// <summary> /// Verification if provided coordinates type is supported by draw method /// </summary> /// <param name="method">Draw method</param> /// <param name="provided">Provided coordinates type</param> /// <param name="supported">Supported coordinates array</param> /// <exception cref="NotSupportedException">Thrown in case provided coordinates type is not supported</exception> protected void VerifyCoordinatesTypeSupported(MethodBase method, eCoordinatesType provided, params eCoordinatesType[] supported) { if (supported != null && !supported.Contains(provided)) throw new NotSupportedException(String.Format("Coordinates of type {0} are not supported by [{1}]!", provided, method.Name)); }
/// <summary> /// Drawing the vector of the ball /// </summary> /// <param name="center">Center point to draw vector from</param> /// <param name="vector">The end of the vector</param> /// <param name="isLocation">Optional is location [default : true]</param> /// <param name="color">Optional color [default : Aqua]</param> public static void DrawBallVector(Point center, Point vector, eCoordinatesType type = eCoordinatesType.FoosbotWorld, SolidColorBrush color = null) { try { Instance.DrawBallVector(center, vector, type, color); } catch (Exception ex) { Log.Print("Unable to draw ball vector mark.", ex, LogTag.COMMON); } }