Jump to content
  • Advertisement
Sign in to follow this  
someone2

Getting current transformation matrix

This topic is 4703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, How can I get the current transformation matrix (The Model View matrix)? Also, if I have a transformation matrix, is there a function that calculates where a certain vertex would go under this matrix (i.e. it will do the matrix multiplication instead of me doing it myself!) Thank you very much

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Original post by someone2
Hi,
How can I get the current transformation matrix (The Model View matrix)?

Also, if I have a transformation matrix, is there a function that calculates where a certain vertex would go under this matrix (i.e. it will do the matrix multiplication instead of me doing it myself!)

Thank you very much


well, u can use glGetFloatv() for ur modelview matrix.
to transform vertex just multiply it by transformation matrix

Share this post


Link to post
Share on other sites
Quote:
Original post by someone2
How can I get the current transformation matrix (The Model View matrix)?

glGetFloatv(GL_MODELVIEW_MATRIX,&a_16_float_buffer);
You could get it in other scalar formats, too, but most often float is the internal representation used by the driver, so it could be seen "natural".

The buffer is filled like this scheme shows

[ 0 4 8 12 ]
[ 1 5 9 13 ]
[ 2 6 10 14 ]
[ 3 7 11 15 ]


where 0..15 are the indices into "a_16_float_buffer".

Quote:
Original post by someone2
Also, if I have a transformation matrix, is there a function that calculates where a certain vertex would go under this matrix (i.e. it will do the matrix multiplication instead of me doing it myself!)

Nope, you have to do it yourself. However, what exactly means "would go under this matrix"? Be aware that applying the MODELVIEW matrix will yield in the vertex position in the view space, of course. E.g. projection is not done by that matrix. So, if you mean the screen position, you have to do more than that. (And if you want it in world space, you have to do more, too.)

Share this post


Link to post
Share on other sites
Quote:
Original post by someone2
Hi,
How can I get the current transformation matrix (The Model View matrix)?

Also, if I have a transformation matrix, is there a function that calculates where a certain vertex would go under this matrix (i.e. it will do the matrix multiplication instead of me doing it myself!)

Thank you very much


Like haegarr said, the sentence "where a certain vertex would go under this matrix" doesn't specify in which coordinate system you want this point. If it is indeed view space (i.e. the position of the point w.r.t. the camera), no function exists, but multiplying a vector by the matrix is pretty straightforward. I can post code for doing this with the output of the glGetFloatv function if you desire.

If instead you want to know the point in screen space (i.e. the position of the point on the window), then there is a function you can use: gluUnProject.
It looks a bit tricky at first, but all required parameters can be obtained through the glGetFloatv function.

Finally, another commonly used coordinate system: the coordinates in world space (i.e. the position of the point in the world). If you want this, they cannot be obtained through the modelview matrix, as they require multplication with the model matrix only. If this is what you want, you'll need to keep track of the model matrix yourself.

Tom

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!