Picking
-
- Posts: 6
- Joined: Fri Mar 14, 2008 6:44 am
- Contact:
Picking
I'd imagine that there is a simple way of specifying a coordinate and then using the spatial hash to find if there is a shape there...i.e. picking. Does anyone know how to do this with chipmunk? Any pointers will be much appreciated.
thanks.
thanks.
-
- Posts: 1
- Joined: Mon Mar 24, 2008 4:08 am
- Contact:
Re: Picking
There are two ways
For polys you can do it manually as all polys in Chipmunk must be concave so its simple to implment.
The alternative way is make a circle shape and add it to your space but dont add its body.
Then update your circle shape to match mouse position. And you can use collisions generated by circle shape.
For polys you can do it manually as all polys in Chipmunk must be concave so its simple to implment.
The alternative way is make a circle shape and add it to your space but dont add its body.
Then update your circle shape to match mouse position. And you can use collisions generated by circle shape.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Picking
If you use the trunk code, I had already added functions for doing point queries against shapes a while ago. I finally added the support to do point queries to the spatial hash just now.
The new function is cpSpaceHashPointQuery(). I didn't test it particularly thoroughly, but it's pretty simple. I added a call to the main demo application so that it highlights the shape under the mouse. Cheers.
One thing to note: cpSpace.activeShapes (or staticShapes) isn't really part of the public API. I intend to add a nice API for generic spatial indexes someday, but until then...
The new function is cpSpaceHashPointQuery(). I didn't test it particularly thoroughly, but it's pretty simple. I added a call to the main demo application so that it highlights the shape under the mouse. Cheers.
One thing to note: cpSpace.activeShapes (or staticShapes) isn't really part of the public API. I intend to add a nice API for generic spatial indexes someday, but until then...
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 6
- Joined: Fri Mar 14, 2008 6:44 am
- Contact:
Re: Picking
Thanks for your quick and helpful responses.
I will use cpSpaceHashPointQuery() and feedback any issues I might encounter.
Thanks,
Jim.
I will use cpSpaceHashPointQuery() and feedback any issues I might encounter.
Thanks,
Jim.
-
- Posts: 13
- Joined: Thu Jan 03, 2008 11:27 am
- Contact:
Re: Picking
Is there any way to do this with the ruby binding?
Thanks.
Thanks.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Picking
Not yet. Right now it's a pretty low level implementation. I'll at least want to make it a function of the space first.
Would probably only be like 30 lines of code if you wanted to try your hand at implementing it.
Would probably only be like 30 lines of code if you wanted to try your hand at implementing it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Picking
Ok, I added a space functions for querying the hashes.
C Side:
Ruby Side:
C Side:
Code: Select all
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data);
void cpSpaceShapePointQuery(cpSpace *space, cpVect point, cpSpacePointQueryFunc func, void *data);
void cpSpaceStaticShapePointQuery(cpSpace *space, cpVect point, cpSpacePointQueryFunc func, void *data);
Code: Select all
CP::Space#shape_point_query(point){|shape| ... }
CP::Space#static_shape_point_query(point){|shape| ... }
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 27
- Joined: Sun Mar 30, 2008 9:00 pm
- Contact:
Re: Picking
Hi,slembcke wrote:Ok, I added a space functions for querying the hashes.
C Side:Ruby Side:Code: Select all
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data); void cpSpaceShapePointQuery(cpSpace *space, cpVect point, cpSpacePointQueryFunc func, void *data); void cpSpaceStaticShapePointQuery(cpSpace *space, cpVect point, cpSpacePointQueryFunc func, void *data);
Code: Select all
CP::Space#shape_point_query(point){|shape| ... } CP::Space#static_shape_point_query(point){|shape| ... }
That is fantastic! I actually just signed up at the forum to ask if something like this were possible. However, I am a little bit confused. How do I get access to these functions? When I click at "source+demos" at the main site I get a "ChipmunkLatest.tgz", which unpacks to a Chipmunk 4.0.2. It does not appear to contain these functions you describe here. Am I missing something?
Thanks.
EDIT: Never mind, I figured out how to check out from svn head. Thanks!
-
- Posts: 6
- Joined: Fri Mar 14, 2008 6:44 am
- Contact:
Re: Picking
Ok, I have some static items that I would like to be picked using this system. These items should not be collideable, so I intend so add them to the Space as static and set them to a sperate layer. Will this work (currently coding it), or is their a better solution?
Thanks,
Jim.
Thanks,
Jim.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Picking
That will work fine. There is support for querying the static hash as well.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 13 guests