stefboombastic

01-03-2003, 01:35 AM

Hello everybody http://www.opengl.org/discussion_boards/ubb/smile.gif

I'm trying to solve this problem since several days, I searched a lot of threads, but I couldn't manage to get rid of it yet http://www.opengl.org/discussion_boards/ubb/frown.gif

I use the same code showed in all the threads dealing about this problem:

//I got the mouse position, and invert the Y

GLfloat Y=ClientWindowWidth-MouseY;

GLfloat X=MouseX;

//then I get the Z by looking into the Z buffer:

GLdouble Z;

glReadPixels(X, Y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Z);

//then I use this code to get the 3d coordinates

GLdouble objx,objy,objz;

GLint viewport[4];

GLdouble modelMatrix[16];

GLdouble projMatrix[16];

glGetIntegerv(GL_VIEWPORT, viewport);

glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);

glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);

gluUnProject(X, Y, Z , modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

But the coordinates I get are very low, they seems to be the ones at Near Clip Plane (I use a Perspective projection with

fovy=45, NearPlane=1 and FarPlane=200)

But my object was about at z=-100 ...How can I get the correct coordinates, or map the ones I got at z=-100 ???

I really Thank You in advance...Please HELP http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif

Stefano B.

I'm trying to solve this problem since several days, I searched a lot of threads, but I couldn't manage to get rid of it yet http://www.opengl.org/discussion_boards/ubb/frown.gif

I use the same code showed in all the threads dealing about this problem:

//I got the mouse position, and invert the Y

GLfloat Y=ClientWindowWidth-MouseY;

GLfloat X=MouseX;

//then I get the Z by looking into the Z buffer:

GLdouble Z;

glReadPixels(X, Y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Z);

//then I use this code to get the 3d coordinates

GLdouble objx,objy,objz;

GLint viewport[4];

GLdouble modelMatrix[16];

GLdouble projMatrix[16];

glGetIntegerv(GL_VIEWPORT, viewport);

glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);

glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);

gluUnProject(X, Y, Z , modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

But the coordinates I get are very low, they seems to be the ones at Near Clip Plane (I use a Perspective projection with

fovy=45, NearPlane=1 and FarPlane=200)

But my object was about at z=-100 ...How can I get the correct coordinates, or map the ones I got at z=-100 ???

I really Thank You in advance...Please HELP http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif

Stefano B.