cpSpaceEachBody

Official forum for the Chipmunk2D Physics Library.
Post Reply
cjung89
Posts: 5
Joined: Mon Jun 08, 2009 7:46 pm
Contact:

cpSpaceEachBody

Post by cjung89 »

I am having trouble using this function properly, particularly the 'data' parameter.

I create a function
void move (cpBody* b, CGPoint l){
b->p = l;
}

then call

cpSpaceEachBody(space, &move, &Location) where Location is a CGPoint acquired from touch event.

I receive a warning "passing argument 2 of 'cpSpaceEachBody' from incompatible pointer type, although the move function does get called. It sets the position to (0,0). How do I change the move function or my call to cpSpaceEachBody to get the desired outcome?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpSpaceEachBody

Post by slembcke »

First of all, you CANNOT use CGPoints interchangeably with cpVects. That is going to cause problems, several people have had problems already that have been fixed by not trying to use CGPoints as cpVects.

Second, the type of your function is not the same as the type because the last parameter is void *. You either need to cast the function pointer or change the second argument type to void * and cast the value inside.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
cjung89
Posts: 5
Joined: Mon Jun 08, 2009 7:46 pm
Contact:

Re: cpSpaceEachBody

Post by cjung89 »

Thanks for the response Slembcke. I am new to Objective C and am not too familiar with this style of function passing. Reading this forum is helping alot.
cjung89
Posts: 5
Joined: Mon Jun 08, 2009 7:46 pm
Contact:

Re: cpSpaceEachBody

Post by cjung89 »

As a follow up to my last question:
if I define "move" like so:

void move(cpBody* b, cpVect* l){
b->p = *l
}

and I call cpSpaceEachBody like so:

cpSpaceEachBody(space, move, &Location);

I get the desired performance with a warning "passing argument 2 of 'cpSpaceEachBody' from incompatible pointer type".
I get the same performance if I preface the 'move' argument with &. Does anyone know how specifically I can get rid of this warning and get the desired result?
cjung89
Posts: 5
Joined: Mon Jun 08, 2009 7:46 pm
Contact:

Re: cpSpaceEachBody

Post by cjung89 »

Nevermind. All I had to do was cast the pointer, like you said. (void *)move
Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests