PDA

View Full Version : gluPerspective question



mjs1
10-16-2004, 03:58 PM
I was trying to create the projection matrix myself rather than using gluPerspective() or glFrustum(). I used the matrix in the back of the red book defined for perspective projection. I'm having trouble coming up with the same values for the matrix I'm calculating that gluPerspective() comes up with. I was hoping someone could spot and see if I'm missing something.

For a camera with aspect ratio 1.33, a viewAngle of 30.0, and clipping planes at 0.1 and 300.0:

gluPersp matrix (from glGetDoublev()):
2.79904
0
0
0
0
3.73205
0
0
0
0
-1.0
-1.0
0
0
-0.2
0

my matrix:
2.79904
0
0
3.73205
0
0
0
0
-1.0
-0.2
0
0
-1.0
0

The 11 and 14 positions seem to be swapped. I'm confused by position 14, as all my references say to load -1.0 here. Why would gluPerspective's position 14 be anything other than -1.0?

Thanks for any help!

Bob
10-17-2004, 12:06 AM
My copy of the Red Book says matrix[11] is -1, and matrix[14] is -2*f*n/(f-n). Here (http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/apf.html#id5560018) 's an online version of the 1.2 guide whihc says the same thing.

Bob
10-17-2004, 12:16 AM
Ok, maybe you just got the position of the indices the wrong way. If you number them row by row, you get the matrix you got. However, OpenGL number the indices column by column, as shown here (http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/ch04.html#id5459800) .

mjs1
10-17-2004, 07:50 AM
Doh!

Thanks Bob. I was loading the matrix in row major order (and reading the output of glGetDoublev in row major order as well.)

Everything was doing what it was supposed to. Except me. :)