opengl 如何将 3d 点投影到屏幕空间?
我正在尝试用我自己的软件光栅器模拟 opengl 的子集。
我大胆猜测该过程如下所示:
将 3d 点乘以模型视图矩阵 ->将该结果乘以投影矩阵
这是正确的吗?
另外,投影矩阵的大小是多少以及它是如何工作的?
I am trying to emulate a subset of opengl with my own software rasterizer.
I'm taking a wild guess that the process looks like this:
Multiply the 3d point by the modelview matrix -> multiply that result by the projection matrix
Is this correct?
Also what size is the projection matrix and how does it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(无耻的自我推销,抱歉)我写了一个关于这个主题的教程:
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
不过,有一点我没有解释。在本教程结束时,您将处于标准化设备坐标中,即 -1 到 +1。一个简单的线性映射将其转换为 [0-screensize]。
(shameless self-promotion, sorry) I wrote a tutorial on the subject :
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
There is a slight caveat that I don't explain, though. At the end of the tutorial, you're in Normalized Device Coordinates, i.e. -1 to +1. A simple linear mapping transorms this to [0-screensize].
查看gluProject() 代码也可能对您有所帮助。这需要对象坐标中的x、y、z点以及指向modelView<的指针/em>、投影和视口矩阵,并告诉您x、y、( z)坐标在屏幕空间中(z是可以在深度缓冲区中使用的 0 到 1 之间的值)。代码中显示了所有三个矩阵乘法,以及透视所需的除法。
You might also benefit from looking at the gluProject() code. This takes an x, y, z point in object coordinates as well as pointers to modelView, projection, and viewport matrices and tells you what the x, y, (z) coordinates are in screenspace (the z is a value between 0 and 1 that can be used in the depth buffer). All three matrix multiplications are shown there in the code, along with the divisions necessary for perspective.
该点乘以模型视图矩阵,然后乘以投影矩阵。将结果归一化,然后与视口矩阵相乘以获得屏幕坐标。所有矩阵都是4X4矩阵。您可以查看此链接以获取更多详细信息。
http://www.songho.ca/opengl/gl_transform.html#example2
The point is multiplied by the modelview matrix and then with projection matrix. The resultant is normalized and then multiplied with viewport matrix to get the screen coordinates. All matrices are 4X4 matrix. You can view this link for further details.
http://www.songho.ca/opengl/gl_transform.html#example2