View Full Version : 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)?
02-22-2004, 06:30 PM
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 mat mat mat ) ( x )
( mat mat mat mat ) * ( y )
( mat mat mat mat ) ( z )
( mat mat mat mat ) ( 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 ) = ( a*e + b*g a*f + b*h )
( c d ) ( g h ) ( c*e + d*g c*f + d*h )
( a b ) * ( x ) = ( a*x + b*y )
( c d ) ( y ) ( c*x + d*y )
You can find a lot more information on this all over the web. Just look up matrix math. Wow, this got long quick. ^_^
[This message has been edited by Nychold (edited 02-22-2004).]
Yes,that is right.
Thank you very very much.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.