Sign in to follow this  
tirengarfio

About the Projection matrix

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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};

Share this post


Link to post
Share on other sites
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 13
2 6 10 14
3 7 11 15
4 8 12 16


You can use LoadTransposeMatrix() to load a matrix in row major order, ie. your option A (requires an extension though).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this