0
votes

I am using opengl 2.0 with the fixed function pipeline. It seems that in opengl 2.0 they push the vertices through the model-view stack which is basically (view matrix * model matrix), in which the model matrix doesn't provide any transformation really it brings an object say a cube to be centered at (0,0,0) if the model view matrix has a identity matrix loaded.Also the camera it self would be located at (0,0,0) looking down the negative z axis.

So if I use a translate call with the cube I am I really moving the cube in Eye space ?

From what I learned the generalized viewing pipeline is

Vertices -> Modelling Matrix -> World Space, Objects in World Space -> Viewing Matrix -> Eye Space, Eye Space Objects -> Projection Matrix -> Clipping Space , Then normalization ect

So If I switch to the model view matrix stack() loadidentity () gltranslate ( up 5 units in the negative z direction) gldrawcube()

it would move the cube from center of the eye space according to the translation ?

I think my confusion is that I don't know what is loaded into the model view matrix stack when the program starts, I assume it is an identity matrix that brings everything to the centre of the eye space.

1

1 Answers

2
votes

In a newly created OpenGL context all matrices are identity, i.e. vectors go through untransformed. In fixed function OpenGL vertex transformation skips the "world" step, collapsing object→world and world→eye into a single transformation. This is no big deal however. Lighting calculations are easiest in eye space anyway. And since fixed function OpenGL doesn't know shaders (except as extension), there's no need to do things in world space.

glTranslate, glRotate, glScale don't transform objects. They manipulate the matrix on top of the stack active for manipulation. So ultimately they contribute to the transformation, but not on the object, but the vertex (position) level.

it would move the cube from center of the eye space according to the translation?

Indeed, but what's "moved" (actually transformed) are the cube's vertices; and it may be not just a translation.

EDIT due to comment

The key thing to understand is transformation composition. First and foremost a transformation is a mapping

T: R^4 -> R^4, v' = v |-> T(v)

There's a subset of transformation, namely the linear transformations which can be represented by matrix multiplication:

v' = T * v

one can concatenate transformations, i.e. v = v |-> T'○T (v) again for the subset of linear transformations, written in matrix form you can expand this to

v' = T * v
v'' = T' * v'

=>

v'' = T' * T * v

Now let V denote the viewing transform and W the world transform. So the total transform is

M = V * W

The order of matrix multiplication matters (i.e. matrix multiplication is not commutative):

∃ M, N ∊ {Matrices}: M * N ≠ N * M

The view transform V is the transform of the whole world so that it is moved in a way, that the camera in the world ends up being at the origin, viewing down the negative Z axis. So let V' be the transform that moves "the camera" from the origin at it's place in the world, the inverse of that movement moves the world in a way that the camera comes to rest at the origin. So

V = inv(V')

Last but not least given some matrices A, B, C for which holds

A = B * C

then

inv(A) = inv(C) * inv(B)

i.e. the order of operations reversed. So if you "position" your "camera" using inverse OpenGL matrix operations, the order of the operations must be reversed. And since the overall order of operation matters the viewing transformations must happen before the model transformations.