Cone(GL10.GL_LINES), //\r
FilledCone(GL10.GL_TRIANGLES), //\r
Curve(GL10.GL_LINES), //\r
+ Polygon(GL10.GL_LINES), //\r
;\r
\r
private final int glType;\r
renderer.color(color.r, color.g, color.b, color.a);\r
renderer.vertex(x + cx, y + cy, z);\r
}\r
+ \r
+ /** Draws a polygon in the x/y plane. The vertices must contain at least 3 points (6 floats x,y). The\r
+ * {@link ShapeType} passed to begin has to be {@link ShapeType#Polygon}.\r
+ * @param vertices */\r
+ public void polygon (float[] vertices) {\r
+ if (currType != ShapeType.Polygon) throw new GdxRuntimeException("Must call begin(ShapeType.Polygon)");\r
+ if (vertices.length < 6) throw new IllegalArgumentException("Polygons must contain at least 3 points.");\r
+ if (vertices.length % 2 != 0) throw new IllegalArgumentException("Polygons must have a pair number of vertices.");\r
+ final int numFloats = vertices.length;\r
+ \r
+ checkDirty();\r
+ checkFlush(numFloats);\r
+ \r
+ float firstX = vertices[0];\r
+ float firstY = vertices[1];\r
+ \r
+ for (int i = 0; i < numFloats; i += 2) {\r
+ float x1 = vertices[i];\r
+ float y1 = vertices[i + 1];\r
+ \r
+ float x2;\r
+ float y2;\r
+ \r
+ if(i + 2 >= numFloats){\r
+ x2 = firstX;\r
+ y2 = firstY;\r
+ }else{\r
+ x2 = vertices[i + 2];\r
+ y2 = vertices[i + 3];\r
+ }\r
+ \r
+ renderer.color(color.r, color.g, color.b, color.a);\r
+ renderer.vertex(x1, y1, 0);\r
+ renderer.color(color.r, color.g, color.b, color.a);\r
+ renderer.vertex(x2, y2, 0);\r
+ }\r
+ }\r
\r
private void checkDirty () {\r
if (!matrixDirty) return;\r