From cf3ddcc41bf65693c9703d9624f3d389e25495cd Mon Sep 17 00:00:00 2001 From: Devin Curry Date: Wed, 4 May 2016 00:22:58 -0700 Subject: [PATCH] Add worldSpace option for drawing polygons --- Sources/kha/graphics2/GraphicsExtension.hx | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Sources/kha/graphics2/GraphicsExtension.hx b/Sources/kha/graphics2/GraphicsExtension.hx index f7070d754..3d81976dd 100644 --- a/Sources/kha/graphics2/GraphicsExtension.hx +++ b/Sources/kha/graphics2/GraphicsExtension.hx @@ -83,32 +83,44 @@ class GraphicsExtension { /** * Draws a convex polygon. */ - public static function drawPolygon(g2: Graphics, x: Float, y: Float, vertices: Array, strength: Float = 1) { + public static function drawPolygon(g2: Graphics, x: Float, y: Float, vertices: Array, strength: Float = 1, ?worldSpace: Bool = false) { var iterator = vertices.iterator(); var v0 = iterator.next(); var v1 = v0; while (iterator.hasNext()) { var v2 = iterator.next(); - g2.drawLine(v1.x + x, v1.y + y, v2.x + x, v2.y + y, strength); + if (worldSpace) + g2.drawLine(v1.x, v1.y, v2.x, v2.y, strength); + else + g2.drawLine(v1.x + x, v1.y + y, v2.x + x, v2.y + y, strength); v1 = v2; } - g2.drawLine(v1.x + x, v1.y + y, v0.x + x, v0.y + y, strength); + if (worldSpace) + g2.drawLine(v1.x, v1.y, v0.x, v0.y, strength); + else + g2.drawLine(v1.x + x, v1.y + y, v0.x + x, v0.y + y, strength); } /** * Draws a filled convex polygon. */ - public static function fillPolygon(g2: Graphics, x: Float, y: Float, vertices: Array) { + public static function fillPolygon(g2: Graphics, x: Float, y: Float, vertices: Array, ?worldSpace: Bool = false) { var iterator = vertices.iterator(); var v0 = iterator.next(); var v1 = v0; while (iterator.hasNext()) { var v2 = iterator.next(); - g2.fillTriangle(v1.x + x, v1.y + y, v2.x + x, v2.y + y, x, y); + if (worldSpace) + g2.fillTriangle(v1.x, v1.y, v2.x, v2.y, x, y); + else + g2.fillTriangle(v1.x + x, v1.y + y, v2.x + x, v2.y + y, x, y); v1 = v2; } - g2.fillTriangle(v1.x + x, v1.y + y, v0.x + x, v0.y + y, x, y); + if (worldSpace) + g2.fillTriangle(v1.x, v1.y, v0.x, v0.y, x, y); + else + g2.fillTriangle(v1.x + x, v1.y + y, v0.x + x, v0.y + y, x, y); } }