View Full Version : how to get the real 3d cordinate

ruixp

11-05-2001, 02:27 AM

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.

Kilam Malik

11-05-2001, 04:39 AM

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

Kilam.

ruixp

11-06-2001, 02:53 AM

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

Kilam Malik

11-06-2001, 04:35 AM

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).]

ruixp

11-06-2001, 02:54 PM

there still have some problems,my code as follows:

OnButtonDown{

..

CRect clientRect;

GetClientRect( &clientRect );

glReadPixels(point.x-1,clientRect.Height()-point.y-1,1,1,GL_DEPTH_COMPONENT

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

glLoadIdentity();

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+"\n"+str2+"\n"+str3);

}

ruixp

11-07-2001, 03:24 AM

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?

ruixp

11-10-2001, 09:18 PM

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

glLoadIdentity();

glGetDoublev(GL_MODELVIEW_MATRIX ,modelMatrix);

hehe u set the matrix to identity + then ask what is the matrix set to, nice one http://www.opengl.org/discussion_boards/ubb/wink.gif

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

ruixp

11-12-2001, 03:14 PM

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

ruixp

11-14-2001, 02:46 AM

to zed

can u speek detailly please?

ruixp

11-15-2001, 08:05 PM

i delete the glPushMarix() and glPopMatrix()

then i get the right result http://www.opengl.org/discussion_boards/ubb/smile.gif

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.