When I call the glRotatef
like this:
glRotatef(angle,0.0,1.0,0.0) //rotate about y-axis
I know it is to rotate by angle
degrees about the y axis
.
But, what is being rotated here? Which object exactly?
Probably a silly question, but I'm entirely new to this.
I was able to rotate a line about it's endpoint using the answer here , but I don't really understand how it works internally.
I understand that glRotatef takes 4 parameters; angle, x, y, z.
To rotate around a different point, the formula: X = cx + (x-cx)*cosA - (y-cy)*sinA, Y = cy + (x-cx)*sinA + (y-cy)*cosA, cx, cy is centre coordinates, A is the angle of rotation. The OpenGL function is glRotatef (A, x, y, z). 3. Scaling: Scaling refers to zooming in and out an object on different scales across axes.
Nothing is being rotated, because OpenGL does not "store" objects.
glRotatef, like glMultMatrixf, is used to modify the currently selected transformation matrix. This has an effect on how things are drawn subsequently. One sets the matrices (and other stuff!) how one wants, and then one draws one's objects.
For more information, see the OpenGL redbook, and google around for the difference between "retained mode" and "immediate mode".
glRotate
will act on the current matrix, which is by default GL_MODELVIEW
. Doing so will affect any 3D object that you draw in the sequence. The current matrix is changed with glMatrixMode
.
The model-view matrix is then applied to any geometry rendered with glVertex
, glDrawArrays
, etc.
OpenGL-side matrices are now deprecated. If you use core OpenGL 3+, these functions are no longer available. If you are new to OpenGL, I suggest that you skip learning the old ways and focus on modern, shader-oriented OpenGL. You can check the following links for some good tutorials.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With