Skip to content

Commit

Permalink
fix asteroid polygon origin
Browse files Browse the repository at this point in the history
-closes #30, but makes the shatter duplication issue much worse...
  • Loading branch information
0XDE57 committed Mar 22, 2023
1 parent 7fd56f3 commit 65a1352
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/src/com/spaceproject/generation/EntityFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ public static Entity createAsteroid(long seed, float x, float y, float velX, flo
//shift vertices to be centered around 0,0 relatively
Vector2 center = new Vector2();
GeometryUtils.polygonCentroid(hull, 0, hull.length, center);
center.add(minX, minY);
for (int index = 0; index < hull.length; index += 2) {
hull[index] -= center.x;
hull[index + 1] -= center.y;
Expand Down
12 changes: 11 additions & 1 deletion core/src/com/spaceproject/systems/AsteroidShatterSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,17 @@ private void spawnChildAsteroid(Entity parentAsteroid, float[] vertices) {
vertices[p2], vertices[p2 + 1], // xy: 2, 3
vertices[p3], vertices[p3 + 1] // xy: 4, 5
};
GeometryUtils.ensureCCW(hull);

//GeometryUtils.ensureCCW(hull);

//shift vertices to be centered around 0,0 relatively
Vector2 center = new Vector2();
GeometryUtils.polygonCentroid(hull, 0, hull.length, center);
for (int j = 0; j < hull.length; j += 2) {
hull[j] -= center.x;
hull[j + 1] -= center.y;
}

float triangleQuality = GeometryUtils.triangleQuality(hull[0], hull[1], hull[2], hull[3], hull[4], hull[5]);
//if (triangleQuality < 2.0f) {
//todo: add new vertices to break in half
Expand Down

0 comments on commit 65a1352

Please sign in to comment.