View Full Version : Inverse Modelview

Keldon

12-19-2003, 09:37 PM

I tried to calculate the inverse Modelview, but what is gl_ModelViewMatrix ? It is definitively not the same like glGetFloatv(GL_MODELVIEW_MATRIX,m). (of course I don't do anymore transformations after I call glGetFloat)

OpenGL seems to make an additional transformation before sending it to the Shader. What is this transformation ?

[This message has been edited by Keldon (edited 12-19-2003).]

fuxiulian

12-20-2003, 12:29 AM

The one returned by glGetFloatv is in column major order, meaning that the matrix is:

a[0] a[4] a[8] a[12]

a[1] a[5] a[9] a[13]

a[2] a[6] a[10]a[14]

a[3] a[7] a[11]a[15]

gl_ModelViewMatrix may be in row major order.

In that case you'll just have to transpose it to get what you were used to get with glGetFloatv

mchristen

12-20-2003, 12:44 AM

Don't forget to update your modelview matrix uniform everytime inside a glPushMatrix() / glPopMatrix().

For example, you can't use glutSolidTeapot or other predefined Objects which use push/pop inside. I wrote a little program using inverse modelview/modelviewprojection and it works fine now. I will upload it to my site tonight.

I really wish gl_ModelViewMatrixInverse would be part of the standard...

--Martin

azazello

12-20-2003, 12:59 AM

>>I tried to calculate the inverse Modelview

gl_NormalMatrix ?

Normal matrix is just the upper 3*3 of the modelview matrix.

Amandeep

12-02-2011, 11:32 PM

Hi,

Yes, gl_NormalMatrix is the inverse matrix of the orientation matrix( 3x3 ), upper 3 columns & rows of gl_ModelViewMatrix.

Regards,

Aman

V-man

12-03-2011, 05:55 AM

Normal matrix is just the upper 3*3 of the modelview matrix.

It isn't.

It is the upper 3x3 of the inverse of the modelview matrix.

Actually, I'm not sure, it might be the upper 3x3 of the inverse transpose of the modelview matrix.

You can of course just use the upper 3x3 of the modelview if there is no non uniform scale operation on it.

thokra

12-03-2011, 07:15 AM

Actually, I'm not sure, it might be the upper 3x3 of the inverse transpose of the modelview matrix.

The normal matrix is the inverse transpose of the rotational part of the modelview matrix.

What Mazy said is true iff the conditions holds that the rotational part is and orthogonal (or even orthonormal) matrix. In this case it is true that M^-1 = M^T. Therefore (M^T)^-1 = (M^-1)^-1 = M.

In general this is NOT true! Still, since most of the time we're dealing with an orthonormal matrix (some form of the 3D rotation matrices) mat3(gl_ModelViewMatrix) == gl_NormalMatrix.

Edit: @Amandeep: You might want to check out rule #6 in the forum posting guidelines. Just realized how incredibly dated this thread is...

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.