A
A
Anthony2283572021-02-28 15:28:15
C++ / C#
Anthony228357, 2021-02-28 15:28:15

How to correctly implement lookat function for camera in opengl using quaterions?

How to implement a camera function to look at a point using quaternions using the glm library? Right now I have the following implementation:

glm::vec3 front = point - Position;
  if (front == vec3(0.0f, 0.0f, 0.0f))
  {
    this->rotation = vec3(0.0f,0.0f,0.0f);//euler rotation
    updateCameraVectors();
  }
  else {
    front = glm::normalize(front);
    quat orient = quatLookAt(front, vec3(0.0f,1.0f,0.0f)); // quaterion rotation
    vec3 rot = (glm::eulerAngles(orient) * 3.14159f / 180.f); //euler rotation
    this->rotation = vec3(glm::degrees(rot.x), glm::degrees(rot.y), glm::degrees(rot.z));
    updateCameraVectors();

Logically, everything is correct, but for some reason the angles are always small and wrong. What is the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question