View Full Version : gluUnProject without glReadpixels

kingc8

10-07-2012, 10:17 AM

Hello,

I have a quick question for you experts.

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?

Any ideas?

Thanks very much,

Cameron

tonyo_au

10-08-2012, 05:52 PM

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.

kingc8

10-09-2012, 03:13 AM

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.

michagl

10-09-2012, 03:46 PM

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.

kingc8

10-10-2012, 03:23 AM

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.

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.

It's just a flat ground, it's simply the Z-plane.

Thanks,

Cameron

Dan Bartlett

10-10-2012, 04:09 AM

Just perform a line-plane intersection (http://en.wikipedia.org/wiki/Line-plane_intersection) test. No need to use glReadPixels for this.

kingc8

10-10-2012, 11:32 AM

Oh yes, that works! Thanks Dan!

.. and thanks to the other contributors for your feedback.

michagl

10-13-2012, 08:21 AM

This is what I thought but I was not sure so I did not want to complicate the thread. Good job with your second description! And good luck :)

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.