Object and Screen Space Rotation Demo

There are lots of questions popping up about how to make objects rotate in certain ways. When people first start programming in OpenGL they naturally try to implement viewing rotations by calling glRotate 3 times around the x, y, and z axes. This is what I did myself (and still do). This results in rotations that can seem unnatural. Depending on the order the rotations are called, objects no longer rotate around an axis that means something to the viewer (either screen axes or object axes). FWIW implementing rotations this way can be thought of as forced Euler Rotations (which I won’t go into). It is often the case that users want to rotate objects around the screen axes (x->right, y->up, z->out of the screen), or object axes (which rotate with the object). These are called ‘Screen’ and ‘Object’ space rotations. The advantage of either of these schemes is that objects always rotate around axes that are meaningful to the viewer. It is not necessary to implement your own rotation matrices or quaternions to do screen or object rotations. The example below does both of these types of rotations. Though the approach does not require much code, it is not intuitive. I would appreciate it if more experienced OpenGL coders could suggest better ways (faster, cleaner, more elegant) to do screen or object rotations.

MaxH - OpenGL Object and Screen Space Rotation Demo

The code I posted previously to demonstrate ways to set up object and screen space rotations ‘expired’ (whatever that means). An improved version is posted below …

Object & Screen Space Rotations

In this version, an illuminated teapot is rotated instead of a colored box.

The link has gone again could you repost or pm it to me or something, it would be very useful!

Sorry - my bad. Let’s try it again …

OpenGL Screen & Object Space Rotations

Thanks, that looks a lot easier than I thought from all the descriptions I’d read!

Could you please repost the code or pm it to me, all the pastebin links don’t work.

Looks like the pastebin link expired. I’m trying something new now. I’ve put the source code up for this demo at:

Object and Screen Space Rotation Demo

Let me know if you have any trouble.

Thank you. That link works.

I have also found this link, which has helped me out considerably:

http://www.songho.ca/opengl/gl_transform.html