Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does glRotate in OpenGL rotate the camera or rotate the world axis or rotate the model object?

Tags:

c

opengl

I want to know whether glRotate rotates the camera, the world axis, or the object. Explain how they are different with examples.

like image 448
topcoder Avatar asked Mar 20 '12 17:03

topcoder


2 Answers

the camera

There is no camera in OpenGL.

the world axis

There is no world in OpenGL.

or the object.

There are no objects in OpenGL.

Confused?


OpenGL is a drawing system, that operates with points, lines and triangles. There is no concept of a scene or a world in OpenGL. All there is are vertices of which each has a set of attributes and there is the state of OpenGL which determines how vertices are turned into pixels.

The very first stage of this process is getting the vertex positions within the viewport. In the fixed function pipeline (i.e. without shaders), to get those, each vertex position if first multiplied with the so called "modelview" matrix, the intermediary result is used for lighting calculations and then multiplied with the "projection" matrix. After that clipping and then normalization into viewport coordinates are applied.

Those two matrices I mentioned save two purposes. The first one "modelview" is used to apply some transformation on the incoming vertices so that those end up in the desired spot relative to the origin. There is no difference in first moving geometry to some place in the world, and then moving the viewpoint within the world. Or keeping the viewpoint at the origin and move the whole world in the opposite. All this can be described by the modelview matrix.

The second one "projection" works together with the normalization process to behave like a kind of "lens", so to speak. With this you set the field of view (and a few other parameters, like shift, which you need for certain applications – don't worry about it).

The interesting thing about matrices is, that they're non-commutative, i.e. for two given matrices N, M

M * N =/= N * M ; for most M, N

This ultimately means, that you can compose a series of transformations A, B, C, D... into one single compound transformation matrix T by multiplying the primitive transformations onto each other in the right order.

The OpenGL matrix manipulation functions (they're obsolete BTW), do just that. You have a matrix selected for manipulation (the matrix mode) for example the modelview M. Then glRotate effectively does this:

M *= R(angle,axis)

i.e. the active matrix gets multiplied on a rotation matrix constructed from the given parameters. Similar for scale and translate.

If this happens to appear to behave like a camera or placing a object depends entirely on how and in which order those manipulations are combined.

But for OpenGL there are just numbers/vectors (vertex attributes), which somehow translate into 2-dimensional viewport coordinates, that get drawn as points for filled inbetween as line or a triangle.

like image 161
datenwolf Avatar answered Oct 10 '22 14:10

datenwolf


glRotate works on the current matrix. So it depend if the matrix is the camera one or a world trasformation one. To know more about the current matrix have a look at glMatrixMode(). Finding example is just googling: I found this one that in order to me should help you to figure out what's happening.

like image 29
Felice Pollano Avatar answered Oct 10 '22 13:10

Felice Pollano