View Full Version : glRotate() For View Rotation - Newbie Question
08-30-2005, 11:21 AM
How is it that I can use glRotate() to rotate both my view and individual objects with the same syntax? Is the command context sensetive?
08-30-2005, 11:42 AM
Because it modifies your transformation matrix which is then used to rotate your object.
If you call glRotate before any objects all objects rendered afterward are rotated.
If you save the xform matrix (glPushMatrix), then perform your rotate and render your object, then restore the xform matrix (glPopMatrix) you've essentially only rendered your object with the modified xform matrix. So, only that one object is rendered with that modified xform matrix.
hope that made some sense.
08-30-2005, 04:58 PM
I still don't understand how the code knows to rotate around the origin with the first glRotate but then rotate a primative with the same syntax right after that:
glRotatef(45, 0.0f, 1.0f, 1.0f);
glRotatef(30, 0.0f, 1.0f, 0.0f);
glEnd();Shouldn't the second glRotatef() rotate the world around the origin on the Y axis another 30 degrees?
08-30-2005, 10:53 PM
OpenGL itself doesn't know about cameras. It simply stores a transformation and applies it to every vertex.
You think of a camera transformation simply as applying the inverse transformation to every object. Ie moving your camera back along the z axis is the same as moving every object the same distance forth the z axis.
So you can either interpret your code snippet as "rotate camera -45 degrees (negative sign!) around <0, 1, 1>, then rotate objects 30 degrees around <0, 1, 0>", or as "rotate objects 45 degrees (positive sign!) around <0, 1, 1>, then another 30 degrees around <0, 1, 0>". But you have to remember that transformations affect following transformations. So the second rotate does not use the original y axis, but the y axis that results from the first rotate call.
08-31-2005, 10:47 AM
I guess that makes sense. So we cannot move a view as much as move the world around the view to simulate a camera?
So we cannot move a view as much as move the world around the view to simulate a camera?From each world-space vertex position the camera's world-space origin is subtracted. The resulting vector is dotted into the camera's 3 world-space axes. The result is the camera-space vertex position.
However you choose to view this or whatever you choose to call it is up to you. If you want to call this construct a camera, then so be it :)
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.