/// <summary> /// Draws a list of connected points /// </summary> /// <param name="points">The points to connect with lines</param> /// <param name="color">The color to use</param> /// <param name="thickness">The thickness of the lines</param> /// <param name="closePoly">If set to <c>true</c> the first and last points will be connected.</param> public static void drawPoints( this Batcher batcher, Vector2 position, Vector2[] points, Color color, bool closePoly = true, float thickness = 1) { if (points.Length < 2) { return; } batcher.setIgnoreRoundingDestinations(true); for (int i = 1; i < points.Length; i++) { drawLine(batcher, position + points[i - 1], position + points[i], color, thickness); } if (closePoly) { drawLine(batcher, position + points[points.Length - 1], position + points[0], color, thickness); } batcher.setIgnoreRoundingDestinations(false); }
public static void drawCircle( this Batcher batcher, Vector2 position, float radius, Color color, float thickness = 1f, int resolution = 12) { var last = Vector2.UnitX * radius; var lastP = Vector2Ext.perpendicular(last); batcher.setIgnoreRoundingDestinations(true); for (int i = 1; i <= resolution; i++) { var at = Mathf.angleToVector(i * MathHelper.PiOver2 / resolution, radius); var atP = Vector2Ext.perpendicular(at); drawLine(batcher, position + last, position + at, color, thickness); drawLine(batcher, position - last, position - at, color, thickness); drawLine(batcher, position + lastP, position + atP, color, thickness); drawLine(batcher, position - lastP, position - atP, color, thickness); last = at; lastP = atP; } batcher.setIgnoreRoundingDestinations(false); }
/// <summary> /// Draws a list of connected points /// </summary> /// <param name="points">The points to connect with lines</param> /// <param name="color">The color to use</param> /// <param name="thickness">The thickness of the lines</param> public static void drawPoints(this Batcher batcher, List <Vector2> points, Color color, float thickness = 1) { if (points.Count < 2) { return; } batcher.setIgnoreRoundingDestinations(true); for (int i = 1; i < points.Count; i++) { drawLine(batcher, points[i - 1], points[i], color, thickness); } batcher.setIgnoreRoundingDestinations(false); }
public static void drawHollowRect(this Batcher batcher, float x, float y, float width, float height, Color color, float thickness = 1) { var tl = new Vector2(x, y).round(); var tr = new Vector2(x + width, y).round(); var br = new Vector2(x + width, y + height).round(); var bl = new Vector2(x, y + height).round(); batcher.setIgnoreRoundingDestinations(true); batcher.drawLine(tl, tr, color, thickness); batcher.drawLine(tr, br, color, thickness); batcher.drawLine(br, bl, color, thickness); batcher.drawLine(bl, tl, color, thickness); batcher.setIgnoreRoundingDestinations(false); }