Box2D Java

kirkjerk wrote:
Just to be pro-actively passive aggressive...

Don't worry about it - if nobody gave a nudge here or there, I'd never know what really needed to be done to make things a bit easier to use!
Quote:
I edited http://www.box2d.org/wiki/index.php?title=JBox2d so it mentions the steps needed to get rid of the unfunctioning Slick integration. Basic instructions like that should work without having to google for additional steps!

Yes, there definitely is a lot of cleanup that needs to happen; right now I have about 8 different versions of JBox2d on my computer, both stale and branched, as well as several C++ ones and a few AS3, so sometimes I lose track of what's actually going on in the release versions! Thanks for adding those instructions, at the next release (when that will be, I'm not sure - I've been swamped with work the past few months, so I haven't been able to do a JBox2d update in quite a while) I'm probably going to pull the Slick code out altogether, as it's too stale to be working and I have zero Slick experience, so am unlikely to pull it back into line.

Re: docs, nothing specific to Java at the moment. JBox2d is very close to Box2d apart from the C++ -> Java translation, so the C++ manual is pretty much the closest thing. The bindings between the physics model and the graphical view are always somewhat tricky no matter what language or libraries they are done in; I suspect the way the testbed does it may be a little opaque, especially if you're using the ProcessingDebugDraw class - the theory goes that you should be using your own real drawing class, but there are fairly few samples of how to do this, so that might be a good thing for me to add (a boring old sample project that shows basic simulation and drawing, without any of the testbed frills).

As far as Processing vs. Slick/PulpCore/JMonkeyEngine/etc., I've mainly used Processing and PulpCore. Personally, I find Processing the best of them all for prototypes, because it has great vector drawing support, and I'm a terrible artist, so the process of generating sprites tends to be a major time-sink for me; Processing also has the additional benefit that you can use the core.jar in a plain old Java project with no build script, whereas PulpCore requires Ant, which is slightly less convenient.

That said, PulpCore has fantastic functionality for games, far better than Processing (which is, after all, not a game library), and it's probably one of the most intelligently built libraries I've seen for that type of stuff (scene handling, sprites, animation, sound, user interface, etc.). It's as fast as software rendering can possibly be for sprites, but has no vector drawing ability. If you're interested in Java game dev, it's definitely worth checking out, it should be getting Android support soon, and can produce some very high quality stuff (Google "Milpa" to see an example).

But ultimately, it depends what you're trying to do, I suppose. For a lot of other things (esp. if graphical speed is an issue) you'll want an OpenGL game library like Slick or JMonkeyEngine, so it's probably worth playing with those a bit, too - I've definitely pushed both Processing and PulpCore past their comfort levels pretty easily by loading up on graphics, so some hardware help can be really useful sometimes (Processing can use OpenGL, but there's a lot of software transformation going on before the polygons hit the graphics card, so it's not as fast as Slick).
i found box2d is really useful
really fxxking cool

it helped me alot on my flash projects
pls keep up the good work
can't wait to se the processing version of it 😉
thanks for your answers!

yeah, I've been shying away from what documentation is out there, not sure what's applicable or not.

Does the C++ talk much about the typical "screen mappers"? It doesn't seem to, and in some ways that's where the money really meets the road. To mix a metaphor.

Besides possibly a "cookbook" (not sure if most of those topics would be touched on in that C++ yet), some kind of minimalist standalone "hello, world" might be worthwhile. The existing testbed is brilliant in many ways, but also gets in a lot of diagnostics and what not and isn't super easy to trace from physics step to graphical presentation. (Of course, at this point, I'm sort of new to doing it outside of the processing IDE anyway)

Incidentally, I got burned by the 1.5/1.6 thing -- my machine was 1.6, I took a stab at compiling against 1.5, messed it up a bit, went back to 1.6, "released" -- didn't work on OSX, and when I went back and got 1.5 to work I think I did see the improvements in Processing framerates .

Is the sensor stuff pretty well exposed in the Java port?
kirkjerk wrote:
Does the C++ talk much about the typical "screen mappers"? It doesn't seem to, and in some ways that's where the money really meets the road. To mix a metaphor.

Yeah, even though it's something that literally anyone working with Box2d has to deal with, there's a lack of authoritative information on how to do it best - that's probably an area worthy of some attention. Setting up a camera, figuring out how to bind sprites to bodies, mapping user input to world coordinates, etc. is a lot to do when all you want to do is see something on the screen, it would be nice to have some nicely debugged classes to handle that that one could just drop in to a project.

If I get some time, I'll try to at least throw together a mini-tutorial covering this at some point, it would definitely be helpful.

Quote:
Besides possibly a "cookbook" (not sure if most of those topics would be touched on in that C++ yet), some kind of minimalist standalone "hello, world" might be worthwhile. The existing testbed is brilliant in many ways, but also gets in a lot of diagnostics and what not and isn't super easy to trace from physics step to graphical presentation. (Of course, at this point, I'm sort of new to doing it outside of the processing IDE anyway)

I agree, a bare-bones example would be great, I'll definitely put something like that in for the next one, demonstrating just the essentials.

Quote:
Is the sensor stuff pretty well exposed in the Java port?

Should be. When you create a ShapeDef of some variety, you should be able to mark the isSensor property.

The Java version still doesn't have the improved contact handling that BorisTheBrave has been working on, though, so you'll still have to use contact listeners.
If you're willing to handhold a bit, I'd be willing to put in some work on that stuff...
You know I just now bothered to google for box2d on the processing.org site, and found
http://www.jbox2d.org/processing/
which is probably closer to what I was looking for this weekend - much closer to a "Hello, World" there--
I need to play with it later, but I think that kind of thinking might be the best people who might be starting with a base in Processing...
the question about what to expose and what to hide is probably the trickiest bit...
I notice jbox2d implements the Segment class, but I didn't see anything in world for raycasting.

I know there's world.query, but this isn't helpful in some situations (For instance, determining if there is an obstacle in a projectile's path) since it only works on AABB areas.

Is there a solution I'm missing? I know I didn't see anything in world for the raycasting methods listed in the wiki ( http://www.box2d.org/wiki/index.php?title=Raycasting )
kirkjerk wrote:
You know I just now bothered to google for box2d on the processing.org site, and found
http://www.jbox2d.org/processing/
which is probably closer to what I was looking for this weekend - much closer to a "Hello, World" there--
I need to play with it later, but I think that kind of thinking might be the best people who might be starting with a base in Processing...
the question about what to expose and what to hide is probably the trickiest bit...

Indeed; I've already gotten BoxWrap2d complaints both about missing features and about things being too complicated to understand, so it's a delicate balancing act. But I think overall, it has potential to be a great simplification, since it's fairly easy to hide some of the details when you're coding to a single I/O API.

That wrapper helps deal with the camera stuff a bit, as it simply maps everything to pixel coordinates as long as there's a wrapped function, so it's probably worth taking a look at. Unfortunately the external documentation is a bit thin (there should be decent Javadoc, though, which can't be viewed within Processing but should be visible in Eclipse if I set the .jar up correctly), and there are still several gaps in the API that I know of that I need to fill in.

FWIW, I'm also in the midst of working on a wrapper like that for PulpCore, written in Scala - Scala has some truly fantastic features for stuff like this, and if it's "bang for your buck" that you're after, it's a language well worth the time to learn (I'll be honest, it takes some time to learn, I'm not quite "there" yet myself but I'm still finding it very useful). There's even a Processing Scala IDE that someone whipped up (Google "Processing in Scala SPDE") if you're curious to play with it in a more familiar environment.

FireSlash wrote:
I notice jbox2d implements the Segment class, but I didn't see anything in world for raycasting.

You're correct - the raycast functions haven't been added yet (if you actually look at the Segment class, the guts are all commented out and haven't been ported). Sorry about that, though I've known about that for a while, it didn't make it onto my JBox2d todo list (it probably predates that list's existence, I used to just try to keep it all in my head), so I just added it.

At some point over the next couple weeks, I promise I'll put out a solid update; there are a lot of things that desperately need attention, and I have lots of local changes that I can't commit until I merge some other optimizations, so it will be good to freshen things up a bit. I'm pretty psyched to get things recent so that I can start taking a look at making this run in parallel.
ewjordan wrote:
As far as Processing vs. Slick/PulpCore/JMonkeyEngine/etc., I've mainly used Processing and PulpCore. Personally, I find Processing the best of them all for prototypes, because it has great vector drawing support, and I'm a terrible artist, so the process of generating sprites tends to be a major time-sink for me; Processing also has the additional benefit that you can use the core.jar in a plain old Java project with no build script, whereas PulpCore requires Ant, which is slightly less convenient.


I've been taking a serious look at Scala and was wondering if you have any thoughts in regard to it's validity as an alternative to classic Java. Game development with jBox2D and Processing (or Slick2D) looks very doable from my research the last few days.

I've always wanted to try a functional programming language (to take advantage of concurrency, multithreading, etc.) and Scala looks like a very good place to start. Processing also looks appealing in that it has a feature rich set of rendering tools (which remind me of Flash) and SVG graphics capability. Processing's Geomerative library can also import vector coordinates from SVG files for easy Box2D model creation...! I'm no artist and I like the idea of creating game models in Inkscape that I can directly import into my game without having to hardcode all the vector coordinates or resorting to bitmap sprites...

From what I understand, Slick2D is OpenGL hardware accelerated vs. Processing's hybrid approach? This would obviously give Slick2D a performance advantage, although I'm not sure if it can match Processing's feature rich drawing library?

Any thoughts or direction would be greatly appreciated.
Zzzzrrr wrote:
I've been taking a serious look at Scala and was wondering if you have any thoughts in regard to it's validity as an alternative to classic Java. Game development with jBox2D and Processing (or Slick2D) looks very doable from my research the last few days.

I love Scala, personally. For single person or small group projects, it's fantastic (for bigger groups, it can be trouble because it's so powerful, with implicits and whatnot) - the language is just so much more powerful than Java or C++, though it has a bit of a learning curve and takes some getting used to. The only problem with it right now is that the IDE plugins leave a lot to be desired, and you won't get the full support that you're used to from Java.

Watch out using recursion too heavily, I know it's "proper" functional style, but the JVM still doesn't support tail calls, so you'll blow stack if you do deep recursion. I forget off the top of my head if the Scala compiler optimizes self-recursion, it might, which would help for most recursive functions.

But yeah, definitely check it out. scalac can now fully support cross dependencies between Java and Scala, which eases development quite a bit, and if you use Proguard you can shrink the Scala library to almost nothing (otherwise it adds a few megs to download size).

Quote:
From what I understand, Slick2D is OpenGL hardware accelerated vs. Processing's hybrid approach? This would obviously give Slick2D a performance advantage, although I'm not sure if it can match Processing's feature rich drawing library?

Yup, Slick is vastly speedier as far as graphics goes. Even in OpenGL mode, Processing does all geometry transformations in software, which can eat up a lot of power. I did some tests in Slick, and it can handle thousands upon thousands of raw drawing ops without a hiccup, whereas Processing would choke under the load.

But as you noted, it doesn't have as great vector drawing support, so it's definitely a trade-off. I suppose it really depends what you're trying to do, ultimately; for me, Processing tends to be more comfortable because I'm very used to it and I know the internals (I wrote the perspective-corrected texture mapping code for P3D). I'd give them both a shot and see which fits your particular use case better.

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