Builders for Bodies & Joints

Hi,

I've recently been experimenting with JBox2D and JavaFX, and I like it. One thing that makes coding easier are builders. I've created some for my own convenience and I'd like to share them if someone is interested. Here's the pattern I used to create them:

http://88.198.17.44/blog/2012/04/06/bui ... heritance/

In case you'd like this as a contribution, let me know. So far I've got RevoluteJointBuilder, CircleShapeBuilder, PolygonShapeBuilder, ChainShapeBuilder, BoxBuilder, but it's easy to create the rest. You can use them like this:

Body circle = new CircleShapeBuilder(world).position(0.2f, 1.4f).type(BodyType.STATIC).radius(.04f).build();

Body box = new BoxBuilder(world).position(0, 2.8f).restitution(.08f).halfWidth(2.7f).
halfHeight(world).angle(1.57079f).type(BodyType.STATIC).userData("wall").build();

new PolygonShapeBuilder(world).position(1.5f, 4.0f).type(BodyType.STATIC).
vertices(
new Vec2[]{
new Vec2(0, .7f),
new Vec2(.5f, .3f),
new Vec2(.5f, .5f),
new Vec2(0, 1.5f)
}).restitution(0.5f).friction(1).build();
I also added some convenience methods to make defining the vertices for Polygons less verbose, etc:

new PolygonShapeBuilder(world).position(0,0).type(BodyType.STATIC).vertices(
0.02f,0.0f, .02f,2f, 0.2f,2.2f, 0.02f,2.4f, 0.2f,2.6f, 0.4f,2.37f,
0.42f,2.45f, 0.1f,3.2f, 0.02f
).restitution(.08f).build();

In case you're interested, please let me know how to contribute. Keep up the good work and thanks for this project!

Toni
Nice use of the builder pattern, definitely cleans things up.

If you make an issue w/ a patch for putting the builders in their own package (org.jbox2d.builders), I can push it in the next 2.1.2 release (probably late May)
It took a while, but now I made a patch: http://code.google.com/p/jbox2d/issues/detail?id=38

Regards

Toni
Awesome, thanks a bunch!

Before I put it in, I'd like to have your consent for distributing this under the New BSD license under my name.

Also, I'm finishing up some summer work and moving back to the west coast, so this might not get patched in until a week or two, along with some other patches from other people.
I'm looking forward to the other patches. If you require some formal agreement, send it and I'll sign it. I'm fine with publishing it under your name and New BSD license; use and modify the code in any way you want.

--Toni

Original thread: https://box2d.org/forum/viewtopic.php?t=8417