使用正交矩阵将 3D 坐标转换为 2D 屏幕坐标
我有一个在 3D 空间中存储顶点的场景。我想做的是从等距角度正交渲染这些顶点。
在我所有的搜索中,明显的答案是使用像 OpenGL 等中的正交相机。
问题是我想从头开始写这个来帮助我的理解,所以我真的在寻找里面的理论相机。
如何使用正交矩阵获取 3D 空间中的任意点并从中获取屏幕坐标?
目前我有我的正交矩阵:
[2/r-l, 0, 0, r+l/r-l]
[0, 2/t-b, 0, 0, t+b/t-b]
[0, 0, 2/f-n, 0, f+n/f-n]
[0, 0, 0, 1]
其中 r 是右,l 是左,t 是顶部,b 是底部,f 是远,n 是近。
我将绕 y 轴的旋转附加到此矩阵,然后将顶点坐标与该矩阵相乘,我相信这会将我的世界空间顶点转换为我的视图空间坐标......
但它仍然是一个 3D 向量,所以我很好奇我如何推断 2D 屏幕坐标。
任何帮助都会很棒。
谢谢, 乔恩
I have a scene that stores vertices in 3D space. What i would like to do is render those vertices Orthographically from an isometric perspective.
In all of my searching the obvious answer is to use an Orthographic camera like the ones in OpenGL etc.
The problem is that i'd like to write this from scratch to help with my understanding so really I'm looking for the theory inside the camera.
How can i take an arbitrary point in 3D space and get the screen coordinates out of it using an orthographic matrix?
Currently I have my orthographic matrix:
[2/r-l, 0, 0, r+l/r-l]
[0, 2/t-b, 0, 0, t+b/t-b]
[0, 0, 2/f-n, 0, f+n/f-n]
[0, 0, 0, 1]
Where r is Right, l is Left, t is Top, b is Bottom, f is Far, and n is Near.
I append my rotation around the y axis to this and then multiply the vertex coordinates against this matrix which I believe converts my World Space vertex into my view space coordinates...
But it's still a 3D vector so I'm curious as to how i extrapolate the 2D Screen coordinates.
Any help would be great.
Thanks,
Jon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里一篇很棒的文章解释了 OpenGL 是如何做到这一点的。
Here's a great article explaining how OpenGL does it.