public void DrawSegment(CCPoint from, CCPoint to, float radius, cpColor color) { var colorFill = color.ToCCColor4B(); if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } var a = from; var b = to; var n = CCPoint.Normalize(CCPoint.PerpendicularCCW(a - b)); var nw = n * (float)radius; var v0 = b - nw; var v1 = b + nw; var v2 = a - nw; var v3 = a + nw; // Triangles from beginning to end primitiveBatch.AddVertex(v1, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(v2, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(v0, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(v1, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(v2, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(v3, colorFill, PrimitiveType.TriangleList); }
public override void DrawSolidPolygon(cpVect[] vertices, int vertexCount, cpColor color) { if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } if (vertexCount == 2) { DrawPolygon(vertices, vertexCount, color); return; } CCColor4B colorFill = color.ToCCColor4B() * 0.5f; for (int i = 1; i < vertexCount - 1; i++) { CCVector2 vertice0 = vertices[0].ToCCVector2(); primitiveBatch.AddVertex(ref vertice0, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(vertices[i].ToCCVector2(), colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(vertices[i + 1].ToCCVector2(), colorFill, PrimitiveType.TriangleList); } DrawPolygon(vertices, vertexCount, color); }
public void DrawCircle(cpVect center, float radius, cpColor color) { var centerPoint = center.ToCCPoint(); var colorOutline = color.ToCCColor4B(); var colorFill = colorOutline * 0.5f; base.DrawCircle(centerPoint, radius, colorOutline); base.DrawSolidCircle(centerPoint, radius, colorFill); }
public override void DrawSolidCircle(cpVect center, float radius, cpVect axis, cpColor color) { float segments = (10 * cp.cpfsqrt(radius)); //<- Let's try to guess at # segments for a reasonable smoothness var colorOutline = color.ToCCColor4B(); var colorFill = colorOutline * 0.5f; var centr = center.ToCCVector2(); if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } float increment = cp.M_PI * 2.0f / segments; float theta = 0.0f; CCVector2 thetaV = new CCVector2((float)Math.Cos(theta), (float)Math.Sin(theta)); CCVector2 v0 = center.ToCCVector2() + (float)radius * thetaV; theta += increment; var v1 = CCVector2.Zero; var v2 = CCVector2.Zero; for (int i = 0, count = (int)segments; i < count; i++) { thetaV.X = (float)Math.Cos(theta); thetaV.Y = (float)Math.Sin(theta); v1 = centr + Convert.ToSingle(radius) * thetaV; thetaV.X = (float)Math.Cos(theta + increment); thetaV.Y = (float)Math.Sin(theta + increment); v2 = centr + Convert.ToSingle(radius) * thetaV; primitiveBatch.AddVertex(ref v0, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(ref v1, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(ref v2, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(ref v1, colorOutline, PrimitiveType.LineList); primitiveBatch.AddVertex(ref v2, colorOutline, PrimitiveType.LineList); theta += increment; } DrawSegment(center, center + axis * radius, color); }
public override void DrawPolygon(cpVect[] vertices, int vertexCount, cpColor color) { CCColor4B fillColor = color.ToCCColor4B(); if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } for (int i = 0; i < vertexCount - 1; i++) { primitiveBatch.AddVertex(vertices[i].ToCCVector2(), fillColor, PrimitiveType.LineList); primitiveBatch.AddVertex(vertices[i + 1].ToCCVector2(), fillColor, PrimitiveType.LineList); } primitiveBatch.AddVertex(vertices[vertexCount - 1].ToCCVector2(), fillColor, PrimitiveType.LineList); primitiveBatch.AddVertex(vertices[0].ToCCVector2(), fillColor, PrimitiveType.LineList); }
public void DrawRect(CCRect rect, cpColor color) { base.DrawRect(rect, color.ToCCColor4B()); }
public void DrawDot(cpVect pos, float radius, cpColor color) { //base.DrawDot(pos.ToCCPoint(), radius, color.ToCCColor4F()); base.DrawSolidCircle(pos.ToCCPoint(), radius, color.ToCCColor4B()); }
public void DrawCircle(cpVect center, float radius, float angle, int segments, cpColor color) { base.DrawCircle(center.ToCCPoint(), radius, angle, segments, color.ToCCColor4B()); }
public void DrawSolidCircle(cpVect center, float radius, cpColor color) { base.DrawCircle(center.ToCCPoint(), radius, color.ToCCColor4B()); }
public void DrawCircle(cpVect center, float radius, cpColor color) { var centerPoint = center.ToCCPoint(); var colorOutline = color.ToCCColor4B(); var colorFill = colorOutline * 0.5f; base.DrawCircle(centerPoint, radius, colorOutline); base.DrawSolidCircle(centerPoint, radius, colorFill); }
public void DrawRect(CCRect rect, cpColor color) { base.DrawRect(rect, color.ToCCColor4B()); }
public void DrawDot(cpVect pos, float radius, cpColor color) { //base.DrawDot(pos.ToCCPoint(), radius, color.ToCCColor4F()); base.DrawSolidCircle(pos.ToCCPoint(), radius, color.ToCCColor4B()); }
public void DrawCircle(cpVect center, float radius, float angle, int segments, cpColor color) { base.DrawCircle(center.ToCCPoint(), radius, angle, segments, color.ToCCColor4B()); }
public void DrawSolidCircle(cpVect center, float radius, cpColor color) { base.DrawCircle(center.ToCCPoint(), radius, color.ToCCColor4B()); }