About the Projection matrix

Started by
5 comments, last by MARS_999 17 years, 8 months ago
Hi! someone can explain me what does establish the Projection matrix? and how can i modify it or create a new one? Is there any direct relation between the Projection matrix and the frustum that can create glOrtho o gluPerspective? Thanks
Advertisement
There is a direct relation between glOrtho and gluPerspective to the perspective matrix. See the bottom of this page.

To create a new perspective matrix do

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

folowed by glOrtho() or gluPerspective().

If you want to modify the projection matrix you must read it back

GLfloat projection[16];
glGetFloatv(GL_PROJECTION_MATRIX, projection);

modify the array (advanced stuff....) then write it back to the projection matrix

glLoadMatrixf(projection);

Remember to switch back to the modelview matrix mode when you've done.
thanks coordz

but for example if i want to load this matrix:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16


How should i write this line?:

GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};

or

GLfloat projection[16]={1, 5, 9, 13, 2, 6, ....16};

or what way?
I can't think of any reason why the OpenGL makers would have choosen option B for storing arrays..

Should be the one:
GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};

"Game Maker For Life, probably never professional thou." =)
It's option B. OpenGL uses column-major matrices. So this array:

GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};

will yield the following Matrix (in standard mathematical notation):
1  5  9  132  6  10 143  7  11 154  8  12 16


You can use LoadTransposeMatrix() to load a matrix in row major order, ie. your option A (requires an extension though).
Haha!
Well.. this would explain a couple of problems I've been having! :D
"Game Maker For Life, probably never professional thou." =)
As usual Yann L to save the day!

This topic is closed to new replies.

Advertisement