0

I am confused in the relation between ndc to screen coordinate system. What i did was

  1. select screen coordinates (for example touch points on the screen).

  2. then pass the screen coordinates to gluUnproject. i set the depth variable(third variable of gluUnproject) to 0.0f.

  3. then i multiply the object coordinates to modelviewmatrix and projectionmatrix.

  4. after that I clipped the space. then i divide the clip space coordinate with W

  5. at last i scaled the ndc coordinates to screen coordinates.
  6. 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?

4

1 回答 1

3

归一化坐标系和屏幕坐标系有什么关系?

标准化设备坐标在 [-1,+1] 范围内表示,并且是从剪辑空间坐标除以它们的 W 分量获得的。

它们通过视口参数和深度范围参数在窗口空间坐标中进行转换。


如何设置 gluUnproject 函数的深度变量?

如果要将窗口空间坐标转换回标准化设备坐标,则需要在要转换的点处设置窗口空间 z 值。因此,直接从OpenGL 常见问题解答

GLdouble z;
glReadPixels (x, y, 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &z);

请注意,OpenGL 在深度缓冲区中存储非线性深度。

于 2012-08-13T14:02:36.787 回答