PDA

View Full Version : How to set depth range in orthographic view



Ronan2013
07-23-2014, 11:46 PM
Dear All,

I'm trying to map the mouse cursor position from screen coordinates into orthographic view, for that I use
world_mouse_position = screen_mouse_position * inverse(MVPW) But it never returns the z value correctly( screen_mouse_position = (X,Y,0) ), interestingly it returns the correct values for the X and Y values in world coordinates, How am I supposed to fix that ?

I already tried to set the depth range of glOrtho with playing around the Near/Far values, but that didn't help also.

Regards,

Dark Photon
07-24-2014, 04:30 AM
So your input value is screen_mouse_position = (X,Y,0)? In window coordinates, with the default glDepthRange setting, 0 = near clip plane. If you have a specific point "under" your mouse click that you want to back transform, you need to feed that in instead of 0.

Use glReadPixels() for instance to fetch back the window-space 0..1 depth value.

MtRoad
07-24-2014, 04:50 AM
An orthographic view flattens or projects a scene onto a plane without any perspective, so it looks like what you are getting is what I'd expect.

What are you trying to do?

Ronan2013
07-24-2014, 08:33 AM
Dark Photon
So your input value is screen_mouse_position = (X,Y,0)?
If you have a specific point "under" your mouse click that you want to back transform, you need to feed that in instead of 0.
Yes I'm reading the windows screen coordinates but this obviously doesn't have any z value,

I don't have any specific point, mouse pointer may completely hoover in spatial space and sometimes may hoover over objects or not.

What I expected to see is :
If I set the ortho as glOrtho(left, right, top, bottom, znear=0 , zfar=1) ; then supplied mouse_screen_position(X,Y,0) should retrieve world_mouse_position(XWorld,YWorld, 0) if mouse_screen_position(X,Y,1) should retrieve world_mouse_position(XWorld,YWorld, 1).

Am I wrong for this reasoning?

Dark Photon
07-24-2014, 02:30 PM
If you mean eye-space instead of world-space (or you have an identify viewing transform), I believe what you say ("What I expected to see is") should be the case except that the near/far values are actually the negative of the eye-space Z values, just like with glFrustum.