Jump to content
  • Advertisement
Sign in to follow this  
tirengarfio

About the Projection matrix

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

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!