# Thread: Tiny difference in Z coordinate

1. ## Tiny difference in Z coordinate

Hi there,

I'm doing a project using the perspective projection. I've a camera located at (20, 20, 20) looking at (0, 0, 0).

When I try to get the coordinates in the nearest plane using gluUnproject(mouseX, height - mouseY, 0, ...) I get (someX, someY, 19.5).

The question is why I get in Z some slightly difference? I was expecting to get 20 in Z because it must be the nearest plane.

Can someone explain me why I get such difference?

Thanks.

2. ## Re: Tiny difference in Z coordinate

You'll probably need to take the near plane distance into account, if you're looking for the world position coinciding with the camera position, say, with a winz of 0.

3. ## Re: Tiny difference in Z coordinate

You'll probably need to take the near plane distance into account, if you're looking for the world position coinciding with the camera position, say, with a winz of 0.
Yes, that's what I'm doing; the third parameter in gluUnproject is zero (WinZ) in the example I posted before

Code :
`gluUnproject(mouseX, height - mouseY, 0, ...)`

But I'm getting some difference in Z. It looks like the camera is a little behind the frustrum but I don't know if it's ok.

4. ## Re: Tiny difference in Z coordinate

How do you set up modelview and projection matrices?
gluUnproject returns coordinates in object space. You may have to transform again these coordinates by the modelview matrix to get coordinates in eye space.

5. ## Re: Tiny difference in Z coordinate

Hi dletozeun,

Here's my code

Code :
```// Set Viewport to window dimensions
Gl.glViewport(0, 0, width, height);
// Reset projection matrix stack
Gl.glMatrixMode(Gl.GL_PROJECTION);
// Establish the projection
if (width > height)
gluPerspective(fovY * height / width, width / height, nearPlane, farPlane);
else
gluPerspective(fovY, width / height, nearPlane, farPlane);
// Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);