/// <summary> /// Rotate the control points by the defined value in radians. /// </summary> /// <param name="value">The amount to rotate by in radians.</param> public void Rotate(float value) { FMatrix rotationMatrix; FMatrix.CreateRotationZ(value, out rotationMatrix); for (int i = 0; i < ControlPoints.Count; i++) { ControlPoints[i] = FVector2.Transform(ControlPoints[i], rotationMatrix); } }
public void DrawArrow(FVector2 start, FVector2 end, float length, float width, bool drawStartIndicator, Color color) { // Draw connection segment between start- and end-point DrawSegment(start, end, color); // Precalculate halfwidth float halfWidth = width / 2; // Create directional reference FVector2 rotation = (start - end); rotation.Normalize(); // Calculate angle of directional vector float angle = (float)Math.Atan2(rotation.X, -rotation.Y); // Create matrix for rotation FMatrix rotFMatrix = FMatrix.CreateRotationZ(angle); // Create translation matrix for end-point FMatrix endFMatrix = FMatrix.CreateTranslation(end.X, end.Y, 0); // Setup arrow end shape FVector2[] verts = new FVector2[3]; verts[0] = new FVector2(0, 0); verts[1] = new FVector2(-halfWidth, -length); verts[2] = new FVector2(halfWidth, -length); // Rotate end shape FVector2.Transform(verts, ref rotFMatrix, verts); // Translate end shape FVector2.Transform(verts, ref endFMatrix, verts); // Draw arrow end shape DrawSolidPolygon(verts, 3, color, false); if (drawStartIndicator) { // Create translation matrix for start FMatrix startFMatrix = FMatrix.CreateTranslation(start.X, start.Y, 0); // Setup arrow start shape FVector2[] baseVerts = new FVector2[4]; baseVerts[0] = new FVector2(-halfWidth, length / 4); baseVerts[1] = new FVector2(halfWidth, length / 4); baseVerts[2] = new FVector2(halfWidth, 0); baseVerts[3] = new FVector2(-halfWidth, 0); // Rotate start shape FVector2.Transform(baseVerts, ref rotFMatrix, baseVerts); // Translate start shape FVector2.Transform(baseVerts, ref startFMatrix, baseVerts); // Draw start shape DrawSolidPolygon(baseVerts, 4, color, false); } }