Re: depth values in picking

Posted by gouessej on
URL: https://forum.jogamp.org/depth-values-in-picking-tp4030347p4030377.html

Hi

Mathieu Blossier wrote
I know that picking is deprecated, but I've never noticed any problem with it. Furthermore, for my use, it always takes less than a frame rendering, so it's ok.
Use it at your own risk. As long as it is only for a tiny project, if it works for you, why not? However, I wouldn't use it in a "serious" application. The fact that on a particular machine you have never noticed any problem with it doesn't mean that there is no problem. For example, color picking isn't a viable approach on lots of Lenovo laptops.

Mathieu Blossier wrote
About depth, I think I've found a quite correct function to map values returned to screen z value :

f(z)=eyeToScreenDistance*(z-1-d/eyeToScreenDistance)/(z-1-eyeToScreenDistance/d);

where :
* z is the min/max value returned, 0 for near plane and 2 for far plane
* eyeToScreenDistance is the distance from eye to the screen, which for me is in the middle between near and far planes
* d is half the distance between near and far planes

I've tested it and got good results (error less than 0.001), to improve it I think the function needs something like sqrt((z-a)²+b²) corresponding to some normalization.

I've tested it only in cases where the screen is in the middle between near and far planes ; and where d is also equal to screen view width.

Cheers,
Mathieu
Thank you for the tip. What do you mean by "screen z value"? I just want to ensure that you can't use glUnproject or something similar in your case.
Julien Gouesse | Personal blog | Website