PDA

View Full Version : screen coordinates to world coordinates



Ramya Maithreyi
03-31-2010, 04:23 AM
Hi

I want to convert a point in screen coordinate to world coordinate. I have gone through several threads regarding this. Everything boils down to ray tracing.

The problem in my case is that, there are numerous objects that are being rendered and we do not keep track of them. As and when an object is processed, it is rendered and we get rid of it. So i would be glad if someone could suggest a solution without going through all objects to find if the projected ray intersects it or not.

One additional info is that, the relationship with the z value to y value for all the objects in world coordinates is linear in my case. I was trying to find the intersection between the projected ray and the yz line. It dint work out. Probably i dint get the proper method to get it right.

Also, it is not necessary to find the exact object that intersects the ray. I have other methods to find it out. All i need is just the exact world coordinate.

I would be glad if someone could derive an alternative method ( apart from object picking - ray tracing ) to find out the world coordinate with the given info.

Thanks in advance.

Dark Photon
03-31-2010, 04:34 AM
I want to convert a point in screen coordinate to world coordinate. ... it is not necessary to find the exact object that intersects the ray. ... All i need is just the exact world coordinate.
Well, ignoring the "exact" world coordinate mention...:

glPixelStorei( GL_PACK_ALIGNMENT, 1 );
glReadPixels( x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth );
gluUnProject( x, y, depth, modelview, projection, viewport,
&x, &y, &z );
As you know, anytime you're dealing with floating point values, there is no "exact" except in odd circumstances.

If you don't think this is sufficient, please respond with why as there are variants (such as higher-resolution depth buffers, different depth buffer encodings, other approaches).

BTW, if you do want "world" coordinates, then your "modelview" above should just be the VIEWING matrix.