[PyOpenGL-Users] R: Need help about Picking
Brought to you by:
mcfletch
|
From: Marco A. <mar...@ex...> - 2010-06-08 13:43:16
|
Hi Ian,
I followed your advice ( I convert now in OpenGL units) and it works.
Thank you for your precious help !!!
Marco
_____
Da: Marco Avellino [mailto:mar...@ex...]
Inviato: lunedì 7 giugno 2010 13.52
A: 'Ian Mallett'
Cc: 'pyopengl-users'
Oggetto: R: [PyOpenGL-Users] Need help about Picking
Ok, Ill try to follow your advice
If it works, I will send a new mail to confirm it.
Thank you for your precious help
Marco
_____
Da: Ian Mallett [mailto:geo...@gm...]
Inviato: venerdì 4 giugno 2010 19.33
A: Marco Avellino
Cc: pyopengl-users
Oggetto: Re: [PyOpenGL-Users] Need help about Picking
On Thu, Jun 3, 2010 at 2:31 AM, Marco Avellino
<mar...@ex...> wrote:
Challenge:
Obtain reliable values of min_depth in everywhere I see models in the scene.
Actually I obtain reliable values of min_depth only in a great level of zoom
(= Page Down).
Seems picking is working . . .
Also, the depth seems to be working fine too. Do however remember that it's
returning the depth value in z-buffer units. These measure the part
difference of the fragment from the near plane to the far one. For example,
in your code, the near and far planes are at 0.1 and 2.0, respectively. If
a fragment is 1.05 OpenGL units away from the camera, then in Z, your
fragment is 0.5, because it is halfway between the near and far planes.
However, in practice, the Z-buffer is mapped to be non-linear, so the
conversion is more difficult.
Do note that for selecting, you can just use the values returned from the
selection buffer "as-is". Conversion is not necessary for a
comparison--only for getting actual OpenGL coordinates.
If you still need to convert to OpenGL units, you can do the following:
mpos = #mouse position--ensure that it is measured in
#pixels from the *lower right* of the screen!
returned_z_value = #whatever value you want to convert
viewport = glGetIntegerv(GL_VIEWPORT)
modelview = glGetDoublev(GL_MODELVIEW_MATRIX)
projection = glGetDoublev(GL_PROJECTION_MATRIX)
#pos is the actual position of the object in OpenGL coordinates
pos =
gluUnProject(mpos[0],mpos[1],returned_z_value,modelview,projection,viewport)
#tells how far away, in OpenGL units, the object is
distance = length(pos-camerapos)
Other than this possible pitfall, I don't see any problem.
Ian
|