Translation Matrix

We saw earlier how translations can be represented as a matrix in homogeneous coordinates. Here we make the make a matrix for translation along x by t. OpenGL specifies matrices as a one-dimensional array listed in column-major order so that the first row in this matrix definition is the first column in the matrix, etc.

121                 function generateModelViewMatrix(t)
122                 {
123                     return new Float32Array([1, 0, 0, 0,
124                                              0, 1, 0, 0,
125                                              0, 0, 1, 0,
126                                              t, 0, 0, 1]);
127                 }

Notes

OpenGL matrices are input in column-major order. This shows the matrix and its operation on a vertex.

This matrix is used in the vertex shader to shift the vertices of the second triangle. Drag the slider under the triangles to see this matrix in action.