Crayon Physics Deluxe

It shouldn't be too hard to allow shapes to be added/removed. There's one API problem though. Users don't create shapes directly, so they don't have any direct handle to the shapes.

Would it be better to have a utility function that merges two bodies? Another function could split a single body.
Yeah, I was worried a bit about that API issue. The thing is, though, users may not be holding refs to the shapes, but they at least have access - that's how drawing gets done. It might be slightly inconvenient, but this is sort of advanced functionality, so a bit of work is not a terrible idea; the only real problem is that it's difficult to know which shape in the array matches up with which original created shape since the shapes themselves don't have user data. It's mildly unfortunate that there's no great way to allow users to hold on to shapes after they are created, but if you want to allow reuse of the shapes during body creation, which I think is pretty important, there's not much choice there.

Regardless of your decision on that front, having merge and split utilities would be great. Any thoughts on how the split method would be used? What's the best way to specify a partition? We still have the "which shape is which" problem, though. Thoughts?
I didn't want to allow shapes to be created directly because it is cleaner to build them all at once in the body constructor (to compute mass properties, etc).

I think a simple solution would be to have b2BodyDef::AddShape return a shape index. Then, I will add

Code: Select all

const b2Shape* b2Body::GetShape(int32 index) const;

This provides read only access to shapes. I can also provide:

Code: Select all

void b2CircleShape::ExtractDef(b2CircleDef* def);
void b2PolyShape::ExtractDef(b2PolyDef* def);


What do you think?
That sounds like a good approach.

Any particular reason for passing a pointer to be filled in the ExtractDef functions instead of just returning a copy?
Shape definitions are not stored in the original form. There is some optimization that happens and some of the data lives in the broad-phase. So extractedDef != originalDef. So the user passes a pointer to a temporary shape definition that is then filled by the extraction code.
That's cool with me. I can live with that.
Crayon Physics is getting majorly Dugg, head over and give it some love if you haven't already - http://digg.com/videos/educational/Cray ... _tablet_PC - 930 Diggs + 1 from me, that's pretty awesome!
Nice, +1. (:
Just stumbled across this video that reminds me a lot of Crayon Physics: http://www.youtube.com/watch?v=d7eGypGOlOc
Thanks guys for the diggs and support 🙂

That digg thing was crazy, I'm just happy that it didn't happen directly to my site. It would have been down for a long time.

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