Page 1 of 1

List of tiles for a given body

PostPosted: Tue Jan 03, 2017 4:10 am
by xanather
Is there any API call that lets me query which tiles (a list of x/y points) a body is inside for a custom tile/grid size (the tile/cell size for the query can change during runtime for a given space - i.e. not related to my spatial hash size).

Being able to retrieve a list of tiles a body intersects with means I could easily illuminate a body for my tile-based & quality-dynamic (different light sized cells based on user settings) lighting engine.

Any idea's how this could be accomplished? (using private API would be fine if necessary).

Excellent library by the way.

Re: List of tiles for a given body

PostPosted: Tue Jan 03, 2017 9:57 am
by xanather
I figured it out, it was easier than I thought. If anyone comes by this looking for a solution, well, I used a combination of functions:

cpBodyEachShape (get the shapes of the body)
cpShapeGetBB (use this to loop over each tile in the tile grid contained within this bounding box).
cpShapePointQuery (within each tile check if shape intersects with the tile)