Rotating in OpenGL relative to the viewport

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-05-03T13:51:54Z Indexed on 2010/05/03 13:58 UTC
Read the original article Hit count: 228

Filed under:
|

I'm trying to display an object in the view which can be rotated naturally by dragging the cursor/touchscreen. At the moment I've got X and Y rotation of an object like this

glRotatef(rotateX, 0f, 1f, 0f); // Dragging along X, so spin around Y axis
glRotatef(rotateY, 1f, 0f, 0f);

I understand why this doesn't do what I want it to do (e.g. if you spin it right 180 degrees, up and down spinning gets reversed). I just can't figure out a way for both directions to stay left-right and up-down relative to the viewer.

I can assume that the camera is fixed and looking along the Z axis. Any ideas?

© Stack Overflow or respective owner

Related posts about opengl

Related posts about rotation