The view matrix is the inverse of the camera's transformation (the position, rotation, and scale of the camera). Instead of having to create the camera's transform matrix and then invert it, you will be implementing a lookAt function that generates this matrix directly.
A lookAt function typically takes a position, the target point at which the camera is looking and a reference up direction. The rest of the work is finding the inverted basis vectors and figuring out where the position is.
Since the basis vectors are orthonormal, their inverse is the same as their transpose. The position can be calculated by negating the dot product of the position column vector with the inverted basis vectors.
Implement the lookAt function in mat4.cpp. Don't forget to add the function declaration to mat4.h. Remember, the view matrix maps the game world forward to the positive Z axis:
The lookAt function is the most convenient way of constructing a view matrix. All of the code samples throughout the rest of this book will use the lookAt function to set up a view matrix.