title: OpenGL weird rotation result with mouse
body: <p>So I'm working on a 3d painting application. I managed to make a basic renderer and model loader.</p>
  <p>I created a camera system where I can use it to navigate around the scene(mouse/keyboard) but that's not what I want, so I made that camera static and now I'm <strong>trying to rotate/pan/zoom the model itself</strong>. I <em>managed to implement panning and zooming</em>. for panning i change the x/y position according to the mouse and for zooming I add or substract from the z-axis according to the mouse scroll.</p>
  <p>But now I want to be able to <strong>rotate the 3d model with the mouse</strong>. Example: When i hold right mouse button and move the mouse up the model should rotate on it's <em>x-axis(pitch)</em> and if i move the mouse to the left/right it should rotate on <em>y-axis(yaw)</em>. And I just couldn't do it.</p>
  <p>The code bellow I get xpos/ypos of the cursor on the screen, calculate the offset and &quot;<em>trying to rotate the cube</em>&quot;. The only problem is that <strong>i can't rotate the cuber normally if i move the mouse up the model rotate on the x-axis and y-axis with a little tilt and vice-versa.</strong></p>
  <p>This is the code in my rendering loop:</p>
  <pre><code>    shader.use();
      glm::mat4 projection = glm::perspective(glm::radians(45.0f), 
      (float)SCR_WIDTH/(float)SCR_HEIGHT, 0.01f, 100.0f);
      shader.setMat4f(&quot;projection&quot;, projection);
  
      glm::mat4 view = camera.getViewMatrix();
      shader.setMat4f(&quot;view&quot;, view);
  
      glm::mat4 modelm = glm::mat4(1.0f);
      modelm = glm::translate(modelm, object_translation);
      // Should rotate cube according to mouse movement
      //modelm = glm::rotate(modelm, glm::radians(angle), glm::vec3(0.0f));
      shader.setMat4f(&quot;model&quot;, modelm);
  
      renderer.draw(model, shader);
  </code></pre>
  <p>This is the call where i handle the mouse movement callback:</p>
  <pre><code>void mouseCallback(GLFWwindow* window, double xpos, double ypos)
  {
  if (is_rotating)
  {
      if (is_first_mouse)
      {
          lastX = xpos;
          lastY = ypos;
          is_first_mouse = false;
      }
  
      // xpos and ypos are the cursor coords i get those with the 
      mouse_callback
      double xoffset = xpos - lastX;
      double yoffset = lastY - ypos;
  
      lastX = xpos;
      lastY = ypos;
  
      object_rotation.y += xoffset; // If i use yoffset the rotation flips
      object_rotation.x += yoffset;
  
      rotation_angle += (xoffset + yoffset) * 0.25f;
  }
  }
  </code></pre>
  <p>Mouse panning works fine too can't say the same for the rotation.</p>