为什么我的正交投影矩阵不起作用?
我正在尝试使用正交投影渲染位于平面 (z=0) 中的一些四边形。在阅读正交投影矩阵的公式?后,我确实设置了投影矩阵?但我想我做错了什么。
我的第一次尝试是以下矩阵。 W 和 H 是我所需视口的宽度和高度,在以下示例中为 640x640:
˹ 2/w 0 0 0 ˺
| 0 2/h 0 0 |
| 0 0 0 0 |
˻ 0 0 0 1 ˼
这是我渲染左上角位于 (0,0,0) 的四边形时获得的结果:
因为它是垂直翻转的,所以我将矩阵更改为:
˹ 2/w 0 0 0 ˺
| 0 -2/h 0 0 |
| 0 0 0 0 |
˻ 0 0 0 1 ˼
我得到:
然后我尝试移动我的四边形,结果出乎意料。我希望 3D 空间的 X 和 Y 与视口的 X 和 Y 相匹配。然而,当我沿 X 轴移动四边形时,发生了以下情况:
沿 Y 轴移动同样产生了意想不到的结果:
如何修复矩阵,使 3D 空间的 X 轴和 Y 轴与视口的 X 轴和 Y 轴匹配?非常感谢。
I am trying to render some quads that are located in the plane (z=0) with an orthogonal projection. I did set up a projection matrix after reading Formula for a orthogonal projection matrix? but I think I did something wrong.
My first attempt was the following matrix. W, and H are the width and height of my desired viewport which is 640x640 in the following examples :
˹ 2/w 0 0 0 ˺
| 0 2/h 0 0 |
| 0 0 0 0 |
˻ 0 0 0 1 ˼
Here is what I obtained when I rendered a quad whose topleft corner was in (0,0,0) :
Since it was flipped vertically I changed my matrix to :
˹ 2/w 0 0 0 ˺
| 0 -2/h 0 0 |
| 0 0 0 0 |
˻ 0 0 0 1 ˼
I obtained :
Then I tried to move my quad around and the results were unexpected. I wanted the X and Y of the 3D space to match those of the viewport. However here is what happened when I moved the quad along the X axis :
Moving along the Y axis gave equally unexpected results :
How can I fix my matrix so that the X and Y axis of the 3D space match those of the viewport ? Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个投影矩阵实际上是正确的。问题出在四元转换代码中,抱歉弄乱了。
This projection matrix is actually correct. The problem was in the quad translation code, sorry for messing up.
你错过了远近剪辑。试试这个
You missing the far near clipping. Try this