# 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.

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 void M4x4::LoadOrtho(float Left, float Right, float Bottom, float Top, float Near, float Far)
{
matrix = 2.0f / (Right - Left);
matrix = 0.0f ;
matrix = 0.0f ;
matrix = 0.0f ;

``````matrix = 0.0f ;
matrix = 2.0f / ( Top-Bottom ) ;
matrix = 0.0f ;
matrix = 0.0f ;

matrix = 0.0f ;
matrix = 0.0f ;
matrix = -2.0f / (Far - Near);
matrix = 0.0f ;

matrix = (Right + Left) / (Right - Left) ;
matrix = (Top + Bottom) / (Top - Bottom) ;
matrix = (Far + Near) / (Far - Near) ;
matrix = 1.0f ;
M4x4 tmp;
*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

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)
{
matrix = Tx;
matrix = Ty;
matrix = Tz;
}

Originally posted by Some Bozo:

matrix = (Right + Left) / (Right - Left) ;
matrix = (Top + Bottom) / (Top - Bottom) ;
matrix = (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