PDA

View Full Version : gluUnProject / gluPerspective / glTanslatef problem



Mat
05-07-2002, 05:08 AM
Hi,

I used gluUnprojet to pick up the object coordinates where the user clicked in my window..

I do not arrive to obtain the good values.

- I calculate at the beginning of the program a Z value that will place the camera in order to see all the object Z=-431 for the object I'm actually using. After the user can change the Z value in order to give a zoom impression on the object. I use glTranslate for moving the camera..

- I set up the the gluperspective like this:
glu.gluPerspective(Angle_View_Degree, width/height, 10.0f, 500.0f);
in order to zoom on the object. If I give a Z value between -10 and -500 I can see the object.

- The gluUnproject is initialised like this:
glu.gluUnProject((double)X,(double)Y,depthbuffer[0],mvmatrix,projmatrix,viewport,x,y,z)
I don't think the problem comes from here..

Now with this configuration I can't get the corrects object points and Z=421...

I think there is something I don't understand in the configuration of gluPerspective combined with changing the Z value with glTranslate..

Anyone has an idea
Thanks for your help
Mat

Furrage
05-07-2002, 07:17 AM
The z in gluUnproject should be between 0 and 1 and is scaled by OpenGL such that 0 maps to zNear (10 in your case) and 1 maps to zFar (500 in your case). So the z you would want to use is something like (421 - 10) / (500 - 10).

[This message has been edited by Furrage (edited 05-07-2002).]

Mat
05-07-2002, 07:24 AM
Originally posted by Furrage:
The z in gluUnproject should be between 0 and 1 and is scaled by OpenGL such that 0 maps to zNear (10 in your case) and 1 maps to zFar (500 in your case). So the z you would want to use is something like (500 - 421) / (500 - 10).

Hi I just noticed that and I tried to put my zFar at -250 and put the value of z at 0.5 but it did not work !! But it worked correctly if I use zFar -500 and z at 1 or zFar -10 and z at 0 !!

It must be proportionaly normaly !!

Thanks for your help
Mat