In the main chipmunk documentation there's some discussion about using a bounding box query to get all shapes inside the box.
http://code.google.com/p/chipmunk-physics/wiki/Queries
I just so happen have a need to do exactly this, but I am using pymunk, and it appears the cpSpaceBBQuery function has not been implemented. Grepping the module's files I see some mentions of the function, but it doesn't seem to have been made a member of the Space class.
I am not really familiar with how C bindings work with Python, is there some other way to access this function I am missing, or is it not possible?
[pymunk] Bounding Box Queries?
-
- Posts: 2
- Joined: Thu Jul 14, 2011 4:31 pm
- Contact:
-
- Posts: 2
- Joined: Thu Jul 14, 2011 4:31 pm
- Contact:
Re: [pymunk] Bounding Box Queries?
Eventually figured this out on my own. Didn't really plan to dig into python modules, but at least I can say I'm a little more educated now.
In case google searches bring someone here in the future. It goes a little something like:
Returns a list of shapes that were inside the bounding box.
I more or less cut and pasted this out of the pymunk source, and shuffled arguments around.
In case google searches bring someone here in the future. It goes a little something like:
Code: Select all
import pymunk._chipmunk as cp
def bbq(space, bb, layers = -1, groups = 0):
self.__query_hits = []
def cf(_shape,data):
shape = space._shapes[_shape.contents.hashid]
self.__query_hits.append(shape)
callback = cp.cpSpaceBBQueryFunc(cf)
cp.cpSpaceBBQuery(space._space, bb._bb, layers, groups, callback, None)
return self.__query_hits
bb = pymunk.BB(left, bottom, right, top)
results = bbq(space,bb)
I more or less cut and pasted this out of the pymunk source, and shuffled arguments around.
-
- Posts: 206
- Joined: Tue Aug 21, 2007 3:12 pm
- Contact:
Re: [pymunk] Bounding Box Queries?
Nice to hear that you solved it!
I have added the missing bb query method (and shape query) to pymunk trunk, expect it to be included from start in the next release.
I have added the missing bb query method (and shape query) to pymunk trunk, expect it to be included from start in the next release.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
Who is online
Users browsing this forum: No registered users and 8 guests