title: Qt OpenGL - Rotation with mouse drag - negative delta
body: <p>I have a GLWdiget subclass of QGLWidget where I would like to make rotate a 3D object  along Ox and Oy axes. </p>
  
  <p>For this, I have reimplemented <code>mousePressEvent</code> and <code>mouseMoveEvent</code> functions this way :</p>
  
  <pre><code>void GLWidget::mousePressEvent(QMouseEvent *event)
  {
   lastPos = event-&gt;pos();
  }
  
  void GLWidget::mouseMoveEvent(QMouseEvent *event)
  {
    float dx = (event-&gt;x() - lastPos.x()) / 10.0f;
    float dy = (event-&gt;y() - lastPos.y())/ 10.0f;
  
   if (event-&gt;buttons() &amp; Qt::LeftButton) 
     {
     glRotatef(dy*0.1, 1.0f, 0.0f, 0.0f);
     glRotatef(dx*0.1, 0.0f, 1.0f, 0.0f);
     }
  }
  </code></pre>
  
  <p>My problem is that <code>dx</code> and <code>dy</code> are never negative so whatever the direction I do with the mouse, it is always rotating in the same direction.</p>
  
  <p>For example, If I drag horizontally to the right, I want the object to rotate along 0y axes with a positive angle, and If I drag horizontally to the left, with a negative angle.</p>
  
  <p>This would be the same for vertical dragging but the rotation would be along Ox axes.</p>
  
  <p>Is this issue coming from global coordinates ? However, <code>event-&gt;x</code> and <code>event-&gt;y</code> give positions relative to the GLWidget.</p>