View Full Version : Projection matrix

I tried something funny.. I took the definition of the orthographic projection(from the red book) and loaded up a calculated matrix as the projection matrix.

Though it didn't give the same result as using built in methods.. i had to multiply a translation to the calculated orthographic projection matrix because the coords 0,0 was lower right coordinates... yepp RIGHT =D

Now i wonder if someone tried this out, is there some matematical stuff going on that isn't specified in the docs. Seems a bit odd that i had multiply by a translation matrix to get the same results as the built in glOrtho.

chowe6685

05-30-2002, 03:50 PM

could be because opengl orders the matrices differently than normal math, try using the transpose of your original matrix

Well, transltion is like moving the camera nearer.. to simulate Zoom , just narrow the FOV, that is exactly what realworld cameras does.

well the matrix is the way opengl wants it, it column ordered in a array(0-3 first column etc..)

The code currently looks like(matrix are a GLfloat matrix[16] http://www.opengl.org/discussion_boards/ubb/wink.gif

void M4x4::LoadOrtho(float Left, float Right, float Bottom, float Top, float Near, float Far)

{

matrix[0] = 2.0f / (Right - Left);

matrix[1] = 0.0f ;

matrix[2] = 0.0f ;

matrix[3] = 0.0f ;

matrix[4] = 0.0f ;

matrix[5] = 2.0f / ( Top-Bottom ) ;

matrix[6] = 0.0f ;

matrix[7] = 0.0f ;

matrix[8] = 0.0f ;

matrix[9] = 0.0f ;

matrix[10] = -2.0f / (Far - Near);

matrix[11] = 0.0f ;

matrix[12] = (Right + Left) / (Right - Left) ;

matrix[13] = (Top + Bottom) / (Top - Bottom) ;

matrix[14] = (Far + Near) / (Far - Near) ;

matrix[15] = 1.0f ;

M4x4 tmp;

tmp.LoadTranslation(Left-Right,Top-Bottom,0);

*this = (*this)*tmp;

}

you also see the LoadTranslation method(pasted below), which is

the current test work around to transpose the scene origin just tested at my perticular case.

Now the entire scene is reseted and world,texture and projection matrix is set to identity before i do any operations.

glMatrixMode(GL_PROJECTION);

M4x4 projection

projection.LoadOrtho(0,287,255,0,-1,1);

glLoadMatrixf(projection.matrix);

Now the above code vill produce the same

result as: gluOrtho2D(0,287,255,0);

But only if i keep the translation matrix in the LoadOrtho method(otherwise the scene will have 0,0 in lower right).

I can't see anything differing from the redbooks definition of the orthomatrix, soo I believe it should yield the same result without the translation but it doesn't.

---

void M4x4::LoadTranslation(float Tx, float Ty, float Tz)

{

LoadIdentity();

matrix[12] = Tx;

matrix[13] = Ty;

matrix[14] = Tz;

}

Jambolo

05-31-2002, 08:13 PM

Originally posted by Some Bozo:

matrix[12] = (Right + Left) / (Right - Left) ;

matrix[13] = (Top + Bottom) / (Top - Bottom) ;

matrix[14] = (Far + Near) / (Far - Near) ;

It's hard to read in the book -- look closely, these terms should be negated.

Yep, that did indeed work =) thanks!

no matter what zoom level i used in the pdf file i couldn't find the sign though, but it now i know, thanks again =D

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.