Advanced collision pair functions

Official forum for the Chipmunk2D Physics Library.

Advanced collision pair functions

Postby sebastiend » Sat Mar 15, 2008 4:48 am

Hello chipmunkers,

I am looking for a way to remove shapes and their graphics when a collision occur. As I use Python, I could extend the Poly class to add a pointer to the other one linking graphics and physics. What do you think about this first solution, and what would I do if I decide to remake it in C?
sebastiend
 
Posts: 4
Joined: Fri Mar 07, 2008 3:47 am

Re: Advanced collision pair functions

Postby sebastiend » Sat Mar 15, 2008 8:36 am

I think I will make the top class check if the shape still exist and if it is not, destroy the graphics and itself. But it doesn't look a gracefull solution to me.
sebastiend
 
Posts: 4
Joined: Fri Mar 07, 2008 3:47 am

Re: Advanced collision pair functions

Postby slembcke » Sat Mar 15, 2008 11:30 am

You should make a list of all of the objects that you want to remove. In the collision pair function add the objects to this list. After the cpSpaceStep() call returns (or whatever it is in the python binding) then you can remove the shapes and bodies from the space. In the C API at least, removing objects during the collision callback is forbidden as it will likely cause nasty crashes. I don't know if the python binding has some sort of protection against this.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Advanced collision pair functions

Postby sebastiend » Sun Mar 16, 2008 7:01 am

Thanks.
sebastiend
 
Posts: 4
Joined: Fri Mar 07, 2008 3:47 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests