I'm attempting to calculate maya's orthographic projection matrix. Is anyone familiar with how to calculate it? I am not interested in perspective, just orthographic camera views.
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()
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))
(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)
I've been researching lots of sites, but I'm not quite sure how to translate the same idea in maya (http://www.songho.ca/opengl/gl_projectionmatrix.html#ortho).
Best How To :
In computer graphics, a projection matrix just defines an affine or projective transformation of some volume into a defined standard volume, typically a cube.
I don't know maya's conventions here, so I'm using GL's. The principles are the same in any case.
In GL, the viewing volume is represented by the unit cube [-1,1] along all 3 dimensions in normalized device space. And the projection's matrix job is to transform data into clip space. The difference between clip space and normalized device space is that the latter is after the perspective divide. However, since you don't want a perspecive but just an ortho matrix and the divisor will just be constantly 1 - so in this case, we can consider normalized device space and clip space as the same.
Now taking your matrix (the more precise version from the comments, the one you pasted in the question actually makes it impossible to reconstruct z) and multiplying a point to it leads to:
(0.066666667 0.0 0.0 0.0 ) (x)
(0.0 0.131734838 0.0 0.0 ) (y)
(0.0 0.0 -0.000200002 -1.00002) (z)
(0.0 0.0 0.0 1.0 ) (1)
x' = 0.066666667 * x
y' = 0.131734838 * y
z' = -0.000200002 * z -1.00002
So this matrix is very nice in that it simply can be inverted by inverting each equation separately. All you need to find out are the
z for the edges of the viewing volume in clip space, so
y'=-1 and so on.
This results in the viewing volume [-15,15] in x, [-7.591,7.591] in y (matching the aspect ratio of 1401/709 as you mentioned in the comments) and [-0.1,-5000] in z. In typical GL terms, this matrix is the result of:
ortho(-15, 15, -15/aspect, 15/aspect, 0.1, 5000)
(the z values for clip near and clip far are negated by convention, as the camera is supposed to look along
-z, and the clip values are distances).
And all of that is actually explained in the link you gave. I would have added that very same link here, if it wasn't already in the quesiton...