Get true location by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

There is a point inited with x,y and z.
Now It has been moved by glTranslatef,glRotatef and some other commends.
How can i get the true location of this point by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

The array mat then holds the current model viewing matrix, so all you have to do is take the vector for the point (x,y,z,1) and multiply it by the matrix you retrieved:

( mat[0][0] mat[1][0] mat[2][0] mat[3][0] ) ( x )
( mat[0][1] mat[1][1] mat[2][1] mat[3][1] ) * ( y )
( mat[0][2] mat[1][2] mat[2][2] mat[3][2] ) ( z )
( mat[0][3] mat[1][3] mat[2][3] mat[3][3] ) ( 1 )

That result will yield the transformed point (ie: the actual point in 3D space), just omit the homogenous coordinate (the last entry). If you’re not familiar with matrix math, get there! Very important in 3D graphics! ^_~ But, here’s the gist: The left matrix tells you how many rows your result will have. The right matrix will tell you how many columns you’ll have. In our case, we’ll have 4 rows and 1 column (a vector in R^4, or 4 dimensional space). Then, pick a row in the left matrix and a column in the right matrix. This will be the location in our resulting matrix for our final answer. Start from the first entries and multiply them. Move to the next elements and multiply, then add with the previous result. Repeat until you run out. Examples generally help:

( a b ) * ( e f ) = ( ae + bg af + bh )
( c d ) ( g h ) ( ce + dg cf + dh )

( a b ) * ( x ) = ( ax + by )
( c d ) ( y ) ( cx + dy )

You can find a lot more information on this all over the web. Just look up matrix math. Wow, this got long quick. :slight_smile:

[This message has been edited by Nychold (edited 02-22-2004).]

Yes,that is right.

Thank you very very much.