Skip to content

Commit 65a1352

Browse files
committed
fix asteroid polygon origin
-closes #30, but makes the shatter duplication issue much worse...
1 parent 7fd56f3 commit 65a1352

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/src/com/spaceproject/generation/EntityFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ public static Entity createAsteroid(long seed, float x, float y, float velX, flo
564564
//shift vertices to be centered around 0,0 relatively
565565
Vector2 center = new Vector2();
566566
GeometryUtils.polygonCentroid(hull, 0, hull.length, center);
567-
center.add(minX, minY);
568567
for (int index = 0; index < hull.length; index += 2) {
569568
hull[index] -= center.x;
570569
hull[index + 1] -= center.y;

core/src/com/spaceproject/systems/AsteroidShatterSystem.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,17 @@ private void spawnChildAsteroid(Entity parentAsteroid, float[] vertices) {
126126
vertices[p2], vertices[p2 + 1], // xy: 2, 3
127127
vertices[p3], vertices[p3 + 1] // xy: 4, 5
128128
};
129-
GeometryUtils.ensureCCW(hull);
129+
130+
//GeometryUtils.ensureCCW(hull);
131+
132+
//shift vertices to be centered around 0,0 relatively
133+
Vector2 center = new Vector2();
134+
GeometryUtils.polygonCentroid(hull, 0, hull.length, center);
135+
for (int j = 0; j < hull.length; j += 2) {
136+
hull[j] -= center.x;
137+
hull[j + 1] -= center.y;
138+
}
139+
130140
float triangleQuality = GeometryUtils.triangleQuality(hull[0], hull[1], hull[2], hull[3], hull[4], hull[5]);
131141
//if (triangleQuality < 2.0f) {
132142
//todo: add new vertices to break in half

0 commit comments

Comments
 (0)