I am confused in the relation between ndc to screen coordinate system.
What i did was
-
select screen coordinates (for example touch points on the screen).
-
then pass the screen coordinates to gluUnproject. i set the depth variable(third variable of gluUnproject) to 0.0f.
-
then i multiply the object coordinates to modelviewmatrix and projectionmatrix.
-
after that I clipped the space. then i divide the clip space coordinate with W
- at last i scaled the ndc coordinates to screen coordinates.
- so the result was equal to coordinates which i first chose except Z coordinates. actually the result of Z was equal to -1.0f
after this I changed the gluUnproject`s third variable to 1.0f which i suppose the result was equal to 0.0f. But the result was 1.0f.
So here is the question what is relation between normalized coordinate system and screen coordinate system. how do i set the depth variable of gluUnproject function?
Normalized device coordinates are expressed in the range [-1,+1] and are obtained from the clip-space coordinates dividing them by their W component.
They are transformed in Window-space coordinates by the viewport parameters and the depth range parameters.
If you want to convert the Window-space coordinates back to Normalized device coordinates you need the Window-space z value at the point you want to convert. So, directly from the OpenGL FAQs:
Please note that OpenGL store non-linear depth in the depth buffer.