Reversing gluLookAt()

Posted on 2006-05-29
Last Modified: 2013-12-06
Hi Guys,

I am struggling a little bit with transformation matricies. I am trying to find a solution that will let me derive values for "eye position" "look at point" "up vector" from a transformation matrix. I know that gluLookAt will let me convert the other way, but I cant find a way to go back!

Many Thanks,

Question by:chrishughes
    LVL 25

    Accepted Solution

    I don't believe that you can reverse all of that info.

    gluLookAt performs the following operation to produce the transformation matrix:

         | centerX - eyeX |
    f = | centerY - eyeY |
         | centerZ - eyeZ |

    f = f / ||f||
    UP' = UP / ||UP||
    u = (f x UP) x f

    The transformation matrix, M:

           |  s[0]   s[1]   s[2]   0  |
    M = |  u[0]   u[1]   u[2]   0  |
           | -f[0]  -f[1]   -f[2]    0  |
           |    0      0        0      1  |

    As you can see, the only data regarding the center and eye positions are lost, as it's the *difference* between these values that is used in the matrix....

    LVL 25

    Expert Comment

    Futhermore, the 'difference' values are then normalised, so you probably wouldn't even be able to retrieve that much, for sure.
    LVL 25

    Expert Comment

    You can reverse the Modelview matrix in order to extract the required camera information.

    Firstly, retrieve the Modelview matrix:

      GLfloat viewMatrix[16] ;
      glGetFloatv( GL_MODELVIEW_MATRIX, viewMatrix ) ;

    Then from this, you can produce the right and up vector components:

      // assuming that you have a vector class called vector3:
      vector3 right( viewMatrix[0], viewMatrix[4], viewMatrix[8] ) ;
      vector3 up   ( viewMatrix[1], viewMatrix[5], viewMatrix[9] ) ;

    And also the eye position:

      vector3 eye ( -viewMatrix[3], -viewMatrix[6], -viewMatrix[9] ) ;

    So long as the Right and Up vectors are normalized (which OpenGL does automatically), then the Look At vector is simply the Cross Product between the Right and Up vectors, defined as:

       vector3 at  ( right.y*up.z - right.x*up.y, right.z*up.x - right.x*up.z, right.x*up.y - right.y*up.x ) ;

    So by mapping a transformation to the modelview matrix, you can deduce these properties.
    LVL 25

    Expert Comment

    Sorry, this line:

      vector3 eye ( -viewMatrix[3], -viewMatrix[6], -viewMatrix[9] ) ;

    Should be:

      vector3 eye ( -viewMatrix[3], -viewMatrix[7], -viewMatrix[11] ) ;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Photoshop CC 2015

    Photoshop has become the standard in image manipulation among professional photographers and graphic designers. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
    As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now