public void drawSegment(Vector2 start, Vector2 end, Color color) { start = FSConvert.toDisplayUnits(start); end = FSConvert.toDisplayUnits(end); _primitiveBatch.addVertex(start, color, PrimitiveType.LineList); _primitiveBatch.addVertex(end, color, PrimitiveType.LineList); }
public void drawSolidCircle(Vector2 center, float radius, Vector2 axis, Color color) { const double increment = Math.PI * 2.0 / circleSegments; double theta = 0.0; Color colorFill = color * 0.5f; Vector2 v0 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); FSConvert.toDisplayUnits(ref v0, out v0); theta += increment; for (int i = 1; i < circleSegments - 1; i++) { Vector2 v1 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); Vector2 v2 = center + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)); _primitiveBatch.addVertex(v0, colorFill, PrimitiveType.TriangleList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(v1), colorFill, PrimitiveType.TriangleList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(v2), colorFill, PrimitiveType.TriangleList); theta += increment; } drawCircle(center, radius, color); drawSegment(center, center + axis * radius, color); }
public void drawPolygon(Vector2[] vertices, int count, Color color, bool closed = true) { for (int i = 0; i < count - 1; i++) { _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[i]), color, PrimitiveType.LineList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[i + 1]), color, PrimitiveType.LineList); } if (closed) { _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[count - 1]), color, PrimitiveType.LineList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[0]), color, PrimitiveType.LineList); } }
public void drawCircle(Vector2 center, float radius, Color color) { const double increment = Math.PI * 2.0 / circleSegments; double theta = 0.0; for (int i = 0; i < circleSegments; i++) { Vector2 v1 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); Vector2 v2 = center + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(v1), color, PrimitiveType.LineList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(v2), color, PrimitiveType.LineList); theta += increment; } }
public void drawSolidPolygon(Vector2[] vertices, int count, Color color, bool outline = true) { if (count == 2) { drawPolygon(vertices, count, color); return; } var colorFill = color * (outline ? 0.5f : 1.0f); for (int i = 1; i < count - 1; i++) { _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[0]), colorFill, PrimitiveType.TriangleList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[i]), colorFill, PrimitiveType.TriangleList); _primitiveBatch.addVertex(FSConvert.toDisplayUnits(vertices[i + 1]), colorFill, PrimitiveType.TriangleList); } if (outline) { drawPolygon(vertices, count, color); } }