public void DrawLine(CCPoint from, CCPoint to, float lineWidth, CCColor4B color, CCLineCap lineCap = CCLineCap.Butt) { System.Diagnostics.Debug.Assert(lineWidth >= 0, "Invalid value specified for lineWidth : value is negative"); if (lineWidth <= 0) return; var cl = color; var a = from; var b = to; var normal = CCPoint.Normalize(a - b); if (lineCap == CCLineCap.Square) { var nr = normal * lineWidth; a += nr; b -= nr; } var n = CCPoint.PerpendicularCCW(normal); var nw = n * lineWidth; var v0 = b - nw; var v1 = b + nw; var v2 = a - nw; var v3 = a + nw; // Triangles from beginning to end AddTriangleVertex(new CCV3F_C4B(v1, cl)); AddTriangleVertex(new CCV3F_C4B(v2, cl)); AddTriangleVertex(new CCV3F_C4B(v0, cl)); AddTriangleVertex(new CCV3F_C4B(v1, cl)); AddTriangleVertex(new CCV3F_C4B(v2, cl)); AddTriangleVertex(new CCV3F_C4B(v3, cl)); if (lineCap == CCLineCap.Round) { var mb = (float)Math.Atan2(v1.Y - b.Y, v1.X - b.X); var ma = (float)Math.Atan2(v2.Y - a.Y, v2.X - a.X); // Draw rounded line caps DrawSolidArc(a, lineWidth, -ma, -MathHelper.Pi, color); DrawSolidArc(b, lineWidth, -mb, -MathHelper.Pi, color); } dirty = true; }
public void DrawLine(CCPoint from, CCPoint to, float lineWidth = 1, CCLineCap lineCap = CCLineCap.Butt) { DrawLine(from, to, lineWidth, new CCColor4B(Color.R, Color.G, Color.B, Opacity)); }
public void DrawLine(CCPoint from, CCPoint to, CCColor4B color, CCLineCap lineCap = CCLineCap.Butt) { DrawLine(from, to, 1, color); }
public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color, CCLineCap lineCap = CCLineCap.Round) { DrawLine(from, to, radius, (CCColor4B)color, lineCap); }
public void DrawLine(CCPoint from, CCPoint to, float lineWidth, CCColor4B color, CCLineCap lineCap = CCLineCap.Butt) { System.Diagnostics.Debug.Assert(lineWidth >= 0, "Invalid value specified for lineWidth : value is negative"); if (lineWidth <= 0) { return; } var cl = color; var a = from; var b = to; var normal = CCPoint.Normalize(a - b); if (lineCap == CCLineCap.Square) { var nr = normal * lineWidth; a += nr; b -= nr; } var n = CCPoint.PerpendicularCCW(normal); var nw = n * lineWidth; var v0 = b - nw; var v1 = b + nw; var v2 = a - nw; var v3 = a + nw; // Triangles from beginning to end AddTriangleVertex(new CCV3F_C4B(v1, cl)); AddTriangleVertex(new CCV3F_C4B(v2, cl)); AddTriangleVertex(new CCV3F_C4B(v0, cl)); AddTriangleVertex(new CCV3F_C4B(v1, cl)); AddTriangleVertex(new CCV3F_C4B(v2, cl)); AddTriangleVertex(new CCV3F_C4B(v3, cl)); if (lineCap == CCLineCap.Round) { var mb = (float)Math.Atan2(v1.Y - b.Y, v1.X - b.X); var ma = (float)Math.Atan2(v2.Y - a.Y, v2.X - a.X); // Draw rounded line caps DrawSolidArc(a, lineWidth, -ma, -MathHelper.Pi, color); DrawSolidArc(b, lineWidth, -mb, -MathHelper.Pi, color); } dirty = true; }