Box2D Java

found this quite by accident, registered just to say it's very cool, excellent work on the port, looks very promising, kudos 🙂
Hi, davbol, glad you found your way here! I know you spend some time over at http://www.processing.org, so it's probably worth mentioning that soon (probably with this version, 1.4.3) I'm going to package this up as a proper Processing library - unfortunately this uses some Java 1.5 stuff currently, which requires either some RetroWeaver magic or a little re-programming to target 1.4, and the package structure is not right for Processing to use as-is, so I have to do a little reorganization before I can get it working in the PDE. But it should integrate pretty well, right now the graphics in the demos are all handled by Processing, so expect to see an announcement of that soon.
re: 1.4 compatibility - it definately would be nice if it compiled straight from the IDE, but I can't imagine it's going to be a "simple" or "beginner's" library, so perhaps most of your target audience would know how to run Processing with a newer JRE. (though 1.4 is still the fastest for rendering)

This'll be _HUGE_ in the processing community - you'll be a veritable rock star for porting it. 😀 I myself may avoid it initially, though i'm starving for dynamics, just to avoid the initial "fad rush" (witness sunflow). But I can imagine there will be a ton of "more serious" applications within the scope of works typically realized via Processing.

..and some more physics-enabled Java games ain't a bad thing either. 🙂
cheers,
first off, thank you guys for making jbox2d - it's a really useful library!!

I am working on a processing application and have managed to get jbox2d working with it in the standard IDE (using retroweaver as suggested). and so far i am very impressed with it's performance. i just have some questions on object behavior that i didn't expect- my objects seem to be sliding over each other somewhat and overlapping. is this expected behavior? and if so is there a way to switch this off or reduce it - currently i haven't found any parameters that affect this. i've also noticed that in the jbox2d demos some of the same is happening - e.g. objects falling outside of the washing machine demo by sliding over the "drum" objects.
Hm, well a little bit of overlap is expected, at least until continuous collisions are ported to JBox2d, but I'm not sure exactly what you mean by sliding, and whether it's a bug or not (I assume changing the body friction values didn't help?). Look at the washing machine demo at http://www.jbox2d.org/demos/washingmachine.html - I think this is the most recent (1.4.3) build. Can you reproduce the problem with that applet? I tried, but unless I drag a box really fast against the edge nothing slips out of the drums...if you're talking about the "tunnelling" problem, where a really fast object moves through another object, that's a different issue, one that will only be fixed by CCD.

Also, a tiny bit of overlap is necessary due to the linear slop factor; if you use extremely small objects this will definitely look weird. Any chance you could post some code to describe the issue you're having, or maybe a screen shot? If there's a bug and the behavior differs from the C++ and AS3 versions, I'd like to handle it, but if it's the same as those, the solution is to wait for CCD. Processing code is fine by me, BTW, I've got it running in that environment, too.

BTW, I've made an actual Processing library as well, but I was hoping to flatten the structure so that all you need is a single "import org.jbox2d.*" statement rather than a whole bunch of ugly imports, and I've run into a name conflict with AWT's shape class...aargh!!! I'll upload it once I decide how to best deal with this (probably I'll rename Shape to b2Shape in this one case, for the Processing library - nobody should be touching that class anyways apart from debug drawing, so it won't be a big deal).
How would you use this in an app that wants to use a drawing library other than Processing? From the examples, it seems that model and view are tied together, and the view is bound to Processing through core.jar.
The view are only the tests, and those yes are renderes using processing. You can render the views using whatever rendering engine you want, name it Java 2D, JOGL, LWJGL, etc
Good to hear. However, I still don't understand what method calls I would use to get the data I would want to render. Do you have any examples?
basically you setup you objects, apply forces to them (gravity can be one), use World.step() and then ask the objects for their position

the loop would be like this:

Code:
setupObjects();
while (true) {
   handleInput();
   world.step();

   drawWorld();
}


drawWorld it's basically the same there is now, but using your own rendering engine, you just get the object position, rotation, etc, and then call the apropiate drawing methods
fyzle: It's worth mentioning that a "real" application would probably not access the shapes at all during the draw loop, preferring instead to bind sprites directly to the body position (this also solves an annoying Java issue, that our Shape class may name-collide with AWT's Shape class, by not forcing you to read shapes at all). I actually have an example of this using Processing, but it looks like I forgot to upload it to SVN. When I do, I'll post a note - that will give you an idea what calls you should be using, at least.

We decided to use Processing in the examples because it gives two things: 1) easy framerate handling (it just calls the draw() method frameRate times per second), and 2) an idiot proof drawing API that requires almost no setup but looks pretty good. All of the other logic in the PTest.java file (basically anything apart from drawing code and some of the stuff in the setup() function, which is called on initialization) should translate to any game engine pretty easily.

However, you're right, the testbed as written doesn't explain very well how you'd do this stuff without Processing, so I'll add making a bare-bones example template to my todo list.

Out of curiosity, do you have another library in mind? Processing is not ideal for full fledged games, it's better suited to smaller demos, so I would definitely be interested in including some examples that use other engines or libraries. We were talking a while back about maybe using JMonkeyEngine, but I don't know it very well and I'm a bit overextended right now to learn it. The only thing I'm opposed to is bare Java, because it's painful to do this type of thing in it (our first examples were done that way, but eventually we gave it up because it was too much trouble).

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