In which you learn how to grow and shrink an object through vector multiplication.
To scale an object, you multiply its position by scale factors. A factor greater than 1 will grow the object. A factor less than 1 but greater than 0 will shrink an object. A factor of 0 will collapse an object into a black hole. A negative factor will flip an object.
Scaling is sometimes expressed as vector multiplication. Here position \(p\) is multiplied by \(\textrm{factors}\):
$$ \begin{bmatrix}p_x \\ p_y \\ p_z \end{bmatrix} \times \begin{bmatrix} \textrm{factors}_x \\ \textrm{factors}_y \\ \textrm{factors}_z \end{bmatrix} = \begin{bmatrix}p_x \times \textrm{factors}_x \\ p_y \times \textrm{factors}_y \\ p_z \times \textrm{factors}_z\end{bmatrix} $$
In GLSL, the factors are declared as a uniform and applied using the *
operator:
uniform vec3 factors;
in vec3 position;
void main() {
vec3 scaledPosition = position * factors;
gl_Position = vec4(scaledPosition, 1.0);
}
Try adding scaling to one of your renderers.