Translate With Dots
Earlier we saw that to translate a vector \(\mathbf{p}\) is to add it component-wise with a vector of offsets. Translation has this vector notation:
Those right-hand sides don't look like dot products at all. Nevertheless, as with scaling and rotation, we want to rewrite the equations above to use dot products. They will have this form:
Let's again expand out these equations to see how the dot products might be constructed:
Neither \(p_y\) nor \(p_z\) are involved in the scalar definition of \(p'_x\), so we zero out their coefficients in \(\mathbf{a}\). The coefficient for \(p_x\) is an implicit 1. That leads us to this possible definition:
But that can't be right. There's no mention of \(\textrm{offset}_x\) anywhere. There's not even a place to introduce it. Perhaps translation cannot be recast as a dot product? Fear not. To make translation fit in the dot product machinery, we will bend the rules. From out of the blue, we will add 1 as a fourth component of \(\mathbf{p}\):
This special fourth component is called the homogeneous coordinate. We've seen it at work already in vertex shaders when we turn the 3-vector position
into the 4-vector gl_Position
:
gl_Position = vec4(position, 1.0);
gl_Position = vec4(position, 1.0);
The 1 serves as a coefficient for \(\textrm{offset}_x\). It allows us to write \(p'_x\) as this dot product:
Components \(p_y\) and \(p_z\) are expressed similarly. Altogether, translation has this dot product form:
By adding a homogeneous coordinate, we've recast translation as a series of dot products. The next step is to get the graphics card to evaluate all of the dot products in parallel.