Page 1 of 1

Converting from world to local coordinates

Posted: Fri May 09, 2008 10:39 am
by ehudros
Hi everyone,
I am trying to create a composite body made up of a large box with several small circles sitting on each of its edges.
What I'm currently doing is creating one static body, and attaching shapes to it (1 polygon and several circles).
The problem is I can't seem to figure out the whole offset from the center of the body thing, and the circles end up in the wrong places...
Can some one point me at the right direction here? just a few lines of code that create one poly with one circle on the center of one of its edges would be
really helpful.
Also, later on how do i get the location each circle from its shape? I have the static body its attached to and offset (a member named "c" if i understand correctly).
But what's the manipulation i need to do here?

Obviously I'm missing something here, so any help for someone more experienced would be great.

Thanks,
Ehud

Re: Converting from world to local coordinates

Posted: Fri May 09, 2008 4:09 pm
by ehudros
Never mind, figured it out myself.
The only problem I have now is that changing the rotation angle of the static object (which contains several dynamic bodies inside its walls) does not
seem to affect collision detection. The object's vertices do change their position and the object seem to be actually rotated as far as coordinates go, but all
the object contained within it seem to still be confined by the old object (the unrotated one) and unaffected by the static object's rotation.

Any ideas what could be causing this?
Thanks :)

Re: Converting from world to local coordinates

Posted: Sat May 10, 2008 3:02 am
by maximile
As I found out recently, you have to move/rotate the body before you add it to the space.

Re: Converting from world to local coordinates

Posted: Sat May 10, 2008 3:40 am
by ehudros
Yeah, that's what i'm figuring out step by step here as well.
It seems that changing the rotation/position of a static object does not have any effect on collision detection.
Is this a bug or a design thing? Is there anything i can do to fake this? I would think moving static objects is something people need quite often, so i'm guessing
there's another way of doing it?

Re: Converting from world to local coordinates

Posted: Sat May 10, 2008 3:53 am
by maximile
I was getting the exact same symptoms as you - shapes were drawing in the right place, but things were bouncing off them as if they had not been moved. The fix for me was to move the bodies before adding them to the space. I'm surprised it doesn't work for you.

In this thread slembcke mentions "updating its collision data", but I didn't have to do that.

Re: Converting from world to local coordinates

Posted: Sat May 10, 2008 3:57 am
by ehudros
Ok, found it in demo4 (which is exacly what im looking for):
cpSpaceRehashStatic(space) is the answer.
it's even documented correctly, but I somehow missed it...

Re: Converting from world to local coordinates

Posted: Mon May 12, 2008 1:23 am
by slembcke
Yes, the objects in the static hash are assumed not to move. That way the collision data doesn't need to be recalculated and rehashed every step.

I'm not sure if I understood the original question, but there are cpBody function for converting between body local and global coordinates. Most offsets are specified as a relative offset in global cordinates.