我试图计算玛雅的正交投影矩阵。有人知道怎么计算吗?我对透视图不感兴趣,只对相机的正交视图感兴趣。在
import math
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import maya.OpenMayaUI as OpenMayaUI
# Get view matrix.
view = OpenMayaUI.M3dView.active3dView()
mayaProjMatrix = OpenMaya.MMatrix()
view.projectionMatrix(mayaProjMatrix)
print("\nMaya Projection:")
for x in xrange(0, 4):
print(round(mayaProjMatrix(x, 0), 3),
round(mayaProjMatrix(x, 1), 3),
round(mayaProjMatrix(x, 2), 3),
round(mayaProjMatrix(x, 3), 3))
Maya Projection:
(0.067, 0.0, 0.0, 0.0)
(0.0, 0.132, 0.0, 0.0)
(0.0, 0.0, -0.0, 0.0)
(0.0, 0.0, -1.0, 1.0)
我已经研究了很多网站,但我不太确定如何在玛雅(http://www.songho.ca/opengl/gl_projectionmatrix.html#ortho)中翻译相同的想法。在
在计算机图形学中,投影矩阵只是定义了某个体积到一个定义的标准体积(通常是立方体)的仿射或投影变换。
我不知道玛雅在这里的约定,所以我用的是GL,原则在任何情况下都是一样的。
在GL中,观察体积由单位立方体[-1,1]表示,在标准化设备空间的所有3个维度上。而投影的矩阵工作是将数据转换成剪辑空间。剪辑空间与规范化设备空间的区别在于后者在透视分割之后。但是,因为你不需要透视,只需要一个正交矩阵,除数总是1,所以在这种情况下,我们可以将规范化设备空间和剪辑空间视为相同的。
现在用你的矩阵(从评论中得到的更精确的版本,你粘贴在问题中的那个实际上使你无法重建z)并将一个点与之相乘得到:
所以这个矩阵非常好,因为它可以简单地通过分别反演每个方程来求逆。您需要找出的是}在剪辑空间中显示体积的边缘,因此
x
y
和{x'=-1
,x'=1
,y'=-1
等等。这将导致x的查看体积为[-15,15]、y为[-7.591,7.591](与您在评论中提到的1401/709的纵横比相匹配)和在z中的[-0.1,-5000]。在典型的GL术语中,该矩阵是由于:
^{pr2}$(clip near和clip far的z值按惯例取反,因为相机应该沿着
-z
看,而clip值是距离)。所有这些都在你给出的链接中得到了解释。我会在这里加上同样的链接,如果不是已经在问题中。。。
我想我会发布我正在使用的玛雅代码。显然,在maya中有一个正交属性,它可以帮助根据derhass的答案计算这个称为“正交宽度”(orthographic Width)。
相关问题 更多 >
编程相关推荐