title: Android OpenGL Rotate cube in the direction of touch movement
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/11207805/visually-correct-rotation-with-opengl-and-touch-screen-capabilities">Visually correct rotation with OpenGl and touch screen capabilities</a>  </p>
  </blockquote>
  
  
  
  <p>I have a cube which I want to rotate in the same direction I am moving my finger while touching. I do know how to get current touch movement and use those values to rotate the cube, but that's not what I want. </p>
  
  <p>This is what I am currently using:</p>
  
  <pre><code>    case MotionEvent.ACTION_DOWN:
          mx = me.getX();
          my = me.getY();
          break;
      case MotionEvent.ACTION_MOVE:
          x_diff = mx - me.getX();
          y_diff = my - me.getY();
          mx = me.getX();
          my = me.getY();
          this.rot_x -= y_diff;
          this.rot_y -= x_diff;
          break;
  </code></pre>
  
  <p>Rotation:</p>
  
  <pre><code>gl.glRotatef(rot_x, 1, 0, 0);
  gl.glRotatef(rot_y, 0, 1, 0);
  gl.glRotatef(rot_z, 0, 0, 1);
  </code></pre>