Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CoderTCD

how does projection matrix work?

This topic is 5357 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

I looked for it but I couldn''t find about the mathematics of projection matrix. do someone explain it on web? serdar

Share this post


Link to post
Share on other sites
Advertisement
The PROJECTION_MATRIX (PM) matrix is used to multiply your MODELVIEW_MATRIX(MM)

point = MM * MP * original_point

After this OpenGL apply z division, clipping,...to project point in the viewport.

You know that you set up PM using directly glFrustum() or gluPerspective()...gluPerspective() fill the PM with this algorithm I found

here is gluPerspective source code (Mesa 3.0):


void APIENTRY gluPerspective( GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar )
{
GLdouble xmin, xmax, ymin, ymax;

ymax = zNear * tan( fovy * M_PI / 360.0 );
ymin = -ymax;

xmin = ymin * aspect;
xmax = ymax * aspect;

glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}



To read PM you use glGetFloatv(GL_PROJECTION_MATRIX, float16)

To read info from this matrix I have resolved the (simple) system

   

// I've used different notation...sorry!

//

// However this is the matrix

// A 0 E 0

// 0 B F 0

// 0 0 C D

// 0 0 -1 0


// We must transpose


// frustumMatrix is the PM as it is from glGet

REAL A = frustumMatrix[0];
REAL B = frustumMatrix[5];
REAL C = frustumMatrix[10];
REAL D = frustumMatrix[14];
REAL E = frustumMatrix[8];
REAL F = frustumMatrix[9];

// The params


REAL n = D/(C-1);
REAL f = D/(C+1);
REAL l = n * (E - 1) / A;
REAL r = n * (E + 1) / A;
REAL b = n * (F - 1) / B;
REAL t = n * (F + 1) / B;



So you get l,r,b,t,n,f that describe your projection: n and f are znear and zfar; l,r,b,t describe the rectangle on znear that is mapped exactly on the viewport.


[edited by - blizzard999 on October 22, 2003 6:51:54 AM]

[edited by - blizzard999 on October 22, 2003 6:53:15 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!