Re: [PyOpenGL-Users] Collision Detections
Brought to you by:
mcfletch
From: Richard J. <ric...@op...> - 2004-01-02 01:00:59
|
On Friday 02 January 2004 11:30, Yannick Gingras wrote: > just a quick question, how do you do your collision detections ? Personally, I've not implemented such a beast yet. I believe a standard=20 approach is to have several levels of accuracy: 1. for all objects, determine a bounding sphere or box (your preference), 2. group those bounding objects in space using an octree to do broad=20 elimination of objects that are too far apart to bother each other, 3. for all objects that may be close enough, use the bounding object to see= =20 whether they're close enough to collide, 4. if you're a) using boxes and b) the boxes are a good enough approximatio= n=20 for you, then you're done, otherwise 5. perform per-plane/line/vertex collision detection. > I made a few quick tests with pure python implementation based on > map() and lists to store vertex coordinates. The performance is=20 > understandably really bad, I drop to 1/5 of the FPS I had before > collision detection. Note that any implementation using map() will incur a function call overhea= d,=20 which is slow if you're not using a builtin function. Use a for loop instea= d.=20 =46or some other optimisation techniques, see: http://www.py3d.org/py3d_zwiki/OptimisationHints and the links from: http://simon.incutio.com/archive/2003/10/28/optimisingPython > Is there a way to implement a decent collision detection in pure > python or will I have to rely on C++ binding ? I'd recommend that you first look at your algorithm - it's almost always=20 easier (and better) to optimise your code than to push it off to C or C++.= =20 I've previously gone down the path of reimplementing core functionality in = C=20 with some gain, but then a different approach proved to give a much better= =20 gain, with no C code. BTW, you don't *need* to use C++, unless you have a particular liking for i= t.=20 C will do fine. Richard |