Transforming matrix with python API ignores translation

   1679   4   1
User Avatar
Member
5 posts
Joined: 8月 2021
オフライン
Using the houdini (20.5.305) python API, I created a transformation matrix that I would like to use to rotate and translate a camera.

The rotation gets applied, but the translation of 5 units in xyz is completely ignored. Am I misunderstanding how to perform this transformation correctly? Thanks!

import hou

cam = hou.node('/obj').createNode('cam')

transform_matrix = hou.Matrix4([
    [1, 0, 0, 5],
    [0, 0, -1, 5],
    [0, 1, 0, 5],
    [0, 0, 0, 1]
])

cam.setWorldTransform(transform_matrix)

print(cam.worldTransform())


Console output (notice the final column reset):
[[1, 0, 0, 0],cam.pre
 [0, 0, -1, 0],cam.pre
 [0, 1, 0, 0],cam.pre
 [0, 0, 0, 1]]cam.pre
cam.pre
Edited by hzwus - 2025年2月6日 14:15:52
User Avatar
Member
247 posts
Joined: 5月 2017
オフライン
Houdini uses the last row for the translate vector or uses the transposed method of the matrix4 object before applying.
User Avatar
Member
9430 posts
Joined: 7月 2007
オフライン
In other words most matrices in Houdini are in Row Major order so bear that in mind overall when doing matrix operations in Python or VEX as that may also imply different order of operations than you are likely expecting if you are used to operate Column Major matrices
Edited by tamte - 2025年2月6日 17:56:25
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
5 posts
Joined: 8月 2021
オフライン
Got it, thank you!!
User Avatar
Member
5132 posts
Joined: 2月 2012
オフライン
It's worth noting VEX sometimes uses column major convention for matrices. For example the gradient matrices returned by volumesmoothsamplev [www.sidefx.com] and volumecubicsamplev [www.sidefx.com] functions.

The grad is a matrix whose i-th column is the gradient of the i-th component of the volume.

To align this matrix with the row-major convention, you need to transpose it.

There are other VEX functions that exhibit this issue.

RFE pending to document these more thoroughly.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
  • Quick Links