PDA

View Full Version : What is this transformation doing?



jkj2000
11-11-2007, 04:47 PM
I'm looking at a code snippet and I can't understand what the point of the series of transformations is. Could someone help me?

libMatrix M;
libMatrix FinalMatrix;

glPushMatrix();
glLoadIdentity();

glMultMatrixf(node->matrix[0][0]);
glTranslatef(-(node->center->pivot[0]), -(node->center->pivot[1]), -(node->center->pivot[2]));

lib_Matrix_Copy(M, node->matrix); //make "M" the inverse
lib_Matrix_Inverse(M);

glMultMatrixf(&M[0][0]);
glGetFloatv(GL_MODELVIEW_MATRIX, FinalMatrix);
glPopMatrix();


FinalMatrix is then used in various transformations down the line.

I understand the individual steps involved but I can't put together the goal of this sequence. What's the point of transforming the modelview matrix, then translating to the center of the object, then applying the inverse of the original matrix? When would you do this?

Relic
11-12-2007, 05:41 AM
What's the point of transforming the modelview matrix, then translating to the center of the object, then applying the inverse of the original matrix? When would you do this?
You misunderstood the sequence in which these transformations are applied to a vector in OpenGL, where vectors are columns and matrices are left-multiplied.
In a sequence of matrix manipulations the one standing nearest to the vector in the code is done first, that is you need to read the matrix code upwards. (Am I in a film here? Reading Matrix code, ha! :))
And then your sequence does v' = M * T * M^1 * v;
which is transform v from node's coordinates to object coordinates, then translate in object coordinates and move it back to node-coordinates.
(If you think of the node->matrix as the modelview matrix, you can replace "node" with "eye" in above sentence.)

Zengar
11-12-2007, 05:46 AM
But it's a really ineffective way of doing that o_O

jkj2000
11-12-2007, 02:22 PM
Thanks for the reply and clarification. I still have a question about the translation in object coordinates?

When I go from modelview coordinates to object coordinates then translate, and then move back to modelview coordinates, as outlined in the transformation, how will that affect the verticies drawn; will the object be moved over a little in the final rendering, by the amount of (and in the direction of) the translation? Thanks again for your help.

Relic
11-14-2007, 05:06 AM
That solely depends on what's in node->matrix.
Let's say it's the identity matrix, then the translation is exactly the same in both coordinate systems.
But imagine there is a rotation inside (most likely for any hierarchy of matrices, like in a skeleton or something) then translating along e.g. one of the basis axes in object coordinates means translating in a totally different (rotated) direction in the node coordinate system.
Or if there is scaling involved (which is generally not a good idea) then the translation is also scaled.