I tried testing it, but I may have done something wrong.
The only other joint I've tested so far is the pin joint, but this code works ok with that. The creation passes ok, but it seems to crash on cpSpaceAddConstraint. Thanks.
I have a question that I can't seem to find an answer for. Is it possible to determine of two cpBodies are connected by a joint from within a callback? I'm mainly talking about a pin join for now. I may be going about this the wrong way, but I'm making a game similar to fantastic contraption. When a solid rod connects to a wheel, it wont collide with that exact wheel's shape, yet it will still collide with other wheels of the same type. For instance, I have collision pairs, wheels/lines, wheels/terrain, lines/terrain, etc... I guess the key may be in the data pointer I'm giving to the cpShapes, but I haven't been able to wrap my head around it. Adding the both shapes to the same cpBody is an option, but that seems really messy. Has anyone around done anything similar to this?
When a solid rod connects to a wheel, it wont collide with that exact wheel's shape, yet it will still collide with other wheels of the same type.
It's very easy. When you connect the rod with the rock assign them the same group (cpShape::group). Shapes from the same group do not collide.
The official documentation wrote:group: Shapes in the same non-zero group do not generate collisions. Useful when creating an object out of many shapes that you don't want to self collide. Defaults to 0
EDIT: Actually, the group thing isn't exactly what i need either, now that I've been messing with it. Is there any possible way using the API to determine if two bodies are connected via a joint? I really need to process this info in the callback. Thanks again!
I don't think there is a way directly via the API. The way I structure things is I have a ChipmunkItem which represents things in my world. The data pointer points to one of these. A ChipmunkItem knows everything about that object, all the bodies and shapes that make it up (a single item can have multiple bodies) and all it's constraints. I drive everything from the ChipmunkItems e.g. i don't just "delete a body", instead a ChipmunkItem deletes one of it's bodies and it knows everything it needs to do for that.
So you could go down a fully flexible solution where you have an equivalent of ChipmunkItem and you add a merge(ChipmunkItem*) method. So you have two objects, draw a pin joint between them and then merge the two sets of bodies/shapes/constraints together. Or if you just want to find the constraint that a body is attached two why not just have a singleton look up table of body => constraint(s) and when you delete a body just scan the list to find any constraint(s).
If you're an over-engineering OO person like me you'll go for the first...I'd recommend the second
hehehe... Well, I have a pretty robust structure, so I can just modify it a bit to contain ptrs for each body's joints and stuff. I was really hoping there was a way through the API... but maybe I'm being lazy. Thanks man.
Hello again. I was wondering if scanning for Constraint->a or Constraint->b to match a body in the world will return as I think it will, or is there some swapping/sorting that happens behind the scenes? It cold be that I just need to rethink my code again.