Picked Position

I am using glSelectBuffer to pick onscreen objects, with no problem. Part of my program is a physics editor that allows the user to push and pull objects around in real time. For this, I need to know the position of the pick, so that I can apply force with the right position and vector.

How can I get the point in 3D space that was picked, or at least the z-distance in front of the camera that was picked (so I can transform it to 3D space)? gluUnproject takes a z-parameter, so I can’t try to use it without knowing how far away my picked point is.

I got some information with glReadPixels, but I don’t understand how a clamped value [0-1] represents a depth relative to my camera. My range is like 60,000, and I am getting values of 1.0 and a little bit less, at a depth like 1000 in front of my camera.


It works. Thanks!