[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Collision Detection with Pygame/OpenGL Surfaces



I am a little (ok, very) late getting into this discussion, but Mr LeCompte's suggestions are right on.

I can add to the discussion that glUnproject is complemented by glProject.   Assuming that you can read the depth buffer in PyOpenGL, one way to approach the molecular modelers problem is by:

1) get pixel coords (x,y) of mouse.
2) get w value from depth buffer for that screen position.
3) use glProject(x,y,w) to get the 3D position in model space for the foremost object. 
4) use a simple proximity search to find the molecule nearest that 3D pos.

The depth buffer contains a w value representing the distance from the camera for the object drawn (the foremost one) at that pixel.  It is in the range of 0-1 rather than model units, for whatever reason, and does not proportionally map to model unit distance, so you need to use the glProject/glUnproject functions to get meaning from the w values.

Also (on a related matter) the 'Lamina' library provides a way to draw in OpenGl displays using the pygame drawing functions.  Check the cheeseshop, or Google it.  I am the author, so feel free to ask for assistance if it doesn't work as expected.

David

On 8/2/07, Ian Mallett <geometrian@xxxxxxxxx> wrote:
On 8/2/07, Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
There isn't really a workaround available to you. Basically you can't
use pygame surface functions on pygame's opengl surfaces (some people
are writing stuff so you can into SDL, but it's not really available
in pygame)
Yep. 
Ian





--
dkeeney@xxxxxxxxxxxxxxxx
Pitcher's Duel -> pitchersduel.python-hosting.com