public override void DrawCircle(cpVect center, float radius, cpColor color) { if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } const float increment = cp.M_PI * 2.0f / CircleSegments; float theta = 0.0f; var col = color; var colorOutline = col.ToCCColor4B(); CCVector2 centr = center.ToCCVector2(); CCVector2 thetaV = CCVector2.Zero; for (int i = 0, count = CircleSegments; i < count; i++) { thetaV.X = cp.cpfcos(theta); thetaV.Y = cp.cpfsin(theta); CCVector2 v1 = centr + Convert.ToSingle(radius) * thetaV; thetaV.X = cp.cpfcos(theta + increment); thetaV.Y = cp.cpfsin(theta + increment); CCVector2 v2 = centr + Convert.ToSingle(radius) * thetaV; primitiveBatch.AddVertex(ref v1, colorOutline, PrimitiveType.LineList); primitiveBatch.AddVertex(ref v2, colorOutline, PrimitiveType.LineList); theta += increment; } }
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); }