Sensors and default collision handlers

Official forum for the Chipmunk2D Physics Library.
Post Reply
gwynne
Posts: 2
Joined: Fri Oct 15, 2010 4:03 am
Contact:

Sensors and default collision handlers

Post by gwynne »

I'm quite new to Chipmunk, so I apologize if this is a foolish question, but today I ran into what to me seems an odd design decision in the engine.

I set up a sensor in the usual fashion, and added it to a space's static body. I also added a couple of normal bodies and shapes to float around. I set some default collision callbacks, then ran my program. The sensors never registered a collision.

Some investigation and confusion later, I found a line inside the implementation of cpSpace which jumps out of collision handling if either object involved is a sensor and the collision handler is the default for the space.

I eventually realized that my design for the specific situation was flawed and that I could make the sensors work with a specific collision type, but I couldn't make sense of why the code does this. It seems to make it impossible to use a sensor that detects collisions with all shapes in the space, unless I've misunderstood that there seems to be no wildcard value for collision types. Can someone explain to me why this is?

The offending code is in cpSpaceStep.c, line 161 (as of version 5.3.2, though I looked in SVN and it appears to go all the way back to the original implementation of sensors).
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Sensors and default collision handlers

Post by slembcke »

I guess I didn't think it through very well. Default collision handlers are a pretty rarely used feature from what I can tell. I put them in because I knew that some people would want/need more flexibility than the basic collision handlers provide. When I implemented it, I didn't want sensors wasting CPU time to perform the precise collision checks if they were just going to be ignored by the default (the default default) collision handlers which will ignore the results anyway. It didn't occur to me at the time that I was also preventing the user from handling sensors in a more generic fashion.

With a couple minor changes, I can change it so that it only ignores sensor collisions when the default collision handler set by Chipmunk is used.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Sensors and default collision handlers

Post by slembcke »

Made a quick patch. Tested it only lightly though. I think it should make both of us happy.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
gwynne
Posts: 2
Joined: Fri Oct 15, 2010 4:03 am
Contact:

Re: Sensors and default collision handlers

Post by gwynne »

As it turned out, you were right to find default handlers rare; I worked around the issue by fixing a flaw in my original design, after all :). That being said, your patch looks good to me, and solved my test case very neatly. Thanks very much!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Sensors and default collision handlers

Post by slembcke »

Heh, no problem I guess. I'll commit the patch changes to trunk as soon as I do more testing.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests