Get camera matrix from an existing camera

Get camera matrix from an existing camera

Anonymous
Not applicable
609 Views
1 Reply
Message 1 of 2

Get camera matrix from an existing camera

Anonymous
Not applicable
I am trying to get the camera1.matrix attribute from an existing camera in a scene.
I thought this would do it (although it seems like a ridiculous amount of code to get that), but it just keeps giving me back an identity matrix (I'm assuming the default return?). Anything blatantly wrong here?

MFnDagNode dagNodCam;
args.get(1,strCamera);
MObject CamObjectParent, CamObjectChild;
MSelectionList activeListCam;
activeListCam.add(strCamera);
MFnCamera fnCamera;
MItSelectionList iterCam(activeListCam);
iterCam.getDependNode(CamObjectParent);
dagNodCam.setObject(CamObjectParent);
CamObjectChild = dagNodCam.child(0);
MDagPath pathToCamera;
MDagPath::getAPathTo(CamObjectChild, pathToCamera);
fnCamera.setObject(pathToCamera);
MMatrix CameraMatrix = fnCamera.transformationMatrix();
MObject MatrixObject = fnCamera.attribute( "matrix" );
MFnMatrixData worldMatrixData(MatrixObject);
MMatrix worldMatrix = worldMatrixData.matrix();
fout_Info << worldMatrix << endl;


Thanks!

David
0 Likes
610 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Does MFnCamera contain the same transformation data as the matrix?
If so, perhaps you could just do this:


MFnCamera fn( dagPath, &status );

MPoint eye = fn.eyePoint(MSpace::kWorld);
MVector right = fn.rightDirection(MSpace::kWorld);
MVector up = fn.upDirection(MSpace::kWorld);
MVector dir = fn.viewDirection(MSpace::kWorld);
0 Likes