List of tiles for a given body

Official forum for the Chipmunk2D Physics Library.

List of tiles for a given body

Postby xanather » Tue Jan 03, 2017 4:10 am

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

Re: List of tiles for a given body

Postby xanather » Tue Jan 03, 2017 9:57 am

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


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests