drawPoly method
Draws a filled polygon defined by a list of vertices.
The polygon is rendered as a sequence of triangles. Requires at least 3 vertices.
vertices
: A list of[x1, y1, x2, y2, ..., xn, yn]
coordinates.uvs
: An optional list of[u1, v1, u2, v2, ..., un, vn]
texture coordinates, matching the number of vertices. Ifnull
, UVs default to (0,0).texture
: An optional Texture to apply. Defaults to a white texture.colors
: An optional list of Color objects. If provided,colors[0]
is applied to all vertices.
Implementation
void drawPoly(List<double> vertices, {List<double>? uvs, Texture? texture, ColorList? colors}) {
int vCount = vertices.length ~/ 2;
if (vCount < 3) {
warn("Can't render polygon. At least 3 vertices required.");
return;
}
if (uvs != null && uvs.length != vertices.length) {
warn("Can't render Polygon. UVs and Vertices have to be of same length.");
return;
}
_prepareRenderState(_PrimitiveType.triangles, texture: texture);
for (var i = 0; i < vCount; i++) {
var x = vertices[i * 2];
var y = vertices[i * 2 + 1];
var u = uvs?[i * 2] ?? 0.0;
var v = uvs?[i * 2 + 1] ?? 0.0;
_transfromAndAddVertices(x, y, u, v, getColorFromList(colors, 0, _encodedColor));
}
}