Skip to content

Commit 8440e86

Browse files
committed
debugging, re break #30
-makes duplication issue so bad its almost unplayble. -remove some dead code -notes -remove velocity drift
1 parent 65a1352 commit 8440e86

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

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

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
import com.spaceproject.generation.BodyFactory;
2121
import com.spaceproject.generation.EntityFactory;
2222
import com.spaceproject.generation.TextureGenerator;
23-
import com.spaceproject.math.MyMath;
2423
import com.spaceproject.utility.Mappers;
2524
import com.spaceproject.utility.SimpleTimer;
2625

2726
public class AsteroidShatterSystem extends EntitySystem implements EntityListener {
2827

2928
private final DelaunayTriangulator delaunay = new DelaunayTriangulator();
3029
private final float minAsteroidSize = 100; //anything smaller than this will not create more
31-
private final float maxDriftVel = 2.0f; //drift when shatter
3230
private final float maxDriftAngle = 0.25f; //angular drift when shatter
3331

3432
@Override
@@ -62,21 +60,15 @@ public void entityRemoved(Entity entity) {
6260
private void shatterAsteroid(Entity parentAsteroid, AsteroidComponent asteroid) {
6361
float[] vertices = asteroid.polygon.getVertices();
6462

65-
//debug center of mass / origin
66-
Vector2 center = new Vector2();
67-
68-
GeometryUtils.polygonCentroid(vertices, 0, vertices.length, center);
69-
if (!asteroid.centerOfMass.epsilonEquals(center)) {
70-
Gdx.app.debug(this.getClass().getSimpleName(), "WARNING: polygonCentroid disagreement");
71-
}
72-
7363
//create new polygons from vertices + center point to "sub shatter" into smaller polygon shards
7464
int length = vertices.length;
7565
float[] newPoly = new float[length + 2];
7666
System.arraycopy(vertices, 0, newPoly, 0, vertices.length);
77-
//add new point in center of triangle
78-
newPoly[length] = asteroid.centerOfMass.x;
79-
newPoly[length + 1] = asteroid.centerOfMass.y;
67+
//add new point in center of polygon
68+
Vector2 center = new Vector2();
69+
GeometryUtils.polygonCentroid(vertices, 0, vertices.length, center);
70+
newPoly[length] = center.x;
71+
newPoly[length + 1] = center.y;
8072

8173
spawnChildAsteroid(parentAsteroid, newPoly);
8274
}
@@ -114,7 +106,7 @@ private void spawnChildAsteroid(Entity parentAsteroid, float[] vertices) {
114106
*/
115107

116108
ShortArray triangles = delaunay.computeTriangles(vertices, false);
117-
//Gdx.app.debug(this.getClass().getSimpleName(), "shatter into " + triangles.size);
109+
Gdx.app.debug(getClass().getSimpleName(), "shatter into " + triangles.size / 3);
118110

119111
//create cells for each triangle
120112
for (int index = 0; index < triangles.size; index += 3) {
@@ -133,23 +125,11 @@ private void spawnChildAsteroid(Entity parentAsteroid, float[] vertices) {
133125
Vector2 center = new Vector2();
134126
GeometryUtils.polygonCentroid(hull, 0, hull.length, center);
135127
for (int j = 0; j < hull.length; j += 2) {
136-
hull[j] -= center.x;
137-
hull[j + 1] -= center.y;
128+
//todo: shift, but fix spawn origin relative to parent body
129+
//hull[j] -= center.x;
130+
//hull[j + 1] -= center.y;
138131
}
139132

140-
float triangleQuality = GeometryUtils.triangleQuality(hull[0], hull[1], hull[2], hull[3], hull[4], hull[5]);
141-
//if (triangleQuality < 2.0f) {
142-
//todo: add new vertices to break in half
143-
// because the current shatter creates long ugly slivers
144-
//}
145-
/*
146-
Gdx.app.debug(this.getClass().getSimpleName(),
147-
MyMath.round(hull[0],1) + ", " + MyMath.round(hull[1],1) + " | " +
148-
MyMath.round(hull[2],1) + ", " + MyMath.round(hull[3],1) + " | " +
149-
MyMath.round(hull[4],1) + ", " + MyMath.round(hull[5],1) +
150-
" | clockwise: " + GeometryUtils.isClockwise(hull, 0, hull.length) + " | quality: " + triangleQuality);
151-
*/
152-
153133
//discard duplicate points
154134
if ((hull[0] == hull[2] && hull[1] == hull[3]) || // p1 == p2 or
155135
(hull[0] == hull[4] && hull[1] == hull[5]) || // p1 == p3 or
@@ -164,14 +144,11 @@ private void spawnChildAsteroid(Entity parentAsteroid, float[] vertices) {
164144

165145
//add some variation in velocity and angular so pieces drift apart
166146
Body parentBody = Mappers.physics.get(parentAsteroid).body;
167-
Vector2 pos = parentBody.getPosition();
147+
Vector2 pos = parentBody.getPosition();//todo: .cpy().add(center); NOT WORKING, WHY??S
168148
Vector2 vel = parentBody.getLinearVelocity();
169-
Vector2 driftVel = MyMath.vector(MathUtils.random(0, MathUtils.PI2), maxDriftVel);
170-
vel.add(driftVel);
171-
float angularDrift = MathUtils.random(-maxDriftAngle, maxDriftAngle);
172-
173149
Entity childAsteroid = EntityFactory.createAsteroid((long) (Math.random() * Long.MAX_VALUE),
174150
pos.x, pos.y, vel.x, vel.y, parentBody.getAngle(), hull);
151+
float angularDrift = MathUtils.random(-maxDriftAngle, maxDriftAngle);
175152
Mappers.physics.get(childAsteroid).body.setAngularVelocity(parentBody.getAngularVelocity() + angularDrift);
176153
getEngine().addEntity(childAsteroid);
177154
}

0 commit comments

Comments
 (0)