iphone - Chipmunk Physics: cpSpaceShapeQuery -
how cpspaceshapequery function work? can not find doc it.
andrea
yeah... never got around documenting that... sorry. create body , shape (neither needs added space) , use query other query functions.
this code snippet makes copy of body , shape on stack , simulates out it's first predicted collision point drawing path goes.
cpbody body = *(originalbody); cppolyshape shape = *((cppolyshape *)originalshape); shape.shape.body = &body; cpfloat dt = 1.0f/60.0f; cpvect gravity = space->gravity; int count = 0; for(int i=0; i<300; i++){ cpbodyupdateposition(&body, dt); cpbodyupdatevelocity(&body, gravity, 1.0f, dt); if(cpspaceshapequery(space, (cpshape *)&shape, null, null)){ quads[count%maxquads] = quad(body.p, body.rot, cgrectmake(0, 2*32, 64, 64), tsize); count++; break; } if(i%10==0){ quads[count%maxquads] = quad(body.p, body.rot, rect, tsize); count++; } }
Comments
Post a Comment