# Computing camera front direction from Euler angles

I am new to OpenGL and Computer Graphics in general.

Lately I was learning how to model a camera, specifically how to model the rotation of camera. I was introduced to Euler angles for this purpose.

I got a rough idea about how to use Euler angles to model camera rotation from this post. Based on that, I wrote something like below:

GLfloat yaw, pitch;
...
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
/*
Here I am updating the yaw, and pitch values
based on mouse movement and previous mouse position
*/

glm::mat4 yawPitchRotMat;
/* We want to do yaw * pitch. */

//y-axis as yaw axis
glm::vec3(0.0f, 1.0f, 0.0f));

//x-axis as pitch axis
glm::vec3(1.0f, 0.0f, 0.0f));

cameraFrontDirection = glm::normalize(-1.0f *
glm::vec3(yawPitchRotMat[2].x, yawPitchRotMat[2].y, yawPitchRotMat[2].z));
}


The above code seems to work. However, I would like to hear your opinion about this approach. Specially as my math is not really very strong, so any mathematical insight regarding Euler angles would be very helpful. Also appreciate any reference to online resource on the same, that is easy to understand.

Note: Though later I also came to know about certain limitation of modelling rotation using Euler angles and use quaternions instead. However I would like to save that topic for future discussion, as I am yet to read about that in details.

• Looks fine to me. Is anything not working as it should, or do you have any specific questions about the code or Euler angles? Asking for "your opinion about this approach" is very vague and will probably lead to questions like this being closed on this site. Apr 10, 2016 at 19:45
• Thanks @NathanReed for your reply and reviewing my code. You were right about the 'open endedness' of the question, thus, rephrased it. Apr 10, 2016 at 20:40
• Meta discussion about review questions. Apr 11, 2016 at 7:04