# Understanding perspective projection

HNY,

Why does perspective projection needÂ´s a far-component to calculate the screeen coordinates ?
(If it is not used for deepth-buffer stuff)

Is there a simple way to understand how gluProject( and gluLookat() in combination) are working without matrices in detail ?

IÂ´am using gluProject and gluUnProject for the OpenGL View, but i nead a simular calculation for exporting a hidden-line vector view to a SVG or PDF file. During this export i have no device-context to use the OpenGL functions.

Howie

If you really want to understand how it all works, you have to learn matrices. It’s not that hard

Basically, gluProject multiplies the coordinate by both matrices (first modelview, then projection), and then divides the x,y,z components of the result by the w component. This gives coordinates in the unit cube. These are then scaled to fit in the viewport.

gluUnproject does exacly the opposite by inverting the matrices.

The source code of GLU should be available somewhere. Try the mesa homepage.

Why does perspective projection needÂ´s a far-component to calculate the screeen coordinates?
The perspective projection needs the far component only to calculate the z coordinate, for the x and y components it makes no difference.

You can see this by looking at the matrix (the redbook has the exact matrix in Appendix G). The far component is only used in the third row.

Thanks Overmind,

All my objects are transformed by my hierarchie of data to world coordinates. So OpenGl needs no specify modelviewmatrix (always glIdentity).
The Perspective Projection in the RedBook (Fifth Edition) on Page 755 (Appendix F) shows the perspective matrix for glFrustum, but i didnÂ´t use the following code (example) instead of glFrustum:

``````glMatrixMode(GL_PROJECTION);
gluPerspective(45.0f, fAspect, fNearPlane, fFarPlane);
gluLookAt(1000.0,-1000.0,700.0,0.0,0.0,0.0,0.0,0.0,1.0);
glMatrixMode(GL_MODELVIEW);
``````

If i see the frustum in 3D-World coordinates. I tried to solve the problem with vector math, but the result seemed to be sheared.
Should this not be possible ?

I will take a further look at the mesa homepage.

Howie

(the first edition of the red book i have lent to a friend years ago.)

Hi howie meyer,

gluPerspective is a glFrustum with some particular values.