## Using Z value returned by gluProject

### Using Z value returned by gluProject

gluProject returns x, y and z in screen coordinates.  I want to use the z value to compute the z
position in eye coordinates.  I think the z value being returned will always be 0 to 1.  If I use
the following formula (far clip - near clip) * z + near clip, will I get what I am after or will
this calculate a z value which is further away do to the projection matrix?  I am going to have to
use gluProject in any case, is there a better way to get the z value than gluProject?

Thanks:

--

Software Consultant     www.vianova.com/~vianova
Via Nova                OpenGL, Open Inventor products for Windows 95/NT
Dallas, Texas

### Using Z value returned by gluProject

> gluProject returns x, y and z in screen coordinates.  I want to use the z value to compute the z
> position in eye coordinates.  I think the z value being returned will always be 0 to 1.  If I use
> the following formula (far clip - near clip) * z + near clip, will I get what I am after or will
> this calculate a z value which is further away do to the projection matrix?  I am going to have to
> use gluProject in any case, is there a better way to get the z value than gluProject?

> Thanks:

> --

> Software Consultant     www.vianova.com/~vianova
> Via Nova                OpenGL, Open Inventor products for Windows 95/NT
> Dallas, Texas

The Z value you want (Zeye) can be derived from the screen coordinate Z
(Zs) using to following formula :

Zeye =  far x near / (far - (far - near)xZs)

this can be derived knowing that :

Zs = A - B/Zeye
where :
A = far/(far - near)
and
B = near/(far - near)

Atually, this formula gives you |Zeye| you may want to change its sign
so that the eye looks down the -Z axis.

Raoul/

--
-----------------------------------------------------------------------------
Raoul MALLART                Laboratoires d'Electronique PHILIPS  S.A.S.

94453 Limeil-Brevannes FRANCE

Ph. (33-1) 45 10 68 14       Fx. (33-1) 45 10 69 60
-----------------------------------------------------------------------------

Hello all; I am trying to create a lens flare & have the following code:

gluproject(globallightposx,globallightposy,globallightposz,modelview,project

The calculations are perfect if my camera's Z coordinate is 0. But, if I
zoom in or out the object in 3d space gets scewed away from the window
coordinates created by gluproject.

Has anyone had this happen before?

My camera works like so:

glTranslatef(-camerax,-cameray,-cameraz);
glRotatef(cameraangle,camerarotx,cameraroty,camerarotz);        // Rotate
The Camera

I have tried