# Component Wise Operations

There are two component wise functions that are sometimes used in games. The first is addition, the second is scaling. The scaling operation doesn't actually scale the matrix, instead it scales each component of the matrix by a scalar value.

Component wise functions are trivial to implement, perform the required operation on every component of the matrix. There isn't much more to say about them, component wise addition and scaling are implemented below.

mat4 Add(mat4 left, mat4 right) { mat4 result; // Consider unrolling these loops for speed for (int i = 0; i < 16; ++i) { result.v[i] = left.v[i] + right.v[i]; } return result; } mat4 Scale(mat4 matrix, float value) { mat4 result; for (int i = 0; i < 16; ++i) { result.v[i] = matrix.v[i] * value; } return result; } // mat 2 and 3 implementations are trivial, change the argument type and loop limit