OpenGL matrix calculations

Started by
3 comments, last by blizzard999 18 years, 8 months ago
Im trying to simulate the way OpenGL handles matrices, namely how at every transformation, the axis are always aligned with the way you are facing (ie. -z is front, +x is right, +y is up). How is this done? I tried using matrices with euler angles, but then i realized that that always rotates around the global axis. So how does OpenGL do its rotations? Does it actually rotate the axis at every rotation, and then use quaternions? Or is there a simpler way? Thanks. edit: hmmm.. after a little more research, it seems that this is exactly euler angles. So then, my implementation of it is somehow wrong. Currently, im taking the rotational matrices and multiplying them together. But it seems that this isnt correct. So what is the correct way to implement euler angles? Thanks. edit2: just to clarify, what im trying to do is so that rotating the point (0,0,-1) 45 degrees about the y axis, and then 45 degrees about the x axis, should result in (-0.5,0.5,-0.5). My current implementation gives me (-0.707,0.5,-0.5). [Edited by - HalcyonX on August 7, 2005 3:16:28 AM]
Advertisement
The OpenGL spec should contain the infomation required, see OpenGL.org for details.
hmmm... i checked out the opengl2.0 spec, and it seems like they're just multiplying the rotation matrices together too. Shouldnt that make it rotate around the global axes then? But how come their glRotate() function works like yaw/pitch/roll?
It does rotate around the axes. But because of how matrix multiplication happens to work, if you call glTranslate, then glRotate, the rotation actually occurs first. So the object will be rotated as if it were at 0,0,0 and _then_ translated to where you specify. Reverse the order of the calls and you'll see it rotate around the axes instead of acting like yaw/pitch/roll.
If you want to seriously handle matrix multiplications see Matrix and Quaternion faqs (remember that the code use the standard notation, GL uses the transposed one!)

See also the OpenGL specifications to see how to handle projection and perspective matrices

This topic is closed to new replies.

Advertisement