Box2D Java

Hi! I'm waiting to try your port, thanks for going to all of the effort!

I used Phys2D (http://www.cokeandcode.com/phys2d/), a port of Erin's GDC code before Box2D was launched. It was kindly ported by Kevin Glass 🤓 and he added stuff to it too.

I liked it but was waiting for polygon support, which was added by another fellow, but it didn't work ideally - a Polygon in the shape of a box did not behave the same as a Box unfortunately.

Since Erin added polygon support, which I assume works well, I'd like to try it but I have no idea about c++ - i don't even know how to try the demos. So thanks for getting this ported to Java.

Maybe you should consider contacting Kevin Glass about your efforts. He's a top bloke and I'm sure he'd have something to say, maybe there'd be a way for you guys to cooperate. You probably know about this already, and I think I've seen quixote there, but you should post your first release at http://www.javagaming.org.

Cheers guys,
Keith 🤓
Hey there Commander!

I posted on the Slick forum, which has a Phys2d subforum about Box2D, basically Kevin doesn't have time to do a full port, but he is willing to help. ewjordan (mostly) and already have a 1.0.0 alpha version working... some tiny features to polish, a few demos to upload to the to-be-made sourceforge page and we are up and running!

Source code is always downloadable from the SVN repository at sourceforge, but I think that soon we will do a release, and of course post about it on the javagaming forum. Of course, testers, bug reports, improvements and suggestions (donations also, why not 🙄) will be most welcomed
salute!
We've finally got everything up and running pretty well, so I figured it was probably about time to post a demo:

http://www.ewjordan.com/Pendulum

This is just the Pendulum test; all the tests are actually somewhere in the .jar file that downloads, but I didn't get a chance yet to set up the HTML to view them. It seems to be running pretty well, though we're still doing some optimizations for Java (there's a lot of data handling that will be better served by using the built Java collection classes than by handling it ourselves, mainly because they can natively optimize those classes whereas our code has to be sandboxed). In case you're wondering, yes, mouse picking is enabled, it's just kind of difficult to aim well enough to grab the pendulum. Zoom in and it's easier, or launch a bomb and grab that.

Hopefully we'll do an actual release over the next couple of days. I'll also try to get the rest of the demos up ASAP. This is still the 1.0.0 code, so after this initial release we'll start upgrading it to bring it in line with the most recent Box2D release.
Nice work guys! Functions very well here 😀 . Can't wait for a release.

Cheers,
Keith 🤓
Considering a .NET port... easier to take java and port or C++?

Java's all ported to classes and references (not pointers)?

J
Hmm, I don't know much about .NET so I'm not sure that I can really point the way as to which port would be easier. Yes, everything is changed from pointers to refs, so if C# requires that, the Java version might be an easier transition; there were also a lot of issues in getting object initializations and copies to happen correctly, as C++ does a lot of this stuff implicitly whereas Java makes you actually force it in a lot of cases. On the other hand, I suspect that a lot of the tougher things we had to deal with to achieve a Java version (stuff where the appropriate syntax just doesn't exist in Java) will be easier in C#, which was explicitly designed to leverage a lot of C/C++ knowledge. Also, we don't have any of Erin's memory-management code, so if you were planning to take that over, the Java version won't help at all.

Also, JBox2D is currently based off of the Box2D 1.0.0 code, though we're hoping to get it updated soon. We just turned out to be far enough along with the 1.0.0 port by the time all the updates came out that it made more sense to finish it up before updating. So you might either want to start off with the 1.3.0 C++ version and refer to the Java version if you have problems, or wait until we get our version up to date.

Also, doing a port of a port could lead to a telephone-like situation, where errors that we've made during translation get compounded by another round of translation. So keep all of this in mind; my suggestion is probably to go from the C++ but to take a look at the Java if you have any problems.
Here's a question for Erin, primarily: we're updating towards 1.4.0 now, and most of the structural changes are done (yay!), so all that's left is pretty much to add the gear and pulley joints, then we'll be in line and current. However, I've still been unable to get rid of one minor problem, even after updating all the code and literally checking each file side by side to make sure we've got all the stuff in there.

The problem is that if I run with assertions enabled, we're tripping one on the equivalent of line 56 in b2ContactSolver.cpp:

b2Assert(manifold->pointCount > 0);

That's within the constructor for b2ContactSolver, in the j loop over the manifolds in a contact. It always seems to happen when it checks manifolds[0] on something whose AABB collides with something else when the objects themselves don't actually collide.

If I just disable the assertion, everything seems to run without trouble, so I'm really not sure what's going on. Do you have any idea what might be going on here, and if it's something that I should be very concerned about?
There shouldn't be any manifolds with zero points. Look at b2ContactManager.cpp line 202:

Code:
if (oldCount == 0 && newCount > 0)
{
    b2Assert(c->GetManifolds()->pointCount > 0);


You should put that assertion in there. Basically, a contact with zero manifolds (and thus zero points), should never be hooked up to its bodies and participate in an island. Islands are based on joints and contacts that actually touch.
Ah, perfect - thank you, that led me right to the spot. I was reading an array length (Java stores them with the array) instead of the pointCount variable, which didn't work because the arrays are all initialized to the same size, empty or not.

This should be done in a day or two now, I'll post a note here with some demos when I get those last few files ported.
JBox2D is now in line with the current Box2D from SVN, as far as I can tell. I'm still not sure that it's entirely debugged, as I just got the last tests running correctly a few minutes ago, but it runs...

I put up most of the testbed demos at http://www.ewjordan.com/jbox2d/, give them a try and let us know if you see anything wrong. Source for the engine is (as always) available at http://www.sf.net/projects/jbox2d.

quixote_arg, I finally did a commit of this stuff, so let's let this one simmer for a couple days, then release it; at least for the moment, let's try to match Box2D's version numbering, so I guess this would be 1.4.0, right? We should start to think more about optimizing now that we're up to date. We also need to rework some function names (in some cases we've changed to camel-case, but in some we've kept the capitalization of Box2d; we need to decide on a good policy here, because it would be great if we could just refer people to the Box2d docs instead of writing our own...), and also, we should do a run through at some point and add license terms on each file, because I think a lot of them are missing it. When I get a chance (or if you'd like to, just let me know if you get to it before me) I'll put together a .jar file trimmed of everything unnecessary that we can distribute so that people don't need to copy/paste our source code in order to use this.

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