gluProject() problem


I need gluProject() functionality. In my engine I am already taking the GL_MODELVIEW and GL_PROJECTION matrices as Float at the begining of the rendering (for culling and other features), and I would like to reuse those matrices, in place of getting them again with double precission as needed by gluProject().

I mean, to not get them once with glFloat() and twice with glDouble().

What is gluProject() actually doing?

In my single-precision implementation I multiply the input point (pos param) by the modelMatrix, then by the projectionMatrix, do the w division, and then I do

xw = (xnd+1)(w/2)+x
xy = (ynd+1)(h/2)+y

Where xnd and ynd are taken from the output of the two previous point4d-matrix multiplications.

x and y (that bugger my mind for a while) must be the viewport origin, wich is not explained in the documentation.

In my implementation I do nothing on z, it is returned as pseudo-depth as it comes from the modelview/projection transform. However my results differ drastically on z from that of gluProject(), and for the error magnitude it cannot be because of double->float precission.

A point [0,0,-10] with an identity modelviewmatrix, and a perspective projection matrix of 60 degrees (on y) and znear/zfar [0.1,100] gives [400,300,0.99099099040031435] with gluProject and [400,300,0.99198198] with mine. x and y are the same in both cases, and it represents, as it should be, the center of a 800x600 viewport.

I tried with other values, x ej [2.45,5.54,-10] gives:
[527.30572915077209,587.86683905124664,0.99099099040031435] (GLU’s)
[527.30573, 587.86682, 0.99198198] (Mine)

I’m using gluProject to test for occlusion on halos, by also reading the depth buffer and comparing zetas. However my method does not work and I’m forced by now to use gluProject and get the matrices twice, wich I would really like to avoid.

What is performed at each step on z on the modelview-projection-viewport transformation pipeline?

What is gluProject() actually doing?…pe=text%2Fplain

Thanks Relic! :slight_smile:

OMG…that link is GOLD !!