Matrix Operations
# Basics
# Dimensions
Houdini most commonly uses 3x3 or 4x4 matrices to store transformation data
3x3 -> rotation and scale 4x4 -> rotation, scale and translation
# Identity Matrix
The identity matrix is sort of the base matrix and means no transformation is applied. The diagonal ones store the scale value.
$$ \bigg[\begin{array}{rcl} 1&0&0&0 \\0&1&0&0 \\0&0&1&0 \\0&0&0&1 \\\end{array}\bigg] $$
It can be created in VEX by calling ident()
.
|
|
# Translation
|
|
This is what happens under the hood:
|
|
# Rotations
Quaternion Rotations
|
|
Euler Rotations
|
|
for more details have a look at Quaternions and Euler Rotations
# Scale
|
|
# Order of Operations for Transformations
The default of the transform node and in most 3D packages ist SRT
, which means first Scaling the object in place and then Rotating it before Translating it’s position.
# Permutations
# Shear
# Usecases
# Extracting a Transformation Matrix with VEX
Sometimes it’s desirable to lock an animated mesh to the origin to perform further operations. To move it from it’s position in world space to the origin we need it’s transformation matrix.
Paweł Rutkowski has a great video on the topic. The following is basically a writeup of the contents of his video for my own memory and to easily get back to it.
To create a transformation matrix we first have to create a local coordinate system that moves with the object. To do so we have to identify 2 Points that don’t deform and calculate a vector between the two. First isolate the the 2 points by deleting everything else.
|
|
$$ \begin{array}{rcl} \color{red} x-Axis \\\color{green} y-Axis \\\color{blue} z-Axis \\\color{orange} Position \\\end{array} \equiv \bigg[\begin{array}{rcl} \color{red} 1&\color{red}0&\color{red}0&0 \\\color{green}0&\color{green}1&\color{green}0&0 \\\color{blue}0&\color{blue}0&\color{blue}1&0 \\\color{orange}0&\color{orange}0&\color{orange}0&1 \\\end{array}\bigg] $$
We don’t really need the fourth column but 3x4 matrices dont “exist” in VEX.
|
|
However this will give us the following matrix with the ones in the fourth column
$$ \bigg[\begin{array}{rcl} \color{red} X.x&\color{red}X.y&\color{red}X.z&1 \\\color{green} Y.x&\color{green}Y.y&\color{green}Y.z&1 \\\color{blue} Z.x&\color{blue}Z.y&\color{blue}Z.z&1 \\\color{orange} P.x&\color{orange}P.y&\color{orange}P.z&1 \\\end{array}\bigg] $$
To fix this we can use the setcomp() function.
|
|
Which will give us the correct transformation matrix:
$$ \bigg[\begin{array}{rcl} \color{red} X.x&\color{red}X.y&\color{red}X.z&0 \\\color{green} Y.x&\color{green}Y.y&\color{green}Y.z&0 \\\color{blue} Z.x&\color{blue}Z.y&\color{blue}Z.z&0 \\\color{orange} P.x&\color{orange}P.y&\color{orange}P.z&1 \\\end{array}\bigg] $$ to move the object to the center the inverted matrix has to be multiplied with the position.
|
|
Download: File
# Warping Space
# Twisting
|
|
# Black Hole Vortex
John Kunz demonstrated this technique in his Pure VEX Workshop Week 6.
|
|
sources / further reading