Skip to content

Instantly share code, notes, and snippets.

@andykorth
Forked from slembcke/cpConvexMoment.c
Created May 17, 2012 15:14
Show Gist options
  • Save andykorth/2719572 to your computer and use it in GitHub Desktop.
Save andykorth/2719572 to your computer and use it in GitHub Desktop.
Convex Moment
So I see two options right now:
Idea 1:
// add a convenience method to the API
cpMakeBodyAndShape(mass, NUM_VERTS, verts){
verts = AllThatConvexHullStuff(verts);
moment = cpMomentForPoly(verts, otherNumber, mass, etc);
body = cpSpaceAddBody(space, cpBodyNew(mass, moment));
shape = cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
return something?;
}
// this convenience method won't work for every situation, not sure if they are expected to add multiple shapes on their own if they want more than one on a body, etc...
// People using this might not understand the distinction between a shape and a body, which was always very clean in the API before. (you always make a body, then you add zero or more shapes to it)
Idea 2:
float PLACE_HOLDER_MOMENT = 7.0; // or whatever. If I want I can calculate this myself. Otherwise I can just leave this argument off the cpBodyNew and maybe it'll give it an infinite moment.
body = cpSpaceAddBody(space, cpBodyNew(mass, PLACE_HOLDER_MOMENT));
shape = cpSpaceAddShapeAND_SET_MOMENT(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
So cpSpaceAddShapeAND_SET_MOMENT will do the convex hull, find the moment, and replace it on body.
If you want a custom moment, you need to calculate it on your own.. so really this is just a convenience method like idea 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment