Skip to content

Instantly share code, notes, and snippets.

@slembcke
Created May 17, 2012 14:41
Show Gist options
  • Save slembcke/2719364 to your computer and use it in GitHub Desktop.
Save slembcke/2719364 to your computer and use it in GitHub Desktop.
Convex Moment
cpFloat moment = cpMomentForPoly(mass, NUM_VERTS, verts, cpvzero);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
/*
So cpPolyShapeNew() now always call cpConvexHull() internally to ensure that you are creating convex shapes. Great! Woo! Whatever.
The issue was that cpMomentForPoly() does not.
* If the vertexes had the correct winding, but were concave, it would give you the correct moment for the concave polygon, but not the convex one used for the collider. This seems like it would be reasonable.
* If the vertexes had the incorrect winding, I think it would give you a negative moment of inertia. This would be bad. I need to check quick.
* If the vertexes were self intersecting, I think it would just give you garbage.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment