将设备坐标标准化为窗口坐标
我刚刚读了一些关于 3D 图形背后的理论的东西。据我了解,标准化设备坐标(NDC)是描述水平轴和垂直轴上从-1到1区间内的点的坐标。另一方面,窗口坐标描述了窗口的 (0,0) 和 (宽度,高度) 之间的某个点。 所以我将点从 NDC 坐标系转换为窗口系统的公式是
xwin = width + xndc * 0.5 * width
ywin = height + ynfv * 0.5 * height
现在的问题是,在 glViewport 的 OpenGL 文档中还有另一个公式:
xwin = ( xndc + 1 ) * width * 0.5 + x
ywin = ( yndc + 1 ) * height * 0.5 + y
现在我想知道我错了什么。特别是我想知道附加的“x”和“y”是什么意思。
希望这个问题不是太“与编程无关”,但我认为它在某种程度上与图形编程有关。
I just read some stuff about the theory behind 3d graphics. As I understand it, normalized device coordinates (NDC) are coordinates that describe a point in the interval from -1 to 1 on both the horizontal and vertical axis. On the other hand window coordinates describe a point somewhere between (0,0) and (width,height) of the window.
So my formula to convert a point from the NDC coordinate system to the window system would be
xwin = width + xndc * 0.5 * width
ywin = height + ynfv * 0.5 * height
The problem now is that in the OpenGL documentation for glViewport there is an other formula:
xwin = ( xndc + 1 ) * width * 0.5 + x
ywin = ( yndc + 1 ) * height * 0.5 + y
Now I'm wondering what I am getting wrong. Especially I'm wondering what the additional "x" and "y" mean.
Hope the question isn't too "not programming related", but I thought somehow it is related to graphics programming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
视口不一定从 (0; 0) 开始,因此 OpenGL 文档中的“x”和“y”指的是视口起始位置。
要查看方程有什么问题,请尝试转换 (0; 0) 标准化位置,您将得到 (width; height) 而不是 (width / 2; height / 2)。
Viewport doesn't necessarily start at (0; 0), so 'x' and 'y' in OpenGL documentation refers to viewport starting position.
To see what's wrong with your equation, try transforming (0; 0) normalized position, and you will get (width; height) instead of (width / 2; height / 2).