Discussion:
Transformation matrices order
(too old to reply)
Cathy L.
2013-09-24 08:47:35 UTC
Permalink
Raw Message
Hello

I am switching from the old OpenGL (with glTranslate, glRotate,
glBegin/End, etc...) to the new (3.3) method calculating my own matrices
(with the help of GLM), so I work on matrices order for
projection/view/model.

I understand that it is done this way:

Mmodelview=Mview * Mmodel

M=Mprojection * Mmodelview

with often Mviewmodel this order:

Mviewmodel=Mtranslation * Mrotation * Mscale

I decided to check if that is really done this way, so I made several
transformations with the old method and check with
glGetFloatv(GL_MODELVIEW_MATRIX,&fMatrix); at each step.

The problem is that if I:

glLoadIdentity();
glRotatef(45,0,1,0); // let's call it Mry
glRotatef(10,1,0,0); // Mrx
glGetFloatv(GL_MODELVIEW_MATRIX,&fMatrix);

the result in fMatrix is like fMatrix was Mry * Mrx. So the old OpenGL
is multiplying to the right the new matrix?

Thanks for the help
Cathy L.
Andy V
2013-09-25 01:21:54 UTC
Permalink
Raw Message
Post by Cathy L.
I am switching from the old OpenGL (with glTranslate, glRotate,
glBegin/End, etc...) to the new (3.3) method calculating my own matrices
(with the help of GLM), so I work on matrices order for
projection/view/model.
Mmodelview=Mview * Mmodel
Yes. For incoming vertices, you want to apply the model transform before the view transform. The basic transformation of a vertex is:

v' = Mmodelview * v

which is also:

v' = Mview * Mmodel * v
Post by Cathy L.
M=Mprojection * Mmodelview
Yes, apply model-view before projection
Post by Cathy L.
Mviewmodel=Mtranslation * Mrotation * Mscale
It's one possibility.
Post by Cathy L.
I decided to check if that is really done this way, so I made several
transformations with the old method and check with
glGetFloatv(GL_MODELVIEW_MATRIX,&fMatrix); at each step.
glLoadIdentity();
glRotatef(45,0,1,0); // let's call it Mry
glRotatef(10,1,0,0); // Mrx
Here you are saying that you want to apply Mrx before Mry -- the transform closer to the vertex is applied before the other.
Post by Cathy L.
glGetFloatv(GL_MODELVIEW_MATRIX,&fMatrix);
the result in fMatrix is like fMatrix was Mry * Mrx. So the old OpenGL
is multiplying to the right the new matrix?
Right. I hope you now see why that is correct for OpenGL.
Cathy L.
2013-09-25 05:50:46 UTC
Permalink
Raw Message
Post by Andy V
Post by Cathy L.
the result in fMatrix is like fMatrix was Mry * Mrx. So the old OpenGL
is multiplying to the right the new matrix?
Right. I hope you now see why that is correct for OpenGL.
Yes I see why: we have to give transformation from the last to the
first. I was thinking the reverse way.
Thanks Andy.

Loading...