JBox2D + Slick2D Sandbox

Quote:
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.

Hmm, I'll have to take a closer look - the rotation stuff is always a bit tricky, you need to figure out what conventions the engine uses for its transforms. It's probably OpenGL-style, but I'll check in more detail later. Usually you have to do three steps:

1) Transform so center of mass is at (0,0) - often this means shifting the box by its half width/height or something like that
2) Rotate about (0,0)
3) Transform so that the center of mass is at the proper world location

It's just a question of how exactly to do that using Slick, which I'm not sure of at the moment.

Quote:
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.

I'm pretty sure if you create a new project, and then go to File->Import, under "General" there should be an option to import existing source files without needing to have a .jar, that's what I usually do. As for compiling, especially when using external libraries it's always a pain...get used to mucking with the build path settings and the "Run as..." dialog, is my advice. I rarely use NetBeans (don't know why, just more used to Eclipse), so I don't know what could be going wrong there.
So the wiki documentation for the Geometric mutations (which I would assume would include rotations) for slick 2d is not done yet, so I'm looking at my (simple) options.

I'm considering just writing in a hack to convert my rectangles to polygons and rotate their points manually, instead of using Slick 2D's rotation transforms, because then I can rotate around the center of each shape, instead of wherever Slick keeps trying to rotate around. I'm pretty sure it's trivial calculating the points at rotation x, based on the points at rotation 0, but I've lost my dry erase markers, so I need to hunt down some paper and pencils if I want to figure out how to do it again. I figure I can write a method "Polygon rotate(Body b, float angle)" and get the points from the shape on b (as bodies only have one shape each at the moment, and it will likely remain that way) rotate them around the origin position of b, and return a polygon consisting of the rotated points, which would be rendered.

To lower the number of bottlenecks, if the rotation was zero, I'd skip everything, and just return the same shape. I have a feeling that it will be, at this point, the easiest way of getting rotation to work how I think it should be working. Hopefully by the end of tonight I'll have rotation finished, though I've only been saying that the past few nights I've been working on it.

In the long term, I may depreciate this little hack, and implement it correctly using Slick's methods, but for the time being, I can't figure out how, so I'm going to try this tonight, and see if I can keep a decent framerate despite it.

Also, can anyone confirm or deny that all rotations, as dictated by the getRotation() method in Body, are around the origin of the body?
I'm pretty sure that in Box2d rotations are around the center of mass, which may not coincide with the origin in general.

The only reason I can think of to prefer handling rotations from within Slick itself rather than trig-ing them out yourself is that Slick quite likely hands them straight off to the graphics card as OpenGL transforms, which means hardware takes care of them much faster than software can. But this is a very minor computation, so I wouldn't worry about it unless you really need every last bit of speed.
After realizing it took all of three lines of code to rotate each point, only two more than the section I replaced with it, I got the rotation of boxes finished. I've also started implementing the option to use circles, and am nearly done, with one small bug, having to do with calculating radius. I'm too tired to find it tonight, so I'll fix it tomorrow morning when I get up.

To-Dos:
  • Buttons to select drawing mode
  • Ability to pause the simulation.
  • Implement "materials"
  • Make it pretty
Quick update, got the circle problem fixed, I wasn't scaling them down to the right size. It is now at a point where it can certainly be played with, though it is still far from finished or user-friendly. My next step is going to be implementing materials, so I'm looking for ideas and such for when I do.

A few I'm planning on:
Steel (high density, very low bounce, low-med friction)
Wood (low density, low amount of bounce med-high friction)
Rubber (Low-med density, high bounce, med-high friction)
Ice (low density, low bounce, low friction, would like to make it break under high stress situations)
Constant (like a wall, density 0, won't be affected by gravity)

Any ideas on other materials I should have implemented by default right now? Also, what might appropriate values be, as far as friction, density, and restitution be? Friction and restitution are simple enough, having absolute endpoints, but what are some examples of values in density for real world objects?

edit: also, can't seem to get eclipse to export an executable jar, I think the native methods are tripping it up somehow.
Minor bump, and a quick update. Haven't posted much progress because, while I have been coding, my vid drivers are pooched, so I haven't been able to test it, so I think I have mats done, but who knows until I fix things. Going to be reinstalling my OS later today so I actually make a bit more progress. Expect a playable concept demo in a week or so.

-Haydre

edit: fixed a typo
Latest News:

  • Fixed my computer for the time being, so coding can continue.
  • Pulled the latest SVN of JBox2D and got it compiled.
  • Working on fixing some of my code rot and ugly hacks to get things working again with the new version of the engine.

Once the code will compile again, which shouldn't be too long, I'm going to rewrite the object creation code, ensure cross-platform compatibility, and release a very simple demo, so you can have something to play with as I add features to it. All previously stated features are still planned, and should be far easier once I've fixed the hacks I came up with back before proper docs were available.

"I love deadlines, I love the whooshing sound they make as they go by."
(Douglas Adams)

-Haydre
BTW, in SVN there's now a real basic Slick demo in org.jbox2d.integrations, if anyone is interested. It's not the full testbed or anything, but it shows how to start setting up a DebugDraw implementation using Slick.

As far as executable jar stuff, I have no idea how to do it with Slick. In general Java OpenGL app exporting is a bit painful, and I find it's usually best achieved with Ant scripts instead of the normal Eclipse build process...might ask at the Slick forums, I'm sure someone has figured it out.

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