Skip to content

Commit

Permalink
Partial fix #30!
Browse files Browse the repository at this point in the history
-partial fix for #30 (fucking finally...)
-NOTE: the child polygon origin is still incorrect. only the drops spawn location is now correct relative to the polygon.
  • Loading branch information
0XDE57 committed Oct 9, 2024
1 parent b225ac6 commit 737c336
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/src/com/spaceproject/systems/AsteroidBeltSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ private void asteroidDestroyed(AsteroidComponent asteroid, Vector2 parentPos, Ve
shatterAsteroid(parentPos, parentVel, parentAngle, parentAngularVel, asteroid);
} else {
//todo: pool drops
Entity drop = EntityBuilder.dropResource(parentPos, parentVel, asteroid.composition, asteroid.color);
GeometryUtils.polygonCentroid(asteroid.polygon.getVertices(), 0, asteroid.polygon.getVertices().length, center);
center.rotateRad(parentAngle);
Entity drop = EntityBuilder.dropResource(parentPos.add(center), parentVel, asteroid.composition, asteroid.color);
getEngine().addEntity(drop);
}
}
Expand Down Expand Up @@ -333,15 +335,16 @@ private void spawnChildAsteroid(Vector2 parentPos, Vector2 parentVel, float pare
hull[j] -= center.x;
hull[j + 1] -= center.y;
}
//center.rotateRad(parentAngle);
//parentPos.rotateAroundRad(center, parentAngle);
//todo: rotate center relative to parent by angle?
//Vector2 pos = parentBody.getPosition().cpy();//.mulAdd(center.rotateAroundRad(parentBody.getPosition(), parentBody.getAngle()), 0.1f);
//center.rotateAroundRad(parentBody.getPosition(), parentBody.getAngle());
//Vector2 pos = parentBody.getPosition().cpy().add(center);
//Vector2 vel = parentBody.getLinearVelocity().cpy();
}


float angularDrift = Math.max(MathUtils.random(-maxDriftAngle, maxDriftAngle), minDriftAngle);
//todo: rotate center relative to parent by angle?
//Vector2 pos = parentBody.getPosition().cpy();//.mulAdd(center.rotateAroundRad(parentBody.getPosition(), parentBody.getAngle()), 0.1f);
//center.rotateAroundRad(parentBody.getPosition(), parentBody.getAngle());
//Vector2 pos = parentBody.getPosition().cpy().add(center);
//Vector2 vel = parentBody.getLinearVelocity().cpy();
Entity childAsteroid = EntityBuilder.createAsteroid(parentPos.x, parentPos.y, parentVel.x, parentVel.y, parentAngle, hull, asteroidComponent.composition, true);
childAsteroid.getComponent(PhysicsComponent.class).body.setAngularVelocity(parentAngularVel + angularDrift);
getEngine().addEntity(childAsteroid);
Expand Down

0 comments on commit 737c336

Please sign in to comment.