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.

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 on other sites
Quote:
 Original post by someone2Hi, 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 on other sites
Quote:
 Original post by someone2How 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 someone2Also, 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 on other sites
Quote:
 Original post by someone2Hi, 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

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• Forum Statistics

• Total Topics
633416
• Total Posts
3011780
• Who's Online (See full list)

There are no registered users currently online

×