Using Z value returned by gluProject

Using Z value returned by gluProject

Post by Zachary Hilbu » Fri, 12 Jul 1996 04:00:00



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

Post by Raoul MALLAR » Sat, 13 Jul 1996 04:00:00



> 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                
-----------------------------------------------------------------------------

 
 
 

1. gluproject - wrong values when camera is zoomed?

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

   gluLookAt(camerax,cameray,cameraz, -cameraDx,-cameraDy,0,0,1,0);
   glRotatef(cameraangle,camerarotx,cameraroty,camerarotz);        // Rotate
The Camera

But that gave the same results.

Any help would be much appreciated!

-Rob

2. ANNOUNCE: Magician for OS/2 Warp 4 Released!

3. POV-Ray 3.1 : Returning a value!

4. GI with C4D

5. returned from-0 value-2 days in-help!

6. Mixed inputs - glutMouseFunc() etc.... FAO esp Nate Miller , but all others 2!

7. what gversion values can an O2 return?

8. Development of Gizmo3D Transfered to ToolTech Software

9. max return value ...

10. Odd return values from LScript Control Objects.

11. Return-Value of function

12. Values returned from glReadPixels slightly off.

13. Click Return Value