title: Rotating a Open GL camera correctly using GLM
body: <p>I have a camera class, which is initialized like so: </p>
  
  <pre><code>CameraFP::CameraFP()  {
      this-&gt;aspect_ratio = 800.0f / 600.0f;
      this-&gt;fov = 45.0f;
      this-&gt;near_plane = 0.1f;
      this-&gt;far_plane = 1000.0f;
      this-&gt;position = glm::vec3(0, 0, 0);
      this-&gt;target = position + glm::vec3(0, 0, -1);
      this-&gt;up = glm::vec3(0, 1, 0);
      this-&gt;m_rotation = glm::mat4(1.0);
  
      m_view = glm::lookAt(position, target, up);
      m_projection = glm::perspective(fov, aspect_ratio, near_plane, far_plane);
  }
  </code></pre>
  
  <p>And here are other functions of import:</p>
  
  <pre><code>void CameraFP::update(sf::Window *app)  {
      process_keyboard(app);
      process_mouse(app);
  
      calculate_view();
  }
  
  void CameraFP::process_keyboard(sf::Window *app)  {
      const sf::Input *input = &amp;app-&gt;GetInput();
  
      up = m_rotation * glm::vec3(0, 1, 0);
  
      glm::vec3 forward = glm::vec3(0, 0, -1);
      glm::vec3 forward_rotated = m_rotation * forward;
  
      glm::vec3 right = glm::vec3(1, 0, 0);
      glm::vec3 right_rotated = m_rotation * right;
  
      if (input-&gt;IsKeyDown(sf::Key::W))  {
          position += forward_rotated;
      }
      if (input-&gt;IsKeyDown(sf::Key::S))  {
          position -= forward_rotated;
      }
      if (input-&gt;IsKeyDown(sf::Key::A))  {
          position -= right_rotated;
      }
      if (input-&gt;IsKeyDown(sf::Key::D))  {
          position += right_rotated;
      }
  }
  
  void CameraFP::process_mouse(sf::Window *app)  {
      // TODO: Make the below constants, and take framerate into account
      GLfloat SPEED_X = 0.000001f;
      GLfloat SPEED_Y = 0.000001f;
  
      GLfloat mouse_x = app-&gt;GetInput().GetMouseX();
      GLfloat mouse_y = app-&gt;GetInput().GetMouseY();
  
      GLfloat mouse_x_delta = old_mouse_x - mouse_x;
      GLfloat mouse_y_delta = old_mouse_y - mouse_y;
  
      if (mouse_x_delta != 0 ||
          mouse_y_delta != 0)  {
          if (mouse_x_delta != 0)  {
              y_rot += mouse_x_delta * SPEED_X;
  
              m_rotation = glm::rotate(m_rotation, y_rot, glm::vec3(0, 1, 0));
          }
          if (mouse_y_delta != 0)  {
              x_rot += mouse_y_delta * SPEED_Y;
  
              m_rotation = glm::rotate(m_rotation, x_rot, glm::vec3(1, 0, 0));;
          }
      }
  
      this-&gt;old_mouse_x = mouse_x;
      this-&gt;old_mouse_y = mouse_y;
  
      app-&gt;SetCursorPosition(app-&gt;GetWidth() / 2, app-&gt;GetHeight() / 2);
  }
  
  
  void CameraFP::calculate_view()  {
      glm::vec3 forward = glm::vec3(0, 0, -1);
      glm::vec3 forward_rotated = m_rotation * forward;
  
      target = position += glm::normalize(forward_rotated);
  
      m_view = glm::lookAt(position, target, up);
  }
  </code></pre>
  
  <p>My problem is that when I compile the project, the compiler outputs an error saying:</p>
  
  <pre><code>\CameraFP.cpp|59|error: no match for 'operator*' in '((CameraFP*)this)-&gt;CameraFP::m_rotation * glm::detail::tvec3&lt;float&gt;(((const int&amp;)((const int*)(&amp;0))), ((const int&amp;)((const int*)(&amp;1))), ((const int&amp;)((const int*)(&amp;0))))'|
  </code></pre>
  
  <p>From what I understand vec = mat4 * vec should yield a rotated vector? Since I haven't been able to test this code, I don't know if the function work correctly.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Updated code according to the comments and awnsers. My problem is now that I get a BSOD, somewhere in the render function...</p>
  
  <pre><code>void CameraFP::process_keyboard(sf::Window *app)  {
      const sf::Input *input = &amp;app-&gt;GetInput();
  
      up = m_rotation * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f);
  
      glm::vec4 forward = glm::vec4(0.0f, 0.0f, -1.0f, 0.0f);
      glm::vec4 forward_rotated = m_rotation * forward;
  
      glm::vec4 right = glm::vec4(1.0f, 0.0f, 0.0f, 0.0f);
      glm::vec4 right_rotated = m_rotation * right;
  
      if (input-&gt;IsKeyDown(sf::Key::W))  {
          position += forward_rotated;
      }
      if (input-&gt;IsKeyDown(sf::Key::S))  {
          position -= forward_rotated;
      }
      if (input-&gt;IsKeyDown(sf::Key::A))  {
          position -= right_rotated;
      }
      if (input-&gt;IsKeyDown(sf::Key::D))  {
          position += right_rotated;
      }
  }
  
  void CameraFP::process_mouse(sf::Window *app)  {
      // TODO: Make the below constants, and take framerate into account
      GLfloat SPEED_X = 0.000001f;
      GLfloat SPEED_Y = 0.000001f;
  
      GLfloat mouse_x = app-&gt;GetInput().GetMouseX();
      GLfloat mouse_y = app-&gt;GetInput().GetMouseY();
  
      GLfloat mouse_x_delta = old_mouse_x - mouse_x;
      GLfloat mouse_y_delta = old_mouse_y - mouse_y;
  
      if (mouse_x_delta != 0 ||
          mouse_y_delta != 0)  {
          if (mouse_x_delta != 0)  {
              y_rot += mouse_x_delta * SPEED_X;
  
              m_rotation = glm::rotate(m_rotation, y_rot, glm::vec3(0.0f, 1.0f, 0.0f));
          }
          if (mouse_y_delta != 0)  {
              x_rot += mouse_y_delta * SPEED_Y;
  
              m_rotation = glm::rotate(m_rotation, x_rot, glm::vec3(1.0f, 0.0f, 0.0f));;
          }
      }
  
      this-&gt;old_mouse_x = mouse_x;
      this-&gt;old_mouse_y = mouse_y;
  
      app-&gt;SetCursorPosition(app-&gt;GetWidth() / 2, app-&gt;GetHeight() / 2);
  }
  
  void CameraFP::calculate_view()  {
      glm::vec4 forward = glm::vec4(0.0f, 0.0f, -1.0f, 0.0f);
      glm::vec4 forward_rotated = m_rotation * forward;
  
      target = position += forward_rotated;
  
      m_view = glm::lookAt(v4tov3(position), v4tov3(target), v4tov3(up));
  }
  
  glm::vec3 v4tov3(glm::vec4 v1)  {
      return glm::vec3(v1.x, v1.y, v1.z);
  }
  </code></pre>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Problem now is with the camera rotation with the mouse, it just doesn't work, for some reason changes on the x axis oft times effect change on the y and vice versa. In addition, if I move the mouse right or left on the x axis (y rotation) the camera rotates left...</p>
  
  <pre><code>void CameraFP::process_mouse(sf::Clock *clock, sf::Window *app)  {
      // TODO: Make the below constants, and take framerate into account
      GLfloat SPEED_X = 0.25f;
      GLfloat SPEED_Y = 0.25f;
  
      GLfloat screen_x = app-&gt;GetWidth();
      GLfloat screen_y = app-&gt;GetHeight();
  
      GLfloat mouse_x = float(screen_x / 2 - app-&gt;GetInput().GetMouseX());
      GLfloat mouse_y = float(screen_y / 2 - app-&gt;GetInput().GetMouseY());
  
      GLfloat mouse_x_delta = old_mouse_x - mouse_x;
      GLfloat mouse_y_delta = old_mouse_y - mouse_y;
  
      GLfloat current_time = clock-&gt;GetElapsedTime();
      GLfloat delta_time = current_time - last_time;
  
      this-&gt;last_time = current_time;
  
      if (mouse_x_delta != 0 ||
          mouse_y_delta != 0)  {
          if (mouse_x_delta != 0)  {
              y_rot += glm::radians(delta_time * SPEED_X * mouse_x);
  
              m_rotation = glm::rotate(m_rotation, y_rot, glm::vec3(0.0f, 1.0f, 0.0f));
  
              std::cout &lt;&lt; "Y Rotation: " &lt;&lt; y_rot &lt;&lt; "\n";
          }
          if (mouse_y_delta != 0)  {
              x_rot += glm::radians(delta_time * SPEED_Y * mouse_y);
  
              m_rotation = glm::rotate(m_rotation, x_rot, glm::vec3(1.0f, 0.0f, 0.0f));
  
              std::cout &lt;&lt; "X rotation: " &lt;&lt; x_rot &lt;&lt; "\n";
          }
      }
  
      app-&gt;SetCursorPosition(screen_x / 2, screen_y / 2);
  
      this-&gt;old_mouse_x = float(screen_x / 2 - app-&gt;GetInput().GetMouseX());
      this-&gt;old_mouse_y = float(screen_y / 2 - app-&gt;GetInput().GetMouseY());
  }
  </code></pre>