Identity matrix
Multiplying a scalar number by 1 will result in the original scalar number. There is a matrix analogue to this, the identity matrix. The identity matrix is commonly written as I. If a matrix is multiplied by the identity matrix, the result is the original matrix .
In the identity matrix, all non-diagonal elements are 0, while all diagonal elements are one . The identity matrix looks like this:
Getting ready
Because the identity matrix has no effect on multiplication, by convention it is the default value for all matrices. We're going to add two constructors to every matrix struct. One of the constructors is going to take no arguments; this will create an identity matrix. The other constructor will take one float for every element of the matrix and assign every element inside the matrix. Both constructors are going to be inline.
How to do it…
Follow these steps to add both a default and overloaded constructors to matrices:
- Add the default inline constructor to the
mat2...