View Full Version : Obtaining coordinates after MVP multiplication
08-29-2011, 06:10 AM
I was wondering if there is any way to obtain the coordinates after a vertex is multiplied by the ModelView and the Projection matrix? i.e just before the perspective divide.
Is there any built-in mechanism by which i can do it or do i need to multiply matrices manually and try?
Thanks in advance.
08-29-2011, 06:14 AM
You'll need to multiply the matrices and then multiply the vertices by the result in order to get those coordinates.
08-30-2011, 03:34 PM
Thanks for the reply aqnuep. I was just querying the Projection matrix, and i found the following results:
glFrustum(-0.1, 0.1, -0.1, 1.0, 1.0, 1000.0);
The matrix i obtained is printed as:(i used glGetFloatfv to obtain the projection matrix) as:
10.000000 0.000000 0.000000 0.000000
0.000000 1.818182 0.000000 0.000000
0.000000 0.818182 -1.002002 -1.000000
0.000000 0.000000 -2.002002 0.000000
However, from this LINK (http://www.opengl.org/wiki/Vertex_Transformation) its given as:
[1.0, 0.00, 0.00, 1.00]
[0.00, 1.0, 0.00, 2.00]
[0.00, 0.00, 1.00, 3.00]
[0.00, 0.00, 0.00, 1.00]
Could you please explain as to how im getting a different answer?
08-30-2011, 04:31 PM
Well, for several reasons.
First, you almost certainly transposed your matrix when you printed it. OpenGL is column-major; the first 4 values are the first column of the matrix.
Second, the tag above that matrix you linked to says, "Let's built a very simple modelview matrix." The modelview matrix is not the projection matrix.
Third, you will only get that matrix by executing the two lines above it, as the example shows. That is not a projection matrix; it's a translation matrix.
08-30-2011, 10:08 PM
Oh! I'm really sorry. I made a mistake while copying it from the other tab of my browser.
I am referring to the projection matrix.
[1.81, 0.00, -0.81, 0.00]
[0.00, 10.0, 0.00, 0.00]
[0.00, 0.00, -1.002, -2.002]
[0.00, 0.00, -1.00, 0.00]
And yes, i had printed the values in the wrong order. Now i cross-checked it. It matches. Thanks a lot.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.