title: Glm Quaternion lookat function
body: <p>I am trying to write a lookat function that uses glm::quat to represent rotations, based of off this <a href="https://stackoverflow.com/a/17654730/771790">answer</a>. I am running into trouble getting a correct angle however. This is my lookat function:</p>
  
  <pre><code>void Camera::LookAt(float x, float y, float z) {
      glm::vec3 lookVector = glm::vec3(x, y, z);
      assert(lookVector != position);
  
      glm::vec3 direction = glm::normalize(lookVector-position);
      float dot = glm::dot(glm::vec3(0, 0, -1), direction);
      if (fabs(dot - (-1.0f)) &lt; 0.000001f)
          rotation = glm::quat(RadiansToDegrees(M_PI), 0.0f, 1.0f, 0.0f);
      if (fabs(dot - (1.0f)) &lt; 0.000001f)
          rotation = glm::quat();
  
      float angle = RadiansToDegrees(acosf(dot));
  
      glm::vec3 cross = (glm::cross(glm::vec3(0, 0, -1), direction));
      rotation = glm::normalize(glm::angleAxis(angle, cross));
  
      std::cout &lt;&lt; glm::eulerAngles(rotation).x  &lt;&lt; " " &lt;&lt; glm::eulerAngles(rotation).y &lt;&lt; " " &lt;&lt; glm::eulerAngles(rotation).z &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>When I call LookAt(0.0f, 0.0f, 0.0f) when my camera is at (0.0f, 0.0f, -10.0f), this outputs a correct rotation of 0,0,0. However if I translate my camera to (0.0f, -0.01f, -10.0f) or more I get a rotation of about 124,0,0. This goes down if I continue to translate y by -0.01f. If I do not normalize the quaternion I do not get this problem. The rotation is still 124 about the x axis, but the appearance is fine. If however I normalize the quaternion later it once again appears to rotate to about 124. I can not normalize <code>cross</code>, because doing so throws an assert. What would cause me to get euler angles of 124 about x from my lookat function, and how can I fix it?</p>