glm::vec3 cameraPos(0.0f, 0.0f, -2.0f); //Camera position
glm::vec3 cameraTarget(0.0f, 0.0f, -3.0f); //Camera target
glm::vec3 lookDir = glm::normalize(cameraTarget - cameraPos); // Direction the camera is looking at
glm::vec3 upDir = glm::normalize(glm::vec3(0.0f, 1.0f, 0.0f)); //Up-direction of the camera
glm::vec3 rightDir = glm::normalize(glm::cross(lookDir, upDir)); //Calculate the third axis
glm::vec3 perpUpDir = glm::normalize(glm::cross(rightDir, lookDir)); //Recalculate the up-direction of the camera
glm::mat4 rotMat(1.0f); //4x4 identity matrix (to be rotation matrix)
rotMat[0] = glm::vec4(rightDir, 0.0f); //Add calculated vector
rotMat[1] = glm::vec4(perpUpDir, 0.0f); //Add calculated vector
rotMat[2] = glm::vec4(-lookDir, 0.0f); //Add calculated vector ********
rotMat = glm::transpose(rotMat); //Transpose the matrix
glm::mat4 transMat(1.0f); //4x4 identity matrix (to be translation matrix)
transMat[3] = glm::vec4(-cameraPos, 1.0f); //Inverse of the world position of the camera
glm::mat4 finalMatrix = rotMat*transMat; //Multiply rotation and translation matrices together to get the view matrix.
Now the code is not what is important here but I displayed it to show the steps I do, it should be pretty self-explanatory with the comments. I understand everything except one thing; why do I have to use the negative result of my camera direction (the line of code commented with *******)? If I just use lookDir then I can't see my objects but if I use -lookDir I see my objects as expected. -lookDir was used in a tutorial which most of this code was taken from but there is never an explanation for that choice.
I've seen countless of tutorials where they explain the theory of how a camera matrix is created and I've not seen one where they use -someCameraDirection instead of someCameraDirection.
So...I'm wondering if I am missing something out in the math involved here or if it's related to something else.