Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

[PyOpenGL-Users] R: Need help about Picking

 [PyOpenGL-Users] R: Need help about Picking From: Marco Avellino - 2010-06-07 11:52:28 Attachments: Message as HTML ```Ok, Ill 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:geometrian@...] 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 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 ```

 [PyOpenGL-Users] Need help about Picking From: Marco Avellino - 2010-05-24 15:11:10 Attachments: Message as HTML ```Hi, I followed a lot of tutorials about picking and I decided to use the Selection Buffer. Now, the code that I wrote works as attended but I am in trouble to discover "the nearest object". In fact, I wrote in my code(as I successfully learned at http://pyopengl.sourceforge.net/documentation/opengl_diffs.html) : . hits = glRenderMode(GL_RENDER) for record in hits: min_depth, max_depth, names = record . and I tried to obtain the lower value of "min_depth" (= "the nearest object") but the result is no correct: the reason is that all my returned values of min_depth are identical. Probably it is perhaps caused by a truncated internal representation - I am not sure, I am a novice in python too -, or by a bad pyopengl configuration. For example, at page http://www.dei.isep.ipp.pt/~matos/cg/docs/manual/gluPerspective.3G.html I read: "roughly log2r bits of depth buffer precision are lost. Because r approaches infinity as zNear approaches 0, zNear must never be set to 0." and I used "gluPerspective(45, 1.0*width/height, 0.05, 100.0)" with the value "0.05" near to 0. I tried to change "0.05" in "1.0" but I obtain the bad effect that my model disappear soon when I zoom into ). Can you suggest me the correct way to calculate the lower value of "min_depth"? Or can you suggest me a alternative method to simulate a pick? I'd like to avoid color based method. Thank you for your help. Marco Avellino ```
 Re: [PyOpenGL-Users] Need help about Picking From: Ian Mallett - 2010-05-25 23:07:29 Attachments: Message as HTML ```On Mon, May 24, 2010 at 7:48 AM, Marco Avellino < marco.avellino@...> wrote: > Hi, I followed a lot of tutorials about picking and I decided to use the > Selection Buffer. > I've never used it, but it looks interesting. > hits = glRenderMode(GL_RENDER) > > for record in hits: > > *min_depth*, max_depth, names = record > In context would be more helpful. For example, did you use glRenderMode(GL_SELECT) and do drawing stuff before this? Could we see your actual source file? > and I tried to obtain the lower value of “min_depth“ (= “the nearest > object”) but the result is no correct: the reason is that all my returned > values of *min_depth* are identical. > ...telling me that nothing is being written to this buffer. Which could mean many things--it's not configured correctly, you're not drawing anything, you don't have a graphics card, etc. Could we see the actual code? Thanks, Ian ```
 Re: [PyOpenGL-Users] Need help about Picking From: Ian Mallett - 2010-05-30 15:31:07 Attachments: Message as HTML ```Hi, Unfortunately, I can't immediately detect any problems with this code. -The name stack is, by default, only 64 large. There's no advantage to having a 1024-length selection buffer. -What happens if you use "print hits"? Is it all zeroes? Ian ```
 [PyOpenGL-Users] R: Need help about Picking From: Marco Avellino - 2010-05-31 16:11:10 Attachments: Message as HTML ```Hi, when I use "print hits" I read the value 0.50000000016 for both min_depth, max_depth. For example, when I call "print min_depth, max_depth, names" l'output is: 0.50000000016 0.50000000016 [object_X's name] 0.50000000016 0.50000000016 [object_Y's name] . If I use GLdouble(min_depth or max_depth), I read 0.5000000001641532 I read always 0.50000000016 except when I draw objects very near. At that moment I read values like 0.49., 0.48, .. etc. and min_depth != max_depth It seems that Selection works only in range [0.2,0.5] where 0.2 is forced by gluPerspective(45, 1.0*width/height, 0.2, 2.0) If you want I can send you my code but I will do it only if you are agree. PS. Sorry if I write you no at sourceforge.net. It seems that I am not able to create a new account _____ Da: Ian Mallett [mailto:geometrian@...] Inviato: domenica 30 maggio 2010 17.31 A: Marco Avellino Cc: pyopengl-users Oggetto: Re: [PyOpenGL-Users] Need help about Picking Hi, Unfortunately, I can't immediately detect any problems with this code. -The name stack is, by default, only 64 large. There's no advantage to having a 1024-length selection buffer. -What happens if you use "print hits"? Is it all zeroes? Ian ```
 Re: [PyOpenGL-Users] Need help about Picking From: Ian Mallett - 2010-05-31 17:06:42 Attachments: Message as HTML ```On Mon, May 31, 2010 at 9:10 AM, Marco Avellino < marco.avellino@...> wrote: > Hi, > > when I use "print hits” I read the value 0.50000000016 for both min_depth, max_depth. > > > > For example, when I call “print min_depth, max_depth, names” l’output is: > > 0.50000000016 0.50000000016 [object_X’s name] > > 0.50000000016 0.50000000016 [object_Y’s name] > > … > > > > If I use GLdouble(min_depth or max_depth), I read 0.5000000001641532 > > > > I read always 0.50000000016 except when I draw objects very near. At that moment I read values like 0.49…, 0.48, …. etc. and min_depth != max_depth > > It seems that Selection works only in range [0.2,0.5] where 0.2 is forced > by gluPerspective(45, 1.0*width/height, *0.2*, 2.0) > > > > If you want I can send you my code but I will do it only if you are agree. > Yes, that might be helpful. I'll fuss with it, and see what I can do. Ian > > > PS. > > Sorry if I write you no at sourceforge.net. It seems that I am not able to > create a new account > ```
 Re: [PyOpenGL-Users] Need help about Picking From: Ian Mallett - 2010-06-04 17:33:22 Attachments: Message as HTML ```On Thu, Jun 3, 2010 at 2:31 AM, Marco Avellino 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 ```
 [PyOpenGL-Users] R: Need help about Picking From: Marco Avellino - 2010-06-07 11:52:28 Attachments: Message as HTML ```Ok, Ill 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:geometrian@...] 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 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 ```
 [PyOpenGL-Users] R: Need help about Picking From: Marco Avellino - 2010-06-08 13:43:16 Attachments: Message as HTML ```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:marco.avellino@...] Inviato: lunedì 7 giugno 2010 13.52 A: 'Ian Mallett' Cc: 'pyopengl-users' Oggetto: R: [PyOpenGL-Users] Need help about Picking Ok, Ill 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:geometrian@...] 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 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 ```
 Re: [PyOpenGL-Users] Need help about Picking From: Ian Mallett - 2010-06-08 13:47:28 Attachments: Message as HTML ```Awesome! Glad I could help. ```