PDA

View Full Version : Object and Screen Space Rotation Demo



MaxH
04-20-2009, 10:59 AM
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 (http://pastebin.com/d625e7bf4)

MaxH
04-23-2009, 10:41 AM
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 (http://pastebin.com/f27c757b2)

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

chemicaloli
04-30-2009, 02:32 PM
The link has gone again could you repost or pm it to me or something, it would be very useful!

MaxH
04-30-2009, 09:39 PM
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 (http://pastebin.com/m451cf249)

chemicaloli
05-01-2009, 02:10 AM
Thanks, that looks a lot easier than I thought from all the descriptions I'd read!

codan3
06-03-2009, 11:01 AM
Could you please repost the code or pm it to me, all the pastebin links don't work.

MaxH
06-03-2009, 04:49 PM
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 (http://www.mfwweb.com/OpenGL/Special_Rotations/)

Let me know if you have any trouble.

codan3
06-03-2009, 05:03 PM
Thank you. That link works.

codan3
06-03-2009, 05:04 PM
I have also found this link, which has helped me out considerably:

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