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

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.

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

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

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.

Hi dletozeun,

Here’s my code

``````// Set Viewport to window dimensions
Gl.glViewport(0, 0, width, height);
// Reset projection matrix stack
Gl.glMatrixMode(Gl.GL_PROJECTION);