getting orientation and position in opengl

I'm trying to extract current orientation and position in opengl. I know it is wrapped in the GL_MODELVIEW matrix, but i am having trouble interpreting it.

Question: How do i extract current orientation and position in opengl?

Please note that I am having trouble after i use gluLookAt(), i have no trouble understanding the GL_MODELVIEW matrix before I use gluLookAt(), but after gluLookAt(), the matrix is distorted in a way that no longer makes sense to me. This is an advance opengl problem that I cannot find much information on the net. If you know any webpage that talks about what gluLookAt() does at the implementation level or know how to extract orientation/position in opengl, please help me. Any suggestion is appriciated.

I have to use gluLookAt() because, i need to render it on the screen, and I need to extract info so that i can do my own math to it and return the result into GL_MODELVIEW matrix.

I need help ASAP, for there is a deadline.

Solved: OpenGL Modelview matrix

Code:

`Just thought might be useful to some other students in the same situation:`

1)

The modelview is a float[16], and write on paper as:

Code:

`m0 m4 m8 m12 `

m1 m5 m9 m13

m2 m6 m10 m14

m3 m7 m11 m15

where,

Code:

`m0 m4 m8 `

m1 m5 m9

m2 m6 m10

is the orientation, {m0 m1 m2} is the where the x-axis of the current currently pointing at in the absolute space, {m4 m5 m6} for y-axis, {m8 m9 m10} for z-axis.

{m12 m13 m14} is the {x y z} of the current frame

2) Modelview matrix typically is initially transformed by a translation and orientation, so even though you thought you didn't twist the frame or translate the current cursor in the absolute space, the modelview matrix still may look like:

0.432 0.432 0.185 2

0.858 0.738 0.980 4

0.890 0.280 0.178 5

0 0 0 1

the reason is you are looking at the product of MODEL matrix and the VIEW matrix. more precisely, you are looking at:

Identity matrix * the 4x4 matrix you see above

and because of the MODEL matrix is currently identity, you are effectively seeing the VIEW matrix, that applies the camera transformation to the MODEL matrix.

to reverse the effect of the VIEW matrix (so you can get the position and orientation in the MODEL space, the space we are use to)

>take the transpose of the orientation matrix (refer to 1 if you don't know what i mean) and negate the translation vector.

>multiply the current **camera frame** by the transpose of orientation matrix, and add the negated version of translation vector to the current translation vector

(this second step is very confusing, so read it again, if you really can't figure out what i am saying, post and i'll attempt to explain further)

Doing this right will generate a 4x4 identity matrix, representing untranslated, default-orientated cursor in the absolute space

this is the MODEL matrix that everyone is talking about when he says you can *easily* get the position and orientation of all the objects you draw in opengl.

I certainly don't think it's easy and clear at all.

Don't even attempt to reverse the effect of gluLookAt(), just use glTranslate() and glRotate() to set up your scene. (by that i mean replace gluLookAt() with the other two function). Do it this way, later you will know this is wiser.

At this point, you should walk baby steps and build test function to watch the content of MODELVIEW matrix. If you need help with the math, opengl.org doesn't tell you at all, nobody on the internet bothers to go into the detail, professor is too busy. This seems like a joke, but that's the reality.

So really, the only best source is to work it out yourself. It's all matrix algebra.

I couldn't find a good tutorial about interpreting modelview matrix. I hope this could be useful for whoever is doing a robotic simulation project in opengl.

If you need further information, you can post here, may take a while for me to answer though so be patient and don't depend your project on it.

ting