I use gluLookAt()…How can I extract the x,y,z coordinates (the first 3 parameters of gluLookAt) from the MODELVIEW matrix??
Ok! I found it by myself looking at the gluLookAt() code!
that article was a bit different from what I needed … anyway the 4th column of the modelview matrix does not contain the coordinate of the observer, infact if you use gluLookAt() the matrix you’ll have is the result of:
(x0 x1 x2 0) (1 0 0 ex)
(y0 y1 y2 0) (0 1 0 ey)
(z0 z1 z2 0) X (0 0 1 ez)
(0 0 0 1) (0 0 0 1 )
where ex,ey,ez are coordinates of the eye.
so the element of the 4th column will be:
A = x0ex+x1ey+x2ez
B = y0yx+y1ey+y2ez
C = z0ex+z1ey+z2*ez
D = 1
to re-obtain ex,ey,ez you have just to solve this equation-system: you can use the Kramer’s rule remembering that the following matrix should be orthonormal (=> DET=1)
(x0 x1 x2)
det (y0 y1 y2) = 1
(z0 z1 z2)
sorry for writing bad all the matrices