Skip to content

Commit

Permalink
rename polygon wireframe method and draw using triangle()
Browse files Browse the repository at this point in the history
  • Loading branch information
earlygrey committed Sep 23, 2022
1 parent 67ebd22 commit c2a7ffc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
16 changes: 0 additions & 16 deletions drawer/src/space/earlygrey/shapedrawer/PolygonDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ void polygon(float centreX, float centreY, int sides, float radiusX, float radiu
}
if (!wasCaching) batchManager.endCaching();
}

void polygonWireframe(float[] vertices, short[] triangles, float offsetX, float offsetY) {
if (triangles.length == 0) return;
float[] v = vertices;
short[] t = triangles;
boolean wasCaching = batchManager.startCaching();
for (int i = 0; i < t.length; i += 3) {
drawer.lineDrawer.pushLine(offsetX + v[2 * t[i]], offsetY + v[2 * t[i] + 1],
offsetX + v[2 * t[i + 1]], offsetY + v[2 * t[i + 1] + 1], 1f, false);
drawer.lineDrawer.pushLine(offsetX + v[2 * t[i + 1]], offsetY + v[2 * t[i + 1] + 1],
offsetX + v[2 * t[i + 2]], offsetY + v[2 * t[i + 2] + 1], 1f, false);
drawer.lineDrawer.pushLine(offsetX + v[2 * t[i]], offsetY + v[2 * t[i] + 1],
offsetX + v[2 * t[i + 2]], offsetY + v[2 * t[i + 2] + 1], 1f, false);
}
if (!wasCaching) batchManager.endCaching();
}

void drawPolygonNoJoin(Vector2 centre, int sides, float lineWidth, float rotation, Vector2 radius, float startAngle, float radians) {
float angleInterval = MathUtils.PI2 / sides;
Expand Down
46 changes: 37 additions & 9 deletions drawer/src/space/earlygrey/shapedrawer/ShapeDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ShapeDrawer(Batch batch) {
public ShapeDrawer(Batch batch, TextureRegion region) {
super(batch, region, new DefaultSideEstimator());
}

public ShapeDrawer(Batch batch, TextureRegion region, SideEstimator sideEstimator) {
super(batch, region, sideEstimator);
}
Expand Down Expand Up @@ -947,13 +947,7 @@ public void polygon(float[] vertices, int start, int end, float lineWidth) {
public void polygon(float[] vertices, int start, int end, float lineWidth, JoinType joinType) {
pathDrawer.path(vertices, start, end, lineWidth, joinType, false);
}

/**
* <p>Draws the wireframe model of the given polygon triangles</p>
*/
public void polygonWireframe(float[] vertices, short[] triangles, float offsetX, float offsetY) {
polygonDrawer.polygonWireframe(vertices, triangles, offsetX, offsetY);
}


//====================
// FILLED
Expand Down Expand Up @@ -1038,7 +1032,16 @@ public void filledPolygon(Polygon polygon, ShortArray triangles) {
public void filledPolygon(float[] vertices, ShortArray triangles) {
filledPolygonDrawer.polygon(vertices, triangles);
}


/**
* <p>Draws a filled polygon using the specified vertices.</p>
* @param vertices consecutive ordered pairs of the x-y coordinates of the vertices of the polygon
* @param triangles ordered triples of the indices of the float[] defining the polygon vertices corresponding to triangles.
* You can use something like {@link com.badlogic.gdx.math.EarClippingTriangulator#computeTriangles(float[])} to
* calculate them.
* @param offsetX the x-offset of the vertices
* @param offsetY the y-offset of the vertices
*/
public void filledPolygon(float[] vertices, short[] triangles, float offsetX, float offsetY) {
filledPolygonDrawer.polygon(vertices, triangles, offsetX, offsetY);
}
Expand Down Expand Up @@ -1195,6 +1198,31 @@ public void triangle(float x1, float y1, float x2, float y2, float x3, float y3,
setColor(c);
}


/**
* Draw the triangles defined by the specified vertices.
* @param vertices consecutive ordered pairs of the x-y coordinates of the vertices of the polygon
* @param triangles ordered triples of the indices of the float[] defining the polygon vertices corresponding to triangles.
* You can use something like {@link com.badlogic.gdx.math.EarClippingTriangulator#computeTriangles(float[])} to
* calculate them.
* @param offsetX the x-offset of the vertices
* @param offsetY the y-offset of the vertices
*/
public void triangles(float[] vertices, short[] triangles, float offsetX, float offsetY) {
float[] v = vertices;
short[] t = triangles;
for (int i = 0; i < t.length; i += 3) {
float x1 = offsetX + v[2 * t[i]];
float y1 = offsetY + v[2 * t[i] + 1];
float x2 = offsetX + v[2 * t[i + 1]];
float y2 = offsetY + v[2 * t[i + 1] + 1];
float x3 = offsetX + v[2 * t[i + 2]];
float y3 = offsetY + v[2 * t[i + 2] + 1];
triangle(x1, y1, x2, y2, x3, y3, getDefaultLineWidth(), JoinType.NONE, getPackedColor());
}
}


//====================
// FILLED
//====================
Expand Down

0 comments on commit c2a7ffc

Please sign in to comment.