collision detection performance issue

I’m having a huge performance issue. My computer (a Pentium D 3GHz, 1GB ram, intel q965 chipset) has a lot of trouble to display the whole scene. It is slow. Very slow. I tried on my boss’s computer, a brand new Centrino Duo 2GHz, 2GB ram and a GeForce Go 7300, and it’s still not OK at all.

I therefore tried to find which part of my program is the troublemaker. And it seems that the collision detection module I made is the one. I commented the line calling the module, and it runs smoothly, even on my computer.

I pasted the code of my collision detection module there :

This code does the following thing : when I move the cursor onto one object, it changes the object colors, and when the cursor moves out, the color goes back to normal. I also have a callback for the click event so that it can get the selected element.

Do you have any idea of what I can do to make it more efficient ?

Panda’s collision system is highly optimized for collision detection with its special CollisionSolids, and not at all optimized for collision detection with visible geometry. Thus, if you are relying on collision detection with visible geometry (as is commonly done to implement picking), it will be very slow.

One solution is to wrap CollisionSolids–for instance, CollisionSpheres or CollisionTubes–around all of your pickable objects. Then set up your picker to test for intersections with those solids instead of with the visible geometry.


Ok, thanks.

Is it possible to create a complex collision solid ? I have some models wich are like a piece of a tore and it would be great if I was not forced to use a lot of cylinder to wrap them.

Sure, you can construct a shape out of CollisionPolygons. You can load such a shape out of an egg file, for instance with the { barrier } tag. Search the comments and/or the manual for more information.

Note, though, that the more polygons you have, the more inefficient the collision test will be. Ideally, the torus you construct for collision detection will be much blockier than the one you would construct for rendering.