View Full Version : Tiny difference in Z coordinate

Exoide

10-01-2009, 06:42 AM

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.

plasmonster

10-01-2009, 11:21 AM

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.

Exoide

10-02-2009, 07:04 AM

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.

dletozeun

10-02-2009, 03:21 PM

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.

Exoide

10-05-2009, 09:55 AM

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

glLoadIdentity();

// 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);

glLoadIdentity();

// Set the camera's position

gluLookAt(30, 20, 20, 0, 0, 0, 0, 0, 1)

Thanks in advance

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.