I have a little question regarding composite objects (objects, represented as multiple shapes, assigned to a single body). You can't get anywhere without them, unless, of course, you don't get to deal with non-convex shapes :P
I can't quite understand what two "offset" arguments stand for:
- offset in cpPolyShapeInit - that is an offset from the body's center of gravity (how can it be known before attaching all shapes?) to what? To the shape's centroid? I simply can't get my head around this :( My guess is that this offset basically "translates" shape-local coordinates into the body-local coordinates. Is that correct?
- offset in cpMomentForPoly - what does this mean? Since cpMomentForPoly assumes, that the center of mass of the polygon (its centroid, essentialy, because the density is constant) is at (0,0), is this offset used for situations, when the center of mass is not actually at (0,0)? So if the center of mass of your polygon is at, say, (20,0), you use (-20,0) as the offset?
Code: Select all
|########|$$$$$$$$|
-8 0 8
The body is composed of two shapes with different masses. Body's center of gravity obviously won't be at 0 in this example.
What would be the correct values of "offset" for both the cpPolyShapeInit and cpMomentForPoly?
EDIT:
Ok, so I've spent a bit more time pondering this and I seem to understand the problem a bit better now:
- When calculating the moment of inertia for the single shape (cpMomentForPoly), that is described in shape-local coordinates, offset is used if the centroid (and, consequently, the center of mass) of the shape doesn't correspond to (0,0) in shape-local coordinates.
- When adding the shapes to the body, it is desired, that the body will rotate around its actual center of mass, meaning, that the (0, 0) point (the point, that corresponds exactly to the body->position in world coordinates) cannot be chosen arbitrarily. A center of mass has to be calculated using the masses and initial offsets of all shapes, that make up the body and that value has to be used to "shift" the center of mass (or, rather the shapes themselves, since the center of mass has to end up at (0, 0) in body-local coordinates) to the desired spot.
And I am really sorry for peppering you with incoherent questions.