I’m using gluUnProject, which is great. And commonly people would use glReadPixels with the GL_DEPTH_COMPONENT to find the viewing volume z value to feed to gluUnProject to determine a 3D point.

My problem is, I want the z value where the projected ray intercepts the Z-plane, and not the object obstructing it. -For example a bunch of trees. ReadPixel would stop once it hit the tree in the depth component look up. -I need the ray to pass through the tree and stop when the z in the viewing volume touches the Z plane (zero) of OGL space.

Put simply, I need the “ground” unprojected, not the stuff on it.

I guess I need to use something other than glReadPixels to find viewing volume z of the Z plane?

the win z value in gluUnProject is a value between 0 and 1 from the depth buffer. If you use 0 you get a point in the near plane, if you use 1 you get a point on the far plane. You now have a ray that you can do what you like with.

Thanks, but I understand that already. What I would like to do with that ray is find out where the Z plane (Z origin, Z zero) is within the zNear (0) and zFar (1) viewing area.

I think you will have to reformulate the question. I can’t understand anyway, so I doubt anyone could

…so you are projecting through some 2D coordinate on the near plane (let’s say your camera lens) and it needs to intersect with what precisely? Just describe it in everyday language if you can.

[QUOTE=michagl;1243295]I think you will have to reformulate the question. I can’t understand anyway, so I doubt anyone could

…so you are projecting through some 2D coordinate on the near plane (let’s say your camera lens) and it needs to intersect with what precisely? Just describe it in everyday language if you can.[/QUOTE]

Ok, imagine the camera has a location of 0,20,20 and we are looking directly at the Origin (0,0,0), so we’re approximately looking at 45 degrees towards the Z plane which is treated as the ground, the camera has a zNear of 0.1 and a zFar of 100.

My window is 500x500 and the mouse cursor is at 100,100 and I want to know where the mouse cursor is projecting a ray that touches the Z plane.

A typical case would be an RTS game, where you have a view like this, and where the 2D mouse is in the window, sets a flat in-world 2D reticule on the ground. It ignores units and building structures, including trees and other stuff.