-
-
Save slembcke/2719765 to your computer and use it in GitHub Desktop.
Convex Moment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a little annoying: | |
cpVect *hullVerts = (cpVect *)calloc(NUM_VERTS, sizeof(cpVect)); | |
int hullCount = cpConvexHull(NUM_VERTS, verts, hullVerts, NULL, 0.0); | |
cpFloat mass = 1.0; | |
cpFloat moment = cpMomentForPoly(mass, hullCount, hullVerts, cpvzero); | |
body = cpSpaceAddBody(space, cpBodyNew(mass, moment)); | |
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, hullCount, hullVerts, cpvzero)); | |
free(hullVerts); | |
// This isn't so bad: | |
CP_MAKE_CONVEX(NUM_VERTS, verts, hullCount, hullVerts); | |
cpFloat mass = 1.0; | |
cpFloat moment = cpMomentForPoly(mass, hullCount, hullVerts, cpvzero); | |
body = cpSpaceAddBody(space, cpBodyNew(mass, moment)); | |
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, hullCount, hullVerts, cpvzero)); | |
// Using the following macro: | |
#define CP_MAKE_CONVEX(__count__, __verts__, __count_var__, __verts_var__) \ | |
cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \ | |
int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment