Box2D Forums

It is currently Thu May 23, 2013 4:26 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Apr 24, 2012 11:08 pm 
Offline

Joined: Tue Apr 24, 2012 10:54 pm
Posts: 7
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


Top
 Profile  
 
PostPosted: Wed Apr 25, 2012 1:03 am 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 353
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)


Top
 Profile  
 
PostPosted: Tue Aug 21, 2012 7:30 am 
Offline

Joined: Tue Apr 24, 2012 10:54 pm
Posts: 7
It took a while, but now I made a patch: http://code.google.com/p/jbox2d/issues/detail?id=38

Regards

Toni


Top
 Profile  
 
PostPosted: Wed Aug 22, 2012 4:46 pm 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 353
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.


Top
 Profile  
 
PostPosted: Wed Aug 22, 2012 11:27 pm 
Offline

Joined: Tue Apr 24, 2012 10:54 pm
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: psbot [Picsearch] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group