public void DrawingTestVector2() { // Draw a circle in a bitmap using the vector class using (var canvas = new Bitmap(1001, 1001)) { var vector = new Vector2(0, 500); using (var graphics = Graphics.FromImage(canvas)) using (var path = new GraphicsPath()) { graphics.TranslateTransform(500, 500); graphics.FillRectangle(Brushes.White, 0, 0, canvas.Width, canvas.Height); path.StartFigure(); var lastPoint = vector.ToPointF(); do { var currentPoint = vector.ToPointF(); path.AddLine(lastPoint, currentPoint); vector.Angle += 0.01f; lastPoint = currentPoint; } while (vector.Angle < 360); path.CloseFigure(); graphics.DrawPath(Pens.Black, path); } canvas.Save("TestVector2.bmp"); } ProcessExtensions.Run("mspaint.exe", "TestVector2.bmp", null, 5); }
public override void Render(Graphics g) { // Draw velocity g.DrawLine(_velocityPen, Pos.ToPointF(), (Pos + Velocity).ToPointF() ); var p1 = new Vector2(-8, 5); var p3 = new Vector2(5, 0); var p2 = new Vector2(-8, -5); var matrix = new Matrix(); matrix.Rotate(Heading, Side); matrix.Translate(Pos.X, Pos.Y); // Transform the vector to world space p1 = matrix.TransformVector2s(p1); p2 = matrix.TransformVector2s(p2); p3 = matrix.TransformVector2s(p3); // Create points that define polygon. PointF[] curvePoints = { p1.ToPointF(), p2.ToPointF(), p3.ToPointF() }; g.DrawPolygon(_objectPen, curvePoints); }
public void ToPointF_Vector2_returns_correct_point() { var vector = new Vector2(10.1, 20.8); var point = vector.ToPointF(); Assert.That(point.X, Is.EqualTo(10.1f)); Assert.That(point.Y, Is.EqualTo(20.8f)); }
/// <summary> /// Adds a line to the end of the path. /// </summary> /// <param name="to">The end point of the line.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddLine(Vector2 to) { PointF end = to.ToPointF(); _pathGeometry?.AddLine(_lastPoint, end); _lastPoint = end; return(this); }
/// <summary> /// Draws a cubic bezier curve to the end of the line. /// </summary> /// <param name="from">The start point of the curve.</param> /// <param name="controlA">The first control point of the curve.</param> /// <param name="controlB">The second control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public void DrawCubicBezier(Vector2 @from, Vector2 controlA, Vector2 controlB, Vector2 to) { _graphics.DrawBezier( LinePen, @from.ToPointF(), controlA.ToPointF(), controlB.ToPointF(), to.ToPointF()); }
/// <summary> /// Draws a quadratic bezier curve to the end of the line. /// </summary> /// <param name="from">The start point of the curve.</param> /// <param name="control">The control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public void DrawQuadraticBezier(Vector2 @from, Vector2 control, Vector2 to) { _graphics.DrawBezier( LinePen, @from.ToPointF(), (@from + (2f / 3f * (control - @from))).ToPointF(), (to + (2f / 3f * (control - to))).ToPointF(), to.ToPointF()); }
/// <summary> /// Adds a cubic bezier curve to the end of the line. /// </summary> /// <param name="controlA">The first control point of the curve.</param> /// <param name="controlB">The second control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddCubicBezier(Vector2 controlA, Vector2 controlB, Vector2 to) { PointF end = to.ToPointF(); PathGeometry?.AddBezier( _lastPoint, controlA.ToPointF(), controlB.ToPointF(), end); _lastPoint = end; return(this); }
/// <summary> /// Adds a quadratic bezier curve to the end of the line. /// </summary> /// <param name="control">The control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddQuadraticBezier(Vector2 control, Vector2 to) { Vector2 @from = _lastPoint.ToVector2(); PointF end = to.ToPointF(); _pathGeometry?.AddBezier( _lastPoint, (@from + (2f / 3f * (control - @from))).ToPointF(), (to + (2f / 3f * (control - to))).ToPointF(), end); _lastPoint = end; return(this); }
public virtual void Draw(Graphics g) { Pen pen = new Pen(selected ? GUIEdge.SelectBrush : GUIEdge.DefaultBrush, LineWidth); StartPos = StartVertex.Pos; EndPos = EndVertex.Pos; Vector2 start = new Vector2(StartPos); Vector2 end = new Vector2(EndPos); Vector2 dir = Vector2.Normalize(end - start); Vector2 drawStart = start + (dir * StartVertex.Radius); Vector2 drawEnd = end - (dir * EndVertex.Radius); g.DrawLine(pen, drawStart.ToPoint(), drawEnd.ToPoint()); Vector2 perpDir = Vector2.Normalize(dir.PerProduct()); //Draw label Vector2 center = (end + start) / 2; Vector2 labelPos = center + (perpDir * 20); if (e.ShowLabel) { g.DrawString(e.Weight.ToString(), font, Brushes.Black, labelPos.ToPointF()); } //Draw arrow if directed if (!e.Directed) { return; } Vector2 arrowBase = drawEnd - (dir * 15); Point[] pArray = new Point[3]; pArray[0] = drawEnd.ToPoint(); pArray[1] = (arrowBase + perpDir * 5).ToPoint(); pArray[2] = (arrowBase - perpDir * 5).ToPoint(); g.FillPolygon(selected ? GUIEdge.SelectBrush : GUIEdge.DefaultBrush, pArray); }
/// <summary> /// Starts the path at the point given. /// </summary> /// <param name="point">The point to start the path at.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath Start(Vector2 point) { _lastPoint = point.ToPointF(); return(this); }
public static double GetAngleBetweenPoints(Vector2 destination, Vector2 center) { return(GetAngleBetweenPoints(destination.ToPointF(), center.ToPointF())); }
/// <summary> /// Adds a cubic bezier curve to the end of the line. /// </summary> /// <param name="controlA">The first control point of the curve.</param> /// <param name="controlB">The second control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddCubicBezier(Vector2 controlA, Vector2 controlB, Vector2 to) { PointF end = to.ToPointF(); PathGeometry?.AddBezier( _lastPoint, controlA.ToPointF(), controlB.ToPointF(), end); _lastPoint = end; return this; }
/// <summary> /// Adds a quadratic bezier curve to the end of the line. /// </summary> /// <param name="control">The control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddQuadraticBezier(Vector2 control, Vector2 to) { Vector2 @from = _lastPoint.ToVector2(); PointF end = to.ToPointF(); _pathGeometry?.AddBezier( _lastPoint, (@from + (2f / 3f * (control - @from))).ToPointF(), (to + (2f / 3f * (control - to))).ToPointF(), end); _lastPoint = end; return this; }
/// <summary> /// Adds a line to the end of the path. /// </summary> /// <param name="to">The end point of the line.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddLine(Vector2 to) { PointF end = to.ToPointF(); _pathGeometry?.AddLine(_lastPoint, end); _lastPoint = end; return this; }
/// <summary> /// Starts the path at the point given. /// </summary> /// <param name="point">The point to start the path at.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath Start(Vector2 point) { _lastPoint = point.ToPointF(); return this; }
/// <summary> /// Draws a line between two points. /// </summary> /// <param name="from">The point to draw the line from.</param> /// <param name="to">The point to draw the line to.</param> public void DrawLine(Vector2 @from, Vector2 to) { _graphics.DrawLine(LinePen, @from.ToPointF(), to.ToPointF()); }
public void Draw(Renderer cam) { GLUtility.DrawEllipse(new GLPen(Color.Red, 1.0f), new RectangleF((float)(currentPoint.X - .1), (float)(currentPoint.Y - .1), .2f, .2f)); GLUtility.DrawString(currentPoint.X.ToString("F2") + "," + currentPoint.Y.ToString("F2"), Color.Black, currentPoint.ToPointF()); //if (poiList.Count > 0) //{ // foreach (NotepointRenderer np in poiList) // { // PointF newPoint = new PointF((float)np.X,(float)np.Y); // if ((shouldMove == true) && np.Equals(pointToMove)) // { // GLUtility.DrawCircle(new GLPen(Color.Red, 0.25f), newPoint, 0.25f); // } // else // { // GLUtility.DrawCircle(new GLPen(np.Color, 0.25f), newPoint, 0.25f); // } // } //} }
public void Update(Vector2 mousePos) { if (FrameContainers.Count > 0) { foreach (var frameContainer in FrameContainers) { if (frameContainer.BoundingRect.Contains(mousePos)) { if (!frameContainer.Highlighted) { _highLightedCount += 1; } frameContainer.Highlighted = true; _frameContainerHighlighted = frameContainer; } else { if (frameContainer.Highlighted) { _highLightedCount -= 1; } frameContainer.Highlighted = false; } } if (_highLightedCount == 0) { _frameContainerHighlighted = null; } } if (Input.MousePressed(MouseButton.Left, "AnimConfig")) { if (!Input.KeyDown(Key.LeftControl, "AnimConfig") && !Input.KeyDown(Key.RightControl, "AnimConfig")) { if (_frameContainersSelected.Count > 0) { foreach (var frameContainer in _frameContainersSelected) { frameContainer.Selected = false; } Application.Instance.MainWindow.PropertiesGrid.SelectedObject = null; _frameContainersSelected.Clear(); } } if (_frameContainerHighlighted != null && !_frameContainerHighlighted.Selected) { _frameContainerHighlighted.Selected = true; Application.Instance.MainWindow.PropertiesGrid.SelectedObject = _frameContainerHighlighted.Frame; _frameContainersSelected.Add(_frameContainerHighlighted); } } if (Input.MouseDown(MouseButton.Left, "AnimConfig") && _frameContainerHighlighted != null) { if (!_draggingFrame) { if (_mouseDownCounter < 5) { _mouseDownCounter += 1; } else { if (_frameContainersSelected.Count > 0) { foreach (var frameContainer in _frameContainersSelected) { frameContainer.Selected = false; } Application.Instance.MainWindow.PropertiesGrid.SelectedObject = null; _frameContainersSelected.Clear(); } _originFrameContainer = _frameContainerHighlighted; _originFrameContainer.Dragged = true; _draggedFrame = _originFrameContainer.Frame; _draggingFrame = true; } } } else if (Input.MouseReleased(MouseButton.Left, "AnimConfig")) { _mouseDownCounter = 0; if (_draggingFrame) { foreach (var frameContainer in _frameContainers) { if (frameContainer.BoundingRect.Contains(mousePos)) { if (!frameContainer.Equals(_originFrameContainer)) { if (frameContainer.Frame != null) { _originFrameContainer.SetFrame(frameContainer.Frame); } else { _originFrameContainer.ClearFrame(); } frameContainer.SetFrame(_draggedFrame); RefreshAnimation(); } break; } } _draggingFrame = false; _originFrameContainer.Dragged = false; _originFrameContainer = null; _draggedFrame = null; } } if (_draggingFrame && _originFrameContainer != null) { _originFrameContainer.FrameDrawPos = mousePos.ToPointF(); } }
public void MoveImediately(Vector2 pos) { Location = new Vector2(pos.ToPointF()); }