Box2D Java

Ok, 2.0.1 is pretty much set, now. There are still a couple issues, the Slick example is broken and I have to update the examples to properly use the new contact handling methods and make sure I've updated everything correctly, but the testbed examples all work correctly.

There's a .zip snapshot at http://jbox2d.svn.sourceforge.net/svnro ... 8-2008.zip, or you can sync to SVN at http://jbox2d.svn.sourceforge.net/svnroot/jbox2d/trunk/ - if you go to that URL in your browser, you'll see I've put up both a 1.2 MB full .jar file, which has the examples (executable to the testbed), Javadoc, and source attached, and a trimmed down library-only one, which weighs in at 156k. At some point I'm going to experiment and see if I can squeeze that down a little more using obfuscation, and I might also add Retroweaving to the build process to get 1.4 compatibility. Anyhow, you should be able to program and debug using the fat one, in theory getting full Javadoc and syntax completion (though I haven't tested it yet - just got done coding right now), and then use the trim one when you release. Beware, though: if any of your code touches the org.jbox2d.testbed package, you won't be able to use the trimmed jar.

Any bugs, suggestions, problems, please let me know!
Great work, thanks a lot.

I'm going to try it out this weekend.

By the way, you should drop a post at http://www.javagaming.org about this update, those guys will really appreciate continuous collision detection.

Keith
That's good news!
I just checked out from svn and everything looks fine (but I didn't have the time yet to test properly).
Thanks a lot!

Stefan
I just stumbled over the missing getContactList method in the body class - that's probably what you meant with
Quote:
have to update the examples to properly use the new contact handling methods and make sure I've updated everything correctly

Can I just de-comment the method and use it or what is the best way to go?

Stefan
Boing wrote:
I just stumbled over the missing getContactList method in the body class - that's probably what you meant with
Quote:
have to update the examples to properly use the new contact handling methods and make sure I've updated everything correctly

Can I just de-comment the method and use it or what is the best way to go?

Stefan


I don't think that's a good idea, but I'll soon be corrected if I'm wrong 😉

You should use the ContactListener mechanism to obtain Contacts.

Bill
Hi there,

First of all, we've been using JBox2D for quite a while now for our school project and it's coming along quit well! There's always some trouble when we update to a new repostitory version, but we can live with it. When everything is done I will make sure the complete source code will be released.

Anywho, I have a question concerning polyshapes in JBox2D (perhaps Box2D aswell?). I'm creating a simple 4-corner polygon, but somehow my bodies keep falling through it. What am I doing wrong?

Here's the code:
Code:
            PolygonDef sd = new PolygonDef()
            sd.clearVertices();
            sd.addVertex(new Vec2(-800.0f, 20.0f));
            sd.addVertex(new Vec2(-300.0f, 50.0f));
            sd.addVertex(new Vec2(-100.0f, 0.0f));
            sd.addVertex(new Vec2(-400.0f, 0.0f));
            ground.createShape(sd);


Also, will there be any support for Oval shapes later on?

Kind regards,
@SaphuA: You're creating that polygon clockwise instead of counterclockwise. If you just reverse the order that you add the vertices it will work right. This would cause an informative crash in C++, but in Java, though the assertions are all in the code, unfortunately they are turned off by default: you'll find development easier if you enable assertions while debugging. In Eclipse, at least, I can walk you through this: go to Run->Open Run Dialog..., select the launch configuration you're using, click the "Arguments" tab, and in the VM arguments box type "-ea" (without the quotes). Personally, for extra speed I like to use "-ea -server" but it all depends on your ultimate deployment - if you're posting to the web, you can't force people to use the server JVM, so you might as well develop with the same performance that your end user will get...with JBox2d and a Java 6 VM, the -server flag gives a decent performance boost (10-20% in some cases), so it's probably worth it if you can use it.

(Note: actually, I just realized that the CCW/convex poly test is disabled due to a private m_debug variable in PolygonShape.java - sorry about that, the assertion is never even tested unless that variable is set to true. I'll add a hack to test if assertions are enabled, and if so, set the m_debug variable to true.)

Re: the update troubles, sorry about that, unfortunately it's just one of those things that's impossible to manage perfectly. Things are getting more and more stable (I'm pretty happy with the API now, and I think Erin is as well), so this should be less of an issue as time goes on.

BTW, I might as well mention this here - three of my brothers and I are having a bi-weekly game making competition between ourselves, and one of them (Will) has posted a demo of one of his games that uses JBox2d and Pulpcore, up at http://rgbgame.nfshost.com/pulptron/ - the topic for this first round was to do a game based on the old real world game Crossfire, which you might remember from its ridiculous commercials. That's probably not where the game will live for good, so I'll post again when things get better settled. My attempt will be coming soon, though I'm already a day past the deadline...
Thanks, the2bears, for the answer concerning my question towards the contact list.
However, I do not feel very happy about not being able to retrieve the contacts of an object at a given time. Using listeners and keeping track of touching objects sounds like some redundancy between the physics engine and my application code to me (please correct me if I'm wrong).
Why was this mechanism changed?
And does the m_contactList field of a Body object still hold the correct information?
In case it matters: My access to the touching objects is read-only.

Any clearification would be greatly appreciated.

Stefan

P.S. Nice game, ewjordan - but your brother should set up a two-player web version 🙂
Boing wrote:
Thanks, the2bears, for the answer concerning my question towards the contact list.
However, I do not feel very happy about not being able to retrieve the contacts of an object at a given time. Using listeners and keeping track of touching objects sounds like some redundancy between the physics engine and my application code to me (please correct me if I'm wrong).
Why was this mechanism changed?

You're right, it's not totally convenient (and in fact, the 1.0 versions all used the contact list for that reason - of course, then people wanted listeners!), just look at the volume of forum traffic devoted to contact handling issues. But it's pretty much necessary because the introduction of continuous collision detection meant that in many hard collisions, the contact would be created and destroyed before the end of the physics step, so a list of the current contacts would not help you at all. There would be no way whatsoever to get at the details of sharp blows, so you could not play sounds or anything like that in response.

If you are only interested in lasting contacts you might be able to get away with changing m_contactList to public and reading the contact list from the world, but be warned - this is completely totally unsupported and likely will not act the way you think it should, which is why m_contactList is now package-access instead of public.

My suggestion is to look at the the ConcreteContactListener inner class in org.jbox2d.testbed.AbstractExample and the org.jbox2d.testbed.ExampleContactPoint class to see how the testbed caches contacts, it's pretty simple to create a list of stored contacts which you can then read off as needed. Just be aware that one contact may show up multiple times in various states.

For the next version I might set this up to be automatic if no other contact listener is registered.

Quote:
P.S. Nice game, ewjordan - but your brother should set up a two-player web version 🙂

[/quote]
Yeah, we thought about doing two player stuff, but at the moment we use NearlyFreeSpeech, which doesn't let you run Java on the server (or run a game server of any sort, for that matter). We used to have our own server, but haven't gotten around to getting another one yet. Soon...
Thanks for the clearification.
I need this for a platformer-like game and my idea was to make the player-body non-bouncing so that the player always has contact to the platform after landing on it. This contact information was to be used for deciding wether the player can control his avatar (when on a platform) or not (when in air).
I guess for this simple use, the contactList could work alright, but for other possible features I might need the listener architecture, so I might just as well implement that now.

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