Creating a matrix
In this section, you will create a new 4 x 4 matrix. This matrix will be stored as a 16-element array of floats. A union will be used to allow access to the data in the matrix in an easier-to-use fashion:
Important note
The identity matrix is a special matrix that multiplies anything by the identity matrix results in the original matrix. The identity matrix does no mapping. An identity matrix contains 0 in all elements except the main diagonal, which is made up entirely of 1.
- Create a new file,
mat4.h
. This file is needed to declare themat4
struct. - Add the following structure declaration to
mat4.h
, which starts a union by declaring a flat array of 16 elements as the first member of the union:struct mat4 { union { float v[16];
- The next member of the union is a structure of
vec4
variables. Each of thevec4
variables represents one column of the matrix; they are named after...