Home

Search IconIcon to open search

OpenGL matrices

For matrix operations to work together nicely, use this convention:

Translation matrix
$$\begin{bmatrix}
1 & 0 & 0 & X\
0 & 1 & 0 & Y\
0 & 0 & 1 & Z\
0 & 0 & 0 & 1\
\end{bmatrix}$$

Scaling matrix
$$\begin{bmatrix}
x & 0 & 0 & 0\
0 & y & 0 & 0\
0 & 0 & z & 0\
0 & 0 & 0 & 1\
\end{bmatrix}$$

1
TransformedVector = TranslationMatrix * RotationMatrix * ScaleMatrix * OriginalVector;

# The Final Product

1
2
// C++ : compute the matrix
glm::mat4 MVPmatrix = projection * view * model; // Remember : inverted !
1
2
// GLSL : apply it
transformed_vertex = MVP * in_vertex;