void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data) { struct BBQueryContext context = {bb, layers, group, func}; cpSpaceLock(space); { cpSpatialIndexQuery(space->activeShapes, &context, bb, (cpSpatialIndexQueryFunc)BBQuery, data); cpSpatialIndexQuery(space->staticShapes, &context, bb, (cpSpatialIndexQueryFunc)BBQuery, data); } cpSpaceUnlock(space, cpTrue); }
void cpSpaceNearestPointQuery(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpSpaceNearestPointQueryFunc func, void *data) { struct NearestPointQueryContext context = {point, maxDistance, layers, group, func}; cpBB bb = cpBBNewForCircle(point, cpfmax(maxDistance, 0.0f)); cpSpaceLock(space); { cpSpatialIndexQuery(space->activeShapes, &context, bb, (cpSpatialIndexQueryFunc)NearestPointQuery, data); cpSpatialIndexQuery(space->staticShapes, &context, bb, (cpSpatialIndexQueryFunc)NearestPointQuery, data); } cpSpaceUnlock(space, cpTrue); }
void cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data) { struct PointQueryContext context = {point, layers, group, func, data}; cpBB bb = cpBBNewForCircle(point, 0.0f); cpSpaceLock(space); { cpSpatialIndexQuery(space->activeShapes, &context, bb, (cpSpatialIndexQueryFunc)PointQuery, data); cpSpatialIndexQuery(space->staticShapes, &context, bb, (cpSpatialIndexQueryFunc)PointQuery, data); } cpSpaceUnlock(space, cpTrue); }
cpBool cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data) { cpBody *body = shape->body; cpBB bb = (body ? cpShapeUpdate(shape, body->p, body->rot) : shape->bb); struct ShapeQueryContext context = {func, data, cpFalse}; cpSpaceLock(space); { cpSpatialIndexQuery(space->activeShapes, shape, bb, (cpSpatialIndexQueryFunc)ShapeQuery, &context); cpSpatialIndexQuery(space->staticShapes, shape, bb, (cpSpatialIndexQueryFunc)ShapeQuery, &context); } cpSpaceUnlock(space, cpTrue); return context.anyCollision; }
cpShape * cpSpaceNearestPointQueryNearest(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpNearestPointQueryInfo *out) { cpNearestPointQueryInfo info = {NULL, cpvzero, maxDistance, cpvzero}; if(out){ (*out) = info; } else { out = &info; } struct NearestPointQueryContext context = { point, maxDistance, layers, group, NULL }; cpBB bb = cpBBNewForCircle(point, cpfmax(maxDistance, 0.0f)); cpSpatialIndexQuery(space->activeShapes, &context, bb, (cpSpatialIndexQueryFunc)NearestPointQueryNearest, out); cpSpatialIndexQuery(space->staticShapes, &context, bb, (cpSpatialIndexQueryFunc)NearestPointQueryNearest, out); return out->shape; }
static void dynamicToStaticIter(void *obj, dynamicToStaticContext *context) { cpSpatialIndexQuery(context->staticIndex, obj, context->bbfunc(obj), context->queryFunc, context->data); }
void SpatialIndex::query(void *obj,cpBB bb,SpatialIndexQueryFunc func) { cpSpatialIndexQuery(index,obj,bb,*SpatialIndexQuery,&func); }
void SpatialIndex::query(void *obj,const cp::BB& bb,cpSpatialIndexQueryFunc func,void *data) { cpSpatialIndexQuery(index,obj,bb,func,data); }