From window to opengl coordinate system intuitive explanation

前端 未结 1 2075
野的像风
野的像风 2020-12-22 10:22

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

相关标签:
1条回答
  • 2020-12-22 10:34

    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.

    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.

    A more complete mapping would include the X and Y location of your viewport:

    • NDCX = (2.0 * (ScreenX - ViewportX) / ViewportW) - 1.0;

    • NDCY = (2.0 * (ScreenY - ViewportY) / ViewportH) - 1.0;

    This mapping is illustrated below (the square on the right is the viewport):

      http://upload.wikimedia.org/wikipedia/commons/2/23/Viewport_transformation.png

    You of course have one additional step necessary since the Y-axis runs the opposite direction in your mouse coordinate system. That is why you see the Y-axis flipped in your mapping h-y

    0 讨论(0)
提交回复
热议问题