I'm writing a little game just for testing chipmunk and I have a little problem, i want to create a function who add a polygon, but my polygon don't bounce against walls, they just fall:
Code: Select all
void make_dynamic_polygon(pt *tabPT, int nbVect)
{
int i;
float minx = 10000.0, miny = 10000.0, maxx = 0.0, maxy = 0.0;
cpVect *verts = (cpVect *) malloc(nbVect*sizeof(cpVect));
for(i=0;i<nbVect;i++) {
if(tabPT[i].x < minx && tabPT[i].y < miny) {
minx = tabPT[i].x;
miny = tabPT[i].y;
}
if(tabPT[i].x > maxx && tabPT[i].y > maxy) {
maxx = tabPT[i].x;
maxy = tabPT[i].y;
}
}
for(i=0;i<nbVect;i++) {
verts[i].x = tabPT[i].x - minx-((maxx-minx)/2);
verts[i].y = tabPT[i].y - miny-((maxy-miny)/2);
printf("x: %.2f, y: %.2f\n",verts[i].x,verts[i].y);
}
double heaviness = (maxx-minx) * (maxy-miny) * 0.001;
cpBody *body = cpBodyNew(heaviness, cpMomentForPoly(heaviness, nbVect, verts, cpvzero));
body->p = cpv(minx+((maxx-minx)/2.0), miny+((maxy-miny)/2.0));
cpSpaceAddBody(space, body);
cpShape *shape = cpPolyShapeNew(body, nbVect, verts, cpvzero);
shape->e = 0.0; shape->u = 0.6;
cpSpaceAddShape(space, shape);
}
and "int nbVect" the array size.
anyone see where i'm wrong?