# Why do I need to inverse the orientation matrix of a camera to be able to translate it in the direction it is facing?

I've been going over some OpenGL learning resources and one of them is this article: Modern OpenGL 04 - Cameras, Vectors & Input in which the author presents an approach to building a Camera class that can be used to derive the view and projection matrices.

In the accompanying source code there is a function that returns the orientation of the camera as a transform matrix (permalink to source code) which is implemented like this:

glm::mat4 Camera::orientation() const {
glm::mat4 orientation;
return orientation;
}


If I'd like to translate the camera relative to the direction it is facing then I would assume that I could multiply the orientation matrix by the translation vector to get a new vector that does the translation in the direction the camera is facing.

However, this does not yield the result I was expecting. After looking at how the forward, up and right axis are derived (permalink to source code):

glm::vec3 Camera::forward() const {
glm::vec4 forward = glm::inverse(orientation()) * glm::vec4(0,0,-1,1);
return glm::vec3(forward);
}

glm::vec3 Camera::right() const {
glm::vec4 right = glm::inverse(orientation()) * glm::vec4(1,0,0,1);
return glm::vec3(right);
}

glm::vec3 Camera::up() const {
glm::vec4 up = glm::inverse(orientation()) * glm::vec4(0,1,0,1);
return glm::vec3(up);
}


I can see that I need to multiply the translation vector with the inverse of the orientation matrix to get the expected result but I don't understand why. Isn't the orientation (as used in this article) a rotation matrix? If that's the case then why do I need to inverse it?

• I guess the author actually computes inverse orientation in orientation because he calls this orientation in Camera::view and then Camera::matrix without transpose or inversion of it. And because glfwGetCursorPos will give you flipped Y coordinates, the orientation does compute the inverse of orientation coincidentally. However X coordinates are not flipped, which should cause problem but I cannot explain why it does not. – TheBusyTypist Sep 5 '17 at 17:02

People always forget that there is no "camera" in OpenGL. In order to simulate a camera you have to move the whole world inversely. So if you want ur camera looking 30 degrees downward, you move the whole world 30 degrees upwards. If you want your camera moved to the left, you move the whole world right. That's why you will notice the "-" sign in the translation vector where he used the variable position.