I've been looking at the demos to try and learn but I've gotten stuck
all I'm trying to do is have a square start at the top of my screen and fall to the bottom.
But its not really working out so great.
I make the space then i make the floor as segment and the square as a poly (of course)
but all that happens is the square stays where it is
the main
Code: Select all
int main(){
startsdl();
startgl();
cpInitChipmunk();
cpSpace *space = cpSpaceNew();
cpSpaceInit(space);
space->iterations = 10;
//cpSpaceResizeStaticHash(space, 30.0f, 1000);
//cpSpaceResizeActiveHash(space, 30.0f, 1000);
space->gravity = cpv(0, -25);
cpShape *ground = cpSegmentShapeNew(&space->staticBody, cpv(0,25), cpv(1377,25), 5);
ground->e = 1; ground->u = 1;
//cpSpaceAddShape(space, ground);
//ground->layers = NOT_GRABABLE_MASK;
cpVect verts[] = {
cpv(0 , 50),
cpv(50, 50),
cpv(50, 0),
cpv(0, 0),
};
cpBody *body = cpSpaceAddBody(space, cpBodyNew(1, /*cpMomentForPoly(1, 4, verts, cpv(675,525))*/ INFINITY));
//body->p = cpv(675, 525);
body->v= cpv(0, -5);
cpShape *shape = cpSpaceAddShape(space, cpPolyShapeNew(body, 4, verts, cpv(675,525)));
shape->e = 0.0f; shape->u = 0.7f; shape->collision_type = 1;
while(1){
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
sleep(1/60);
cpSpaceStep(space, 1.0f/60);
drawrect(shape, NULL);
SDL_GL_SwapBuffers();
}
cpSpaceFreeChildren(space);
cpSpaceFree(space);
SDL_Quit();
return 0;
}
what i use to draw
Code: Select all
void drawrect (void *ptr, void* unused){
cpShape *s = (cpShape*)ptr;
cpVect verts[4];
for(int i = 0; i < 4; i++){
verts[i] = cpPolyShapeGetVert(s, i);
printf("(%f, %f)\n", verts[i].x, verts[i].y);
}
glBegin(GL_QUADS);
glVertex2i(verts[0].x, verts[0].y); //top left
glVertex2i(verts[1].x, verts[1].y); //top right
glVertex2i(verts[2].x, verts[2].y); //bottom right
glVertex2i(verts[3].x, verts[3].y); // bottom left
glEnd();
printf("\n");
}
i guess i really don't know what I'm doing that much.
I just what to get this test to work first
any help would be appreciated.