6.10 - Chaining Transformations (Summary)

The previous lesson demonstrated a robot arm with two linkages. This demonstrated how matrix transformations are chained together to create complex motion. The creation of the rendering transformations were created explicitly to make it clear how the transformations are created. Here is a summary of the transforms and the code that created them:

baseTransform =baseRotation
Eq1
forearmTransform =baseRotation
*translateToPin
*rotateForearm
Eq2
upperArmTransform =baseRotation
*translateToPin
*rotateForearm
*translateToForearmEnd
*rotateUpperarm
Eq3
// For rendering the base
matrix.multiplySeries(transform, projection, view, base_y_rotate);

// For rendering the forearm
matrix.multiplySeries(transform, projection, view, base_y_rotate,
                      forearm_translate, forearm_rotate);

// For rendering the upper arm
matrix.multiplySeries(transform, projection, view, base_y_rotate,
                      forearm_translate, forearm_rotate,
                      upperarm_translate, upperarm_rotate);

Reusing Transformations

Matrix multiplication is an expensive operation. For 4-by-4 matrices, multiplication requires 64 multiplies and 48 additions. We would like to avoid duplicate matrix multiplications whenever possible. For the robot arm, there is no need to repeat the same matrix multiplications over and over again. We can reuse the previous transform and simply post-multiply the additional transforms. The creation of each transform in the code could be done like this:

// For rendering the base
matrix.multiplySeries(transform, projection, view, base_y_rotate);

// For rendering the forearm
matrix.multiplySeries(transform, transform, forearm_translate, forearm_rotate);

// For rendering the upper arm
matrix.multiplySeries(transform, transform, upperarm_translate, upperarm_rotate);

Notice that in the 2nd and 3rd function calls the second parameter is the value of transform from the previous calculation. The following demo code contains theses simplified calculations.

Reusing transform calculations is important for complex renderings, but you should not collapse your transform calculations until you are completely clear on how to build complex chains of transformations. First, get a WebGL program to work correctly. You can always make efficiency optimizations later if slow rendering is an issue.

Show: Code Canvas Run Info
./simple_transform_example4/simple_transform_example4.html

A robot arm rendered by re-using transforms.

Please use a browser that supports "canvas"
-90.0 +90.0 Forearm angle: 0.00 :
-90.0 +90.0 Upper arm angle: 0.00 :
Animate
Shader errors, Shader warnings, Javascript info
Open this webgl program in a new tab or window

Next Section - 6.11 - More Matrix Math Concepts