Position Vector of cpBody

Official forum for the Chipmunk2D Physics Library.
Post Reply
ayushv
Posts: 14
Joined: Thu Oct 21, 2010 1:52 pm
Contact:

Position Vector of cpBody

Post by ayushv »

I'm writing my first iPhone game using Chipmunk and I need some clarifications regarding the position vector of a cpBody and the offset vector of the shapes attached to this body.

The following is the shape that I need to add to the cpSpace (file attached). Its like an inverted T and the black dot denotes the approximate position of the center of gravity (CoG). I can calculate the exact position of the CoG but for now lets assume that the black dot indicates its position.
shape.png
Since the overall inverted T shape is not convex, I will attach two cpShapes to this body. The first shape will be the rectangle of the lower (horizontal) bar of the inverted T. The second shape will be the vertical arm of the inverted T.

My queries are:

1) In the cpBody APIs, does the position vector, i.e. cpBody->p , represent the position of the Center of Gravity of the body? Or does the position vector represent the lower left corner (i.e. origin) of the shapes attached to the body?

2) In the following cpShape API:
cpShape *cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset)

does the cpVect offset denote the offset of the CENTER of the cpShape from the cpBody's CoG?

I've tried to figure out the answers to these query by updating the position of the actual sprite ... but I'm getting very weird movements of the sprite.

~Thanks
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Position Vector of cpBody

Post by slembcke »

Bodies don't know anything about shapes really. The position of the body is it's CoG, and shapes are attached relative to the CoG. For poly shapes, the vertexes are interpreted relative to the CoG of the body you are attaching them to and the offset is simply added to each vertex.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ayushv
Posts: 14
Joined: Thu Oct 21, 2010 1:52 pm
Contact:

Re: Position Vector of cpBody

Post by ayushv »

Thanks a ton ... thats really helped clear a lot of concepts now. Needed to go back to the physics books to learn how to calculate the CoG for complicated shapes but at least the program is working now.

~Ayush
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests