public static List <VertexArray> GenerateLineWithThickness(List <Vector2f> points, Color color, float thickness, bool[] lines) { List <VertexArray> result = new List <VertexArray>( ); VertexArray array = new VertexArray(PrimitiveType.TrianglesStrip); for (int i = 0; i < points.Count; i++) { Vector2f v0 = (i == 0 ? 2 * points[0] - points[1] : points[i - 1]); Vector2f v1 = points[i]; Vector2f v2 = (i == points.Count - 1 ? 2 * points[i] - points[i - 1] : points[i + 1]); Vector2f v01 = (v1 - v0).Normalized( ); Vector2f v12 = (v2 - v1).Normalized( ); Vector2f d = (v01 + v12).GetNormal( ); float dot = d.Dot(v01.GetNormal( )); d *= thickness / 2f / dot; //< TODO: Add flat miter joint in extreme cases if (lines[i % lines.Length]) { array.Append(new Vertex(v1 + d, color)); array.Append(new Vertex(v1 - d, color)); } else { if (array.VertexCount > 0) { result.Add(array); array = new VertexArray(PrimitiveType.TrianglesStrip); } } } if (array.VertexCount > 0) { result.Add(array); } return(result); }
VertexArray GenerateTrianglesStrip(List <Vector2f> points, Color color, float thickness, bool open) { var array = new VertexArray(PrimitiveType.TrianglesStrip); for (int i = 1; i < points.Count + 1 + (open ? 0 : 1); i++) { Vector2f v0 = points[(i - 1) % points.Count]; Vector2f v1 = points[i % points.Count]; Vector2f v2 = points[(i + 1) % points.Count]; Vector2f v01 = (v1 - v0).Normalized(); Vector2f v12 = (v2 - v1).Normalized(); Vector2f d = (v01 + v12).GetNormal(); float dot = d.Dot(v01.GetNormal()); d *= thickness / 2f / dot; //< TODO: Add flat miter joint in extreme cases // d *= thickness / 2f / (float)Math.Max(.8, dot); if (points.Count == i) { array.Append(new Vertex(v0 - d / 4, color)); array.Append(new Vertex(v0 + d / 4, color)); } else { array.Append(new Vertex(v0 + d, color)); array.Append(new Vertex(v0 - d, color)); } } return(array); }