possible to get eyepoint?

yes,as I know, I can use gluLookAt to indciate an eyepoint, but is it possible to get it back with opengl functions?
Maybe, according to my understanding, opengl doesn’t keep this information, because gluLookAt is just a easy way to defines a viewing transformation matrix. But I am not sure.

// Some code to get the projection matrix,
// model view matrix and viewport.

GLdouble Projection [16], Model [16];
GLint Viewport [4];

glGetDoublev ( GL_PROJECTION_MATRIX, Projection );
glGetDoublev ( GL_MODELVIEW_MATRIX, Model );
glGetIntegerv( GL_VIEWPORT, Viewport );

Of course, if you have any further transforms before or after your `look at’ on the stack, these will be part of the modelview matrix.

The eye-point are the parts [0][3], [1][3] and [2][3] of the modelview matrix (negate of course). <-- I think this is correct

[This message has been edited by Robbo (edited 04-25-2002).]

Remember the call for gluLookAt is void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz);. Hence you’re eye point is given by eyex, eyey, eyez. Use the same values you supplied.

Doh!

Of course thats right

I figured this problem was slightly more complicated than in fact it was. The question if phrased correctly, would have been circular and therefore philosophicaly unsound.

Thanks for your replies first.
Maybe my question is not very clear. gluLookAt actually needs eyepoint and we can use it. But, working this way, one class needs to be notified if other classes modify the eyepoint. This makes classes more tightly coupled. This is why I hope to solve this problem through opengl functions.

Well in that case I think your approach is wrong. I have lots of classes that need to use the eye-point - so I have a single camera object which I pass into each class (by reference) when needed.

Although you have the cost of pushing\popping a pointer onto\off the stack, it is MUCH MUCH more expensive to find the eyepoint from OpenGL.

I completely agree with Robbo –

If you have sopmething that needs to know the state of the camera, then pass the camera as a parameter. If the situation is more complicated, then the class may need to contain a reference to the camera. This is what makes the most sense (in general).

Alternatively, you can pass a reference to the object that controls the camera.

Or, you could query the camera’s state and pass that info rather than the camera itself.

The biggest problem with getting the location of the camera from modelview matrix is that the data is correct only after you do the gluLookAt (or whatever) and before you do anything else. After you start drawing things, the matrix will be changed and you can no longer get the camera’s location from it.

Actually, you could still get the info from the matrix with careful use of matrix push and pop. But (repeating what Robbo said) that is very slow – querying OpenGL’s state generally involves flushing the rendering pipeline, and waiting for the flush to finish. Ouch.

to Robbo and Jambolo:
I really appreciate your help. I think your way is actually the only way.
In my demo, I do implement camera which stores the current eyepoint. The
very reason why I have to complicate this is that I am programming a set of APIs for simulating such natural phenomena as rain, snow etc. I cannot assume the user will use something like camera and tell the API where the current eyepoint is. Maybe some expert users are accustomed to directly manipulating matrices. So I hoped that opengl functions could help me. But it seems impossible now. Who knows.
Any more suggestion will be appreciated.

[This message has been edited by hapcafe (edited 04-28-2002).]