how to get the real 3d cordinate

i want get the real 3d cordinate by clicking, but how can i do?
i know the "gluUnProject"function,but the return value is not correct.where this function should be put.
i put i at the mouse event
gluUnProject((double)point.x,(double)point.y,1.0,…,&realX,&realY,&realZ)
and what’s meaning of the third parameter of this function?

The depth at the given pixel in your viewport is one way to interpretate the value.

Since it’s mathematically impossible to convert a 2D point to one signel unique 3D point, you must add one more coordinate, and that corodinate is the third parameter.

1.0 gives you a point on the far clipping plane, and 0.0 on the near clipping plane. A value between 0.0 and 1.0 gives a point on the line between the point on the near and far plane.

…and you get the third coordinate with glReadPixels on the depth buffer at that coordinate.

Kilam.

i am sorry that i don’t know how to use the function of glReadPixels ,can u give some code? 3x a lot

For a given x and y position in the OpenGL window this flips the y coordinate and reads the depth value from the z-buffer.

GLfloat pixel;

x = x;
y = drawSizeY - y;

glReadPixels(x - 1, y -1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, pixel);

Kilam.

[This message has been edited by Kilam Malik (edited 11-06-2001).]

there still have some problems,my code as follows:

OnButtonDown{

CRect clientRect;
GetClientRect( &clientRect );
,GL_FLOAT, &m_Up);
getRealCordinate( point.x, clientRect.Height()-/**/point.y, m_Up);
}

BOOL CEarthRView::getRealCordinate(GLdouble wndX, GLdouble wndY, GLdouble wn
dZ)
{
glMatrixMode(GL_MODELVIEW);
glGetDoublev(GL_MODELVIEW_MATRIX ,modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX ,projMatrix);
glGetIntegerv(GL_VIEWPORT,viewport);

``````    gluUnProject(wndX,wndY,wndZ,modelMatrix,projMatrix,viewport,&m_dRealX,&m
``````

ealY,&m_dRealZ);
RealToLCordinate(m_dRealX,m_dRealY,m_dRealZ);
return TRUE;
}
void CEarthRView::RealToLCordinate(double realX, double realY, double realZ)

{
CString str1,str2,str3;
str1.Format("%f",realX);
str2.Format("%f",realY);
str3.Format("%f",realZ);
AfxMessageBox(str1+"
“+str2+”
"+str3);
}

when the picture first appeared,i can get the true real 3d codinates,but when the picture is transfomed,i can not get the right result.
i think gluUnProject function should be used at the location between transfomation and drawing,but i want get the 3d cordinates by mouse clicking ,how can i get it?

god save me
when i rotate,i can get the right 3d coordinate,but when i zoom ,the result is not right ,why?

glMatrixMode(GL_MODELVIEW);
glGetDoublev(GL_MODELVIEW_MATRIX ,modelMatrix);

hehe u set the matrix to identity + then ask what is the matrix set to, nice one
u need to have the SAME matrixs for the gluunproject function as what youve used to draw on the screen (which most likely aint the identity matrix esp if youve moved the camera)

check the red book or glut or (maybe) the faq for an example of using gluunproject

when zoom ,the returned vlaue is same as the glRotate scale

to zed