List of tiles for a given body

Official forum for the Chipmunk2D Physics Library.
Post Reply
User avatar
xanather
Posts: 3
Joined: Tue Jan 03, 2017 3:35 am
Contact:

List of tiles for a given body

Post 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.
User avatar
xanather
Posts: 3
Joined: Tue Jan 03, 2017 3:35 am
Contact:

Re: List of tiles for a given body

Post 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests