Get camera transform matrix and optical axis in Houdini

I’ve been trying to find a straight-forward way to get the transformation matrix and optical axis from a camera in Houdini. Eventually, I found a way which is fast and reliable.

The script needs the camera sop path selected with the chsop() function. optransform() will give the transformation matrix of the camera. The optical axis will be the inverted local z axis of the matrix. The local z axis consists of the first three horizontal components on the third row of the matrix. These values can be extracted with the getcomp() function.

string path = chsop("id");
matrix xform = optransform(path);
4@xform = xform;

float a = getcomp(xform,2,0);
float b = getcomp(xform,2,1);
float c = getcomp(xform,2,2);

v@optical_axis = set(a,b,c)*-1;
Previous
Previous

Camera angle of view from focal length

Next
Next

Simple way to automate exports in Houdini with Python