Convert user view to Camera view.

I have a perspective view and I would like to convert it into a camera view(gluLookAt). For short by given the current view matrix, I would like to get the eye position, center of viewing and Up direction. Thanks in advance!

This isn’t really an advanced question.

VIEWING matrix takes you from WORLD-SPACE to EYE-SPACE, right? And you know what those points/vectors are in EYE-SPACE: (0,0,0), (0,0,-1), and (0,1,0), respectively. And you know that the VIEWING matrix is invertible. So the simple (and inefficient) method is to do a full inverse on that matrix and transform that EYE-SPACE point and those EYE-SPACE vectors through it to get the WORLD-SPACE point and vectors.

You can do this much more efficiently if you know that VIEWING matrix is orthonormal (e.g. just rotates and translates, which it almost always is). If so then you know your matrix is RT, where the rotate is the upper-left 3x3 and the translate is the top 3 of the far right column. You can do a really fast invert of that: (RT)^-1 = T^-1 * R^-1. Consider that inverse of R is just the transpose, and this is simple. Google fast orthonormal invert for details.

Crunch through it and you’ll see that your EYE-SPACE Y and Z vectors transformed to WORLD-SPACE you can just pick right out of the original VIEWING matrix. And getting the WORLD-SPACE eye position is just a short 3x3 multiply away.

Thanks for the reply. And sorry for posting at the Advanced category. I found out another solution which I use gluUnProject to project two window coordinate ( one at z == 0 and second at z = 0.5) into the world coordinate and calculate the vector of it. Manipulate the vector and the distance from the object I am able to get the eye position.