PDA

View Full Version : Projection matrix



tirengarfio
08-17-2006, 06:27 AM
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

Michael L. Croswell
08-17-2006, 05:03 PM
You are correct in that there is a tight relationship between the frustum and projection matrix. The project matrix changes the scale of things in order to cull at -1 to 1 (if I remember right).

Anyway, this is why you first call:
glMatrixMode(GL_PROJECTION);

and set identity matrix and then your calls to glOrtho or gluPerspective(). You can even call glFrustum() if you want, but I like gluPerspective().

Don't forget that after you've taken care of the perspective transform it's then time to put the matrix mode into GL_MODELVIEW so the rest of your code works. Remember, OpenGL is very "state" based and in the Model-View state we are thinking of moving the camera, moving our models and no longer in the "frustrum".

Does this help?

- Michael L. Croswell

PS: I did a search and found some example code at my old school (I actually took this CS410 course over a decade ago and we had to implement a ray-tracer by hand with only the ability to draw one pixel-at-time - it took minutes to render a frame!)
The link shows some code (written by Andy Curtis) at:
http://www.cs.colostate.edu/~cs410/resources/glulookat/lookat.cpp