jkj2000

03-15-2009, 05:35 PM

Hi everyone,

I'm working with a 3rd party modeling library that defines some data structures within the model file. One of these is a "pivot" value, a 3D vector.

Someone who worked on a project before me had this code in his initialization routine, and I can't make sense of it. Could someone help me understand what it's doing?

glPushMatrix();

glLoadIdentity();

ObjectData *d = &model->data.object;

glMultMatrixf(&model->matrix[0][0]);

glTranslatef(-d->pivot[0], -d->pivot[1], -d->pivot[2]);

matrix_copy(M, model->matrix);

matrix_invert(M);

glMultMatrixf(&M[0][0]);

glGetFloatv(GL_MODELVIEW_MATRIX, another_matrix);

glPopMatrix();

Don't worry too much about the data structures listed. They're confusing, I know and I apologize for it.

What I'm really interested in knowing is what is going on there with the glMultMatrix calls sandwiching a glTranslate like that?

Here's what's happening as best as I can tell. (Correct me if I'm wrong.) The original author starts by setting the 3D object's internal matrix as the modelview, then translates the 3D object's "pivot" point to the origin. Then, he inverts the modelview matrix and multiplies that to the existing modelview matrix and saves it in the variable "another_matrix".

That's the step by step. What I don't understand is the purpose behind it-- is he trying to...well, I don't know what he's trying to do. If you have an explanation what the purpose of all that might be I'd be grateful. Thanks so much.

I'm working with a 3rd party modeling library that defines some data structures within the model file. One of these is a "pivot" value, a 3D vector.

Someone who worked on a project before me had this code in his initialization routine, and I can't make sense of it. Could someone help me understand what it's doing?

glPushMatrix();

glLoadIdentity();

ObjectData *d = &model->data.object;

glMultMatrixf(&model->matrix[0][0]);

glTranslatef(-d->pivot[0], -d->pivot[1], -d->pivot[2]);

matrix_copy(M, model->matrix);

matrix_invert(M);

glMultMatrixf(&M[0][0]);

glGetFloatv(GL_MODELVIEW_MATRIX, another_matrix);

glPopMatrix();

Don't worry too much about the data structures listed. They're confusing, I know and I apologize for it.

What I'm really interested in knowing is what is going on there with the glMultMatrix calls sandwiching a glTranslate like that?

Here's what's happening as best as I can tell. (Correct me if I'm wrong.) The original author starts by setting the 3D object's internal matrix as the modelview, then translates the 3D object's "pivot" point to the origin. Then, he inverts the modelview matrix and multiplies that to the existing modelview matrix and saves it in the variable "another_matrix".

That's the step by step. What I don't understand is the purpose behind it-- is he trying to...well, I don't know what he's trying to do. If you have an explanation what the purpose of all that might be I'd be grateful. Thanks so much.