Hi,
i have some problems with my code. I worked on chipmunk version 4 for a long time, and now want to use my whole project with cp 5.2. Problem like collision from adding a collisionpairfunc to a collisionhandler has been solved, but now also the picking has a new way it seems. My current code:
case 1: //Single Tap.
{
cpVect cpKlikPos =cpv(klikPos.x/10.0f,klikPos.y/10.0f) ;
cpSpaceShapePointQuery(activeLevel->space, cpKlikPos, pickingFunc,nil);
cpSpaceStaticShapePointQuery(activeLevel->space, cpKlikPos, pickingFunc,nil);
}
break;
worked with chipmunk 4, but i cant compile these 2 functions on 5.2.. can anyone tell me how picking is done now?
thanks!
Upgrade code for 5.2 problems
-
- Posts: 9
- Joined: Thu Jul 30, 2009 10:49 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Upgrade code for 5.2 problems
http://code.google.com/p/chipmunk-physics/wiki/Queries
cpSpaceStaticShapePointQuery() and cpSpaceStaticShapePointQuery() have been merged together into cpSpacePointQuery(). The new function allows you to specify layers and groups to filter out queries.
cpSpaceStaticShapePointQuery() and cpSpaceStaticShapePointQuery() have been merged together into cpSpacePointQuery(). The new function allows you to specify layers and groups to filter out queries.
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: 9
- Joined: Thu Jul 30, 2009 10:49 am
- Contact:
Re: Upgrade code for 5.2 problems
edit: my guess is, this should work: cpSpacePointQuery(localSpace,clickPoint,CP_ALL_LAYERS,CP_NO_GROUP,pickFunc,nil)Thank you very much. The function you're suggestion is:
int cpShapePointQuery(cpShape *shape, cpVect p) ?
is there any more info on how to use these?
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data);
void cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data)
i'm quite familiar with it all, but i'm looking at a school deadline so i don't have much time to figure it all out.. All i really need is to call my function 'pickFunc' whenever the 'cpVect points' matches a shape.. My confusion is that the new function 'cpShapePointQuery(cpShape *shape, cpVect p)' doesn't take an argument to call a function when a match is found, wheras the previous function did.. also a direct call to
"void cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data)" doesn't seem to work, maybe because of the fact i really don't understand the typedef there, do i need to refactor my pickFunc to some sort of 'cpSpacePointQueryFunc'? sorry if this sounds a bit noobish..
hope you can help me, because all the rest is working perfectly.
but it doesn't.. i can only assume its about the
typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data);
which i truely don't understand. its now just:
void pickFunc(cpShape *shape, void *data){..}
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Upgrade code for 5.2 problems
That should work just fine. The callback shouldn't need to change at all. The only thing I can think of is that you've set all your shapes to be in no layers. Otherwise I'm not sure what the problem would be.
The callback version allows you to get all shapes overlapping a point. If you just want the first shape found you can use cpSpacePointQueryFirst().
The callback version allows you to get all shapes overlapping a point. If you just want the first shape found you can use cpSpacePointQueryFirst().
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: 9
- Joined: Thu Jul 30, 2009 10:49 am
- Contact:
Re: Upgrade code for 5.2 problems
my bad! copied the whole project, but didnt overwrite the include map for chipmunk, there were 2 separate include folders in my project. guess he searched in the version 4 headers, because CP_ALL_LAYERS and CP_NO_GROUP were not found.. solved now, working like a charm!
thanks so much
thanks so much
Who is online
Users browsing this forum: Bing [Bot], Heise IT-Markt [Crawler] and 17 guests