Chipmunk Physics: cpSpaceShapeQuery
How does the cpSpace开发者_Go百科ShapeQuery function work? I can not find any doc about it.
Andrea
Yeah... I never got around to documenting that... Sorry. Basically you create a body and shape (neither needs to be added to the space) and use that to query much like the other query functions.
This code snippet makes a copy of a body and shape on the stack and then simulates it out to it's first predicted collision point drawing the path as it 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++;
}
}
精彩评论