Hi all,
I want to use my own Projection Matrix, so I make a simple C++ test with Maya2018,
--------------------------------
M3dView ActiveView = M3dView::activeView();
MMatrix viewProjectionMatrix;
ActiveView.projectionMatrix(viewProjectionMatrix);
MDagPath CameraDagPath;
ActiveView.getCamera(CameraDagPath);
MFnCamera Camera(CameraDagPath);
MFloatMatrix CameraProjectionMatrix = Camera.projectionMatrix();
--------------------------------
viewProjectionMatrix is :
[0] 0x000000ed3f9f9e90 {1.9444444444444440, 0.00000000000000000, 5.5512261465384802e-17, 5.5511151231257827e-17}
[1] 0x000000ed3f9f9eb0 {5.3969174808167319e-17, 2.4253565062388596, -2.7756130732692401e-17, -2.7755575615628914e-17}
[2] 0x000000ed3f9f9ed0 {-1.0793834961633464e-16, 6.7317165903770225e-17, -1.0000200002000021, -1.0000000000000000}
[3] 0x000000ed3f9f9ef0 {-4.7896294409778205e-15, -3.4794329937342400e-15, -0.20000200002000021, 0.00000000000000000}
while CameraProjectionMatrix is:
[0] 0x000000ed3f9f9dd0 {1.94444454, 0.000000000, 0.000000000, 0.000000000}
[1] 0x000000ed3f9f9de0 {0.000000000, 3.45679021, 0.000000000, 0.000000000}
[2] 0x000000ed3f9f9df0 {0.000000000, 0.000000000, 1.00001991, -1.00000000}
[3] 0x000000ed3f9f9e00 {0.000000000, 0.000000000, 0.200001985, 0.000000000}
Why the both is different?
viewport width = 933
viewport height=748
FOV = 54.43
Near clipping plane 0.100
Far clipping plane 10000.000
Hi all,
I want to use my own Projection Matrix, so I make a simple C++ test with Maya2018,
--------------------------------
M3dView ActiveView = M3dView::activeView();
MMatrix viewProjectionMatrix;
ActiveView.projectionMatrix(viewProjectionMatrix);
MDagPath CameraDagPath;
ActiveView.getCamera(CameraDagPath);
MFnCamera Camera(CameraDagPath);
MFloatMatrix CameraProjectionMatrix = Camera.projectionMatrix();
--------------------------------
viewProjectionMatrix is :
[0] 0x000000ed3f9f9e90 {1.9444444444444440, 0.00000000000000000, 5.5512261465384802e-17, 5.5511151231257827e-17}
[1] 0x000000ed3f9f9eb0 {5.3969174808167319e-17, 2.4253565062388596, -2.7756130732692401e-17, -2.7755575615628914e-17}
[2] 0x000000ed3f9f9ed0 {-1.0793834961633464e-16, 6.7317165903770225e-17, -1.0000200002000021, -1.0000000000000000}
[3] 0x000000ed3f9f9ef0 {-4.7896294409778205e-15, -3.4794329937342400e-15, -0.20000200002000021, 0.00000000000000000}
while CameraProjectionMatrix is:
[0] 0x000000ed3f9f9dd0 {1.94444454, 0.000000000, 0.000000000, 0.000000000}
[1] 0x000000ed3f9f9de0 {0.000000000, 3.45679021, 0.000000000, 0.000000000}
[2] 0x000000ed3f9f9df0 {0.000000000, 0.000000000, 1.00001991, -1.00000000}
[3] 0x000000ed3f9f9e00 {0.000000000, 0.000000000, 0.200001985, 0.000000000}
Why the both is different?
viewport width = 933
viewport height=748
FOV = 54.43
Near clipping plane 0.100
Far clipping plane 10000.000
More tests shows that CameraProjectionMatrix changes with near/far clipping plane, but not with the viewport size,
CameraProjectionMatrix[0][0] and CameraProjectionMatrix[1][1] remain unchanged.
3.45679021 / 1.94444454 = 1920/1080
while 1920*1080 is right my PC's display resolution.
What's happening?
More tests shows that CameraProjectionMatrix changes with near/far clipping plane, but not with the viewport size,
CameraProjectionMatrix[0][0] and CameraProjectionMatrix[1][1] remain unchanged.
3.45679021 / 1.94444454 = 1920/1080
while 1920*1080 is right my PC's display resolution.
What's happening?
I think the active view is including the overscan in the projection matrix.
If I disable the Resolution Gate by doing View > Camera Settings > No Gate then the values becomes very similar. Note that this sets the Overscan on the camera to 1.0 on the camera shape.
Here's test code in Python which might be easier to iterate with than in C++:
import maya.api.OpenMaya as om
import maya.api.OpenMayaUI as omui
view = omui.M3dView.active3dView()
view_matrix = view.projectionMatrix()
print view_matrix
sel = om.MSelectionList()
sel.add("persp")
dag = sel.getDagPath(0)
fn_cam = om.MFnCamera(dag)
cam_matrix = fn_cam.projectionMatrix()
print cam_matrix
I think the active view is including the overscan in the projection matrix.
If I disable the Resolution Gate by doing View > Camera Settings > No Gate then the values becomes very similar. Note that this sets the Overscan on the camera to 1.0 on the camera shape.
Here's test code in Python which might be easier to iterate with than in C++:
import maya.api.OpenMaya as om
import maya.api.OpenMayaUI as omui
view = omui.M3dView.active3dView()
view_matrix = view.projectionMatrix()
print view_matrix
sel = om.MSelectionList()
sel.add("persp")
dag = sel.getDagPath(0)
fn_cam = om.MFnCamera(dag)
cam_matrix = fn_cam.projectionMatrix()
print cam_matrix
Can't find what you're looking for? Ask the community or share your knowledge.