Matrices for Tech Artists, non Affine Transformations

Different Axis or Origin

In the previous post, I mentioned a series of affine transformations. The linear ones were scaling, rotation and skewing, and the affine one was those plus translation in homogeneous coordinate systems. That was fun. The issue was, everything was with respect to the origin. What if you wanted to rotate the mesh not around the origin, but around an arbitrary point or axis?

Arbitrary Origin

Consider the following scenario. In the scene below, the origin is marked using the xyz arrows. We would like to rotate the mesh, but not around the origin, but around the head of the statue. Let’s see what happens first if we simply rotate around the origin. I am not going to go over the rotation matrix since I covered it last time, this is the rotation around x axis. Code

Figure -1- Translation to Head space, rotate, translate back

Arbitrary Axis

In the scene below, I added a fourth axis colored magenta. This one is the axis we actually wish to rotate around. This axis can of course be represented in a vector form. Let’s call it c1, c1 has the value (-1, 0, -1).

Figure -2- rotation first to align the x axis with the desired axis of rotation, rotate back

Model Matrix

You didn’t need to do all this work. Above we almost finished implementing the model matrix for a local space we defined ourselves. The only thing we didn’t do was scale. Good news is you now know how to create the transform.localToWorld and transform.WorldtoLocal matrix in Untiy. In future, you can simply put an empty gameobject where you want your rotation center to be, and rotate it so that the axis are how your want them to be, and pass on the localToWorld and WorldToLocal matrix of the empty gameobejct to the shader to imitate everything we did above.

Non Affine Transformations

Finally more juicy stuff. A non affine transformations is one where the parallel lines in the space are not conserved after the transformations (like perspective projections) or the mid points between lines are not conserved (for example non linear scaling along an axis).

Vertex Attribute and Transformation Matrices

So let’s go back to the statue of the wandering man. Let’s say we are happy with how the transformation looks, but don’t want the staff to bend with the body. The issue at the moment is that our transformation is a function of the y component of the vertex position. This will apply a global effect everywhere on the mesh.

Figure -4- Vertex painting

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store