Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Inverse Modelview

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2003
    Posts
    1

    Inverse Modelview

    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).]

  2. #2
    Intern Newbie
    Join Date
    May 2003
    Location
    Bucharest,Romania
    Posts
    40

    Re: Inverse Modelview

    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

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2003
    Location
    Switzerland
    Posts
    12

    Re: Inverse Modelview

    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

  4. #4
    Junior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    Kiev, Ukraine
    Posts
    130

    Re: Inverse Modelview

    >>I tried to calculate the inverse Modelview
    gl_NormalMatrix ?
    Andrey Yaromenok

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: Inverse Modelview

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

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    1

    Re: Inverse Modelview

    Hi,

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

    Regards,
    Aman

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264

    Re: Inverse Modelview

    Quote Originally Posted by Mazy
    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.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099

    Re: Inverse Modelview

    Quote Originally Posted by V-man
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •