Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: What does glRotatef rotate?

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.

like image 526
sanjeev mk Avatar asked Aug 13 '14 18:08

sanjeev mk


People also ask

How many parameters are the in glRotatef () function?

I understand that glRotatef takes 4 parameters; angle, x, y, z.

How do I rotate an object in OpenGL?

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.


2 Answers

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".

like image 121
Sneftel Avatar answered Oct 15 '22 00:10

Sneftel


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.

  1. open.gl
  2. opengl-tutorial.org
  3. ogldev
like image 35
glampert Avatar answered Oct 15 '22 02:10

glampert