Attached is some code that I've knocked together over the last week or so implementing a Engine on top of JBox2D in JavaFX. It uses the scene-graph objects from JavaFX to render the Circles and Polygons of JBox2D. So you get code like...
Code:
private function updateCircleShape(nextShape : Shape, nextBody : Body) : Void {
var circleShape = nextShape as CircleShape;
var nextCircle = circleShape.getUserData() as Circle;
if(nextCircle == null) {
nextCircle = Circle {
transform : myTransform;
stroke : Color.RED;
strokeWidth: 0.2;
}
insert nextCircle into myGroup.content;
circleShape.setUserData(nextCircle);
}
nextCircle.centerX = nextBody.getPosition().x;
nextCircle.centerY = nextBody.getPosition().y * -1;
nextCircle.radius = circleShape.getRadius();
}
Instead of following the DebugDraw approach which redraws the shape each time the JavaFX approach is to update the (x,y) coordinates of the "Node" object in the scene and let JavaFX take care of actually rendering it.
So it's all pretty rough around the edges but basically the best way to build it is to simply unpack the attached source zip into the JBox2D source directory and then build JBox2D just like you would normally.
Now the tricky part is... ...so that I could reuse the test classes that came with JBox2D I had to add a public constructor to AbstractExample and then any of the test classes I wanted to run.
Code:
public AbstractExample() {
createWorld();
create();
}
And then....
Code:
public class Domino extends AbstractExample {
public Domino() {
super();
}
Anyway if people are interested here it is.
Thoughts or feedback most welcomed.
Btw I don't know why the DominoTower test class doesn't work yet.