I’m experimenting with the dyn4j integration on my editor, and I think I may not be updating the debug state properly:
When editing the shape of a body, I call removeAllFixtures() and add a new one.
It works as expected (only the new fixture is used for collision). However, the removed fixtures are still being drawn by the debug state, leaving a trail
What should I call to clear that, as that’s the only thing being dirty on screen?
I’m experimenting with the dyn4j integration on my editor, and I think I may not be updating the debug state properly:
When editing the shape of a body, I call removeAllFixtures() and add a new one.
It works as expected (only the new fixture is used for collision). However, the removed fixtures are still being drawn by the debug state, leaving a trail
What should I call to clear that, as that’s the only thing being dirty on screen?
public class PhysicsTestCase extends SimpleApplication {
Dyn4jAppState dyn4jAppState;
Body body;
Vector2 vectors[] = {new Vector2(-1, 1), new Vector2(-1, -1), new Vector2(1, -1), new Vector2(1, 1)};
float speed = 0.4f;
@Override
public void simpleInitApp() {
dyn4jAppState = new Dyn4jAppState(new AxisAlignedBounds(30, 30));
this.dyn4jAppState.setDebugEnabled(true);
this.dyn4jAppState.setEnabled(true);
this.stateManager.attach(dyn4jAppState);
// create the geometry that will be edited later
Polygon polygon = new Polygon(vectors);
body = new Body();
body.addFixture(new BodyFixture(polygon));
body.setMass(Mass.Type.INFINITE);
dyn4jAppState.getPhysicsSpace().addBody(body);
// create a dynamic body to show collision
final Rectangle boxShape = org.dyn4j.geometry.Geometry.createRectangle(.5f, .5f);
Body dynBody = new Body();
dynBody.addFixture(boxShape);
dynBody.translate(0, 2);
dynBody.setMass();
dyn4jAppState.getPhysicsSpace().addBody(dynBody);
}
@Override
public void simpleUpdate(float tpf) {
// notice that when the shape changes, the previous fixtures are still rendered
vectors[0].y -= speed * tpf;
vectors[3].y -= speed * tpf;
if (vectors[0].y < 0.25f) {
speed = 0;
}
body.removeAllFixtures();
Polygon polygon = new Polygon(vectors);
body.addFixture(new BodyFixture(polygon));
body.setMass(Mass.Type.INFINITE);
}
public static void main(String args[]) {
new PhysicsTestCase().start();
}