Converting from world to local coordinates

Official forum for the Chipmunk2D Physics Library.
Post Reply
ehudros
Posts: 17
Joined: Fri Oct 12, 2007 8:59 pm
Contact:

Converting from world to local coordinates

Post 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
ehudros
Posts: 17
Joined: Fri Oct 12, 2007 8:59 pm
Contact:

Re: Converting from world to local coordinates

Post 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 :)
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Converting from world to local coordinates

Post by maximile »

As I found out recently, you have to move/rotate the body before you add it to the space.
ehudros
Posts: 17
Joined: Fri Oct 12, 2007 8:59 pm
Contact:

Re: Converting from world to local coordinates

Post 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?
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Converting from world to local coordinates

Post 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.
ehudros
Posts: 17
Joined: Fri Oct 12, 2007 8:59 pm
Contact:

Re: Converting from world to local coordinates

Post 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...
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Converting from world to local coordinates

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 5 guests