JBox2D + Slick2D Sandbox

Hey all, I'm working on a project right now using JBox2D and Slick2D, in the end, being something similar to Falling Sand Game with rigid bodies, instead of particles (though in future revisions I may add some of those as well) It will be highly extensible, with the ability to create your own materials, and put them into the environment.

My problems right now are with the lack of documentation available at the moment, I'm hoping that come 2.0, with Doxygen support for upstream, Javadocs will come as well. Regardless, I'm having trouble rendering rotations of the bodies, as I can't figure out how to find the point of rotation, in order to pass that to Slick2D's rotation transform method. Any thoughts? I'm 90% convinced that my errors are simply in the rendering of the environment, not the environment itself.
Hi Haydre,

Yeah, we haven't had the time yet to put together Javadocs for this, I would say for the moment, use the Box2d docs. Most things are the same except for naming conventions (b2PolyDef -> PolyDef, AddShape() - > addShape(), etc.) - I think there might be a tiny difference in how to create polygons, too, but there should be a few examples in the source that cover that.

I always loved the falling sand games, I'm very interested to see what you come up with. One thing, make sure you've got the most recent SVN build, I think the last actual release we did was 1.0.0, but SVN is up to 1.4.3 now (I can't do the release myself right now, I'll have to talk to quixote_arg about that).

As far as the rotation problems, if you want to post some code (or a link to it) I can try to help out - I got this working at some point, but I don't have the code in front of me right now and it wasn't using Slick.
I wasn't aware that the release was not up to date, I'll work on porting it to the latest version, and see if that fixes anything. Any idea though, if put a long rectangle half on top of a square, the half that's in the air will rotate around the corner of the square. Is there any way, in the code, that I can find that vertex? Because I need to send the center of rotation to slick, so it will render correctly, and I can't figure out how to find it.
I must confess I didn't work on the project for a couple of months now... I want to do a round of "javaization" of things (using LinkedList instead of pointers to next and previous) and that kind of stuff, and then profile. I still don't know if the bottleneck is the creation and garbage collect of objects, maybe an object pool can help... probably the best move is to port everything to 2.0 and then start optimizing, either way, we are always two steps behind Erin 🙂
Quick Update on what's going on, I was having some problems with my rendering engine, due to some early, and very misguided design decisions.

I've been trying to backtrack and implement rendering correctly, but every IDE I've used decides to hate me. Netbeans won't run the compiled app (I think a bug with self-signed code), so I resorted to Eclipse, which is now crashing nearly every time I try to change anything.

Also, I found that both Slick 2D and Box 2D Both define a Shape object, and since the B2 prefix has been removed from JBox 2D objects, I need to set up a workaround so I can pick one type or the other.

I didn't even bother trying to compile JBox 2D from SVN, I'm just going to wait for release and port it up. Any idea when it will be up to date?
Quote:
Also, I found that both Slick 2D and Box 2D Both define a Shape object, and since the B2 prefix has been removed from JBox 2D objects, I need to set up a workaround so I can pick one type or the other.

Yeah, that was a problem for me, too, as AWT has a Shape class as well. In theory Java's package structure is supposed to make this okay, but really it's a mess to deal with (you have to not import some of it and refer to it by its full name).

quixote_arg, do you have any objection if we add the b2 prefix back to Shape, or any other ideas how to make it easier to handle the conflicts?
I think there's some sort of typedef like command in java that I could locally set to specific shape classes, no need to change it upstream and break style with the system.
Yeah, that's true, you can use the so-called "poor man's typedef", just set up an empty class that extends the one with the conflict (specified, of course, by its fully qualified name). This might even work in this case if all you need to do is read the shapes. This is kind of a dirty trick, but it may be enough to get by in this case, I'm not positive.

That reminds me, I also need to move the files into their own jbox2d package...I'll have to think about how to deal with all this stuff a little more.
Alright, well one issue is solved - I tagged the 1.4.3 release, and there's a zip you can download at https://jbox2d.svn.sourceforge.net/svnr ... -1.4.3.zip. You should be able to import the thing into Eclipse and be up and running very quickly.

I'm moving everything into "proper" packages right now (I'm tentatively using org.jbox2d as the main package), but it's taking a while since there's some reflection stuff in the testbed that needs to be manually changed under a package switch. I'm thinking I'll wait until 2.0 to put this switch in a release, I don't want to break any code that anyone has already made (2.0 will break a lot of it, so I feel less bad about it then).

As far as the Shape conflict, if you use Eclipse you might just want to refactor->rename that particular class in your project; you're importing the source anyway (which reminds me, adding a trimmed down .jar to the build script would be a good thing for my todo list...), so that shouldn't be too big a deal. If you're not using Eclipse, I'm not sure how simple it will be, though any decent IDE should allow it.
Nice job, just finished compiling it and the migration was flawless, not a single problem as a result. I just ran what I have so far, and my fps has over doubled from 15-17 to 35-38. I still have some optimisations of my own to so on my render method, and I hope to hit a consistent 40 fps.

As to a status update, I have a set window, with a ground box, and the ability to draw dynamic rectangular boxes into the environment. The renderer also, at this time, supports circles, though the ability to switch has yet to be put in. Objects fall smoothly now, thanks to the latest jar, and the one major problem I have left is the lack of rotation of my shapes, which I'll fix as soon as I better understand the way Box2D represents rotations.

I'll keep you updated.

Update:
I've gotten the angle into radians, as they should've been from the start, and I'm scaling it correctly, but it seems like Slick 2D's RotateTransform() wants to rotate around the origin of the screen. There is an overloaded version that takes input of x and y to rotate around, but when I use them, my entire viewport goes screwy, even my ground box disappears below the screen. I've pastebin'd what I have so far at http://www.pastebin.org/17194
I'm sure there are things I've done way wrong, or roundabout, and I'm interested in hearing about any you might see, but my main focus, at the moment is the rotation.

P.S.
Funny story, I normally use NetBeans as my IDE of choice, however for some reason, perhaps a bug, perhaps I'm trying to put a round peg in a square hole, I can't get my project to compile in NetBeans, and it wants to run everything in Webstart mode, and I can't convince it otherwise. For those reasons, I've been using Eclipse for this, and have gotten used to it, and it's not bad. I have yet to figure out, however, how to import projects with existing code into eclipse without an ANT buildfile, and since JBox2D 1.4.3 was in src, I was at a loss for how to compile it. I had to go back to NetBeans to compile the jar to migrate up to in Eclipse... I am inefficient.

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