Polygon Help - Offsets and Centers
Posted: Mon Aug 03, 2009 3:41 pm
Hi, I'm looking to attach a polygon to a circle (an arm to a body) at a single point and have the arm flop around when the body has forces applied to it. I think that a pin-joint would be best (correct me if I'm wrong), but I'm having significant troubles with the OFFSET params to a few of the chipmunk functions.
Can anyone explain in a little more detail where the centers of shapes are (are they at x/2, y/2 ?), what the offsets for cpMomentForPoly and cpPolyShapeNew actually do (do they move the center of the shape?), and anything else you think I might be missing?
Here's an image showing what I want done (pivoting at the obvious point), and the relevant code snippet that I'm trying.

Any idea what might not be right about this? Any help is greatly appreciated!
Thanks!
Can anyone explain in a little more detail where the centers of shapes are (are they at x/2, y/2 ?), what the offsets for cpMomentForPoly and cpPolyShapeNew actually do (do they move the center of the shape?), and anything else you think I might be missing?
Here's an image showing what I want done (pivoting at the obvious point), and the relevant code snippet that I'm trying.

Code: Select all
////// LEFT ARM //////
cpVect laVerts[]={cpv(0,0),cpv(20,0),cpv(25,-5),cpv(20,-10),cpv(0,-10)}; // Clockwise
moment = cpMomentForPoly(armMass, 5, laVerts, cpvzero);
// (Not sure what the offset does here, but I think this means MOI in center)
golferLArmBody = cpBodyNew(armMass, moment);
golferLArmBody->p = cpv(bodyX-bodyRadius,bodyY);
cpSpaceAddBody(space, golferLArmBody);
// I think the center of the shape is at (12.5, -5)? Maybe?
// The OFFSET moves the center to (25, -5), which is the point I want the joint at?
shape = cpPolyShapeNew(golferLArmBody, 5, laVerts, cpv(12.5f,0);
cpSpaceAddShape(space, shape);
////// LEFT SHOULDER //////
leftShoulderJoint = cpPinJointNew(golferBody, golferLArmBody, cpv(-bodyRadius,0), cpvzero;
// The point on the arm to connect to the body should be at (0,0) since I moved the offset to
// the point on want when creating the shape? Is this wrong?
cpSpaceAddJoint(space, leftShoulderJoint);

Thanks!