Skip to main content
GameDev.net gamedev.net
🔒 Locked

understanding glMultmatrix

Started by sapdev May 23, 2009 at 12:54 AM 7 replies 2.1k views
Original Post
sapdev
sapdev
The Case : Let there be a matrix m[16], It contains some data, some custom transformations. Now we multiply this matrix to the ModelView Matrix (which is set as the current matrix ) by glMultMatrix(m); Now The Question: In which order the matrix is multiplied ? M = modelview matrix m = custom matrix. M * m or m * M Please reply . . . . .
------------------------------------------------------------------------------------------------------------------------------------------sapdev"A Ship is always safe at the shore - but that is NOT what it is built for" - Albert Einsteinhttp://saptarshi.devnath.googlepages.com/
inferno82
inferno82
If I remember correctly it will be

modelview_matrix *= custom_matrix

- me
sapdev
sapdev
Thanks . . . . . . :)
------------------------------------------------------------------------------------------------------------------------------------------sapdev"A Ship is always safe at the shore - but that is NOT what it is built for" - Albert Einsteinhttp://saptarshi.devnath.googlepages.com/
sapdev
sapdev
I got one more question . . . .


consider the pseudo code below :-

glPushMatrix();glLoadIdentity();gluLookAt();glTranslate();gRotate();glScale();/////////////glBegin(GL_TRIANGLES)**********glEnd();/////////////glPopMatrix();


In this particular case in what order is the original modelview matrix is multiplied.

is it ?

m * s * r * t * g

m = old modelview matrix
s = scaling matrix
r = rotation matrix
t = translation matrix
g = gluLookAt Matrix or camera martix
------------------------------------------------------------------------------------------------------------------------------------------sapdev"A Ship is always safe at the shore - but that is NOT what it is built for" - Albert Einsteinhttp://saptarshi.devnath.googlepages.com/
Brother Bob
Brother Bob
As inferno82 said, new matrices are multiplied in from the right hand side. Think about your code and answer for a second.

What does the matrix look like after the call to glLoadIdentity? It completely resets the matrix so you have a new fresh identity matrix. Then you multiply g in from the right, what is the current matrix? Now, from that current matrix, if you multiply t in from the right, what is the current matrix? Keep going like that.
sapdev
sapdev
Ok got it . . .

m * g * t * r * s.


But there is a concept (I got over the internet) like the last transformation is applied first. So this two are opposite to each other, Can you please explain that.

Sorry if this has been answered already, but I am really new in this field and am really confused.

------------------------------------------------------------------------------------------------------------------------------------------sapdev"A Ship is always safe at the shore - but that is NOT what it is built for" - Albert Einsteinhttp://saptarshi.devnath.googlepages.com/
Brother Bob
Brother Bob
That is completely dependent on how you see transformations. They can be applied from last to first, or from first to last, depending on if you see transformations on the object locally or globally.
sapdev
sapdev
Hmmmm . . . .

Can you please explain it a bit more . . .

Do you mean that the global space / coordinate system and Object space / coordinate system . . . .

Thanks for the reply.
------------------------------------------------------------------------------------------------------------------------------------------sapdev"A Ship is always safe at the shore - but that is NOT what it is built for" - Albert Einsteinhttp://saptarshi.devnath.googlepages.com/
Brother Bob
Brother Bob
I mean transformations applied relative the global coordinate system or the local coordinate system. That is, should a rotation be about the global origin, or about the local origin? Should a translation be along the global axes, or the local axes? The global origin is in a fixed position and orientation, while the local origin moves and rotates along with the individual transformations applied. That difference will give for forward or backward interpretation of the transformation order.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.