从窗口到opengl坐标系的直观解释 [英] From window to opengl coordinate system intuitive explanation
问题描述
使用鼠标功能时,我试图理解从窗口坐标轴(左上角原点)到OpenGL
坐标轴(左下角原点)的地图.在相关书籍中,此地图由以下两行描述:
I am trying to understand the map from window coordinate axis (origin top-left) to OpenGL
coordinate axis (origin left-bottom) when using the mouse function. In relevant book this map is described by the two following lines:
points[count].x = (float) x / (w/2) - 1.0;
points[count].y = (float) (h-y) / (h/2) - 1.0;
我怀疑这两行描述了一个比例.您能对此地图进行直观的数学解释吗?
I suspect that these two lines depict a scale. Could you please give an intuitive-mathematical explanation of this map?
推荐答案
您指的是哪本书? NDC空间中的原点是视口的中心( 0,0 是中心; -1,-1 是左下角; 1, 1 是右上角).其他任何坐标空间都由投影矩阵定义.
What book are you referring to? The origin in NDC-space is the center of the viewport (0,0 is the center; -1,-1 is the bottom-left; 1,1 is the top-right). Any other coordinate space is defined by your projection matrix.
我相信这本书试图教给你的是 NDC -1,-1 是视口和 NDC 1,1 是右上角.
I believe what the book is trying to teach you is that NDC-1,-1 is the bottom-left corner of your viewport and NDC1,1 is the top-right corner.
-
NDC X =(2.0 *(Screen X -Viewport X )/Viewport W )-1.0;
NDCX = (2.0 * (ScreenX - ViewportX) / ViewportW) - 1.0;
NDC Y =(2.0 *(Screen Y -Viewport Y )/Viewport H )-1.0;
NDCY = (2.0 * (ScreenY - ViewportY) / ViewportH) - 1.0;
当然,您还需要执行一个附加步骤,因为Y轴在鼠标坐标系中沿相反的方向运行.这就是为什么您在映射h-y
这篇关于从窗口到opengl坐标系的直观解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!