View Full Version : Obtaining coordinates after MVP multiplication

Mukund

08-29-2011, 07:10 AM

Hello everyone,

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.

aqnuep

08-29-2011, 07:14 AM

You'll need to multiply the matrices and then multiply the vertices by the result in order to get those coordinates.

Mukund

08-30-2011, 04:34 PM

Thanks for the reply aqnuep. I was just querying the Projection matrix, and i found the following results:

Frustum:

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?

Thanks.

Alfonse Reinheart

08-30-2011, 05: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.

Mukund

08-30-2011, 11:08 PM

@Alfonse Reinheart

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.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.