OpenGL single Point picking
Hi!
I''ve a problem! i want to pick a single point! the X and Y coordinates are ok, but i get the wrong z-value! here is my c++-code:
wx=0;wy=0;wz=0;
LX->Caption = X-FrMain->ClientWidth/2;
LY->Caption = Y-FrMain->ClientHeight/2;
float depth;
GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
GLint realy = viewport[3] - (GLint) Y - 1;
glReadPixels(X,realy,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&depth);
gluUnProject ((GLdouble) X, (GLdouble) realy, depth,
mvmatrix, projmatrix, viewport, &wx, &wy, &wz);
if(depth!=1)
{
wx = (wx+minx)+(dimx/2);
wy = (wy+miny)+(dimy/2);
wz = (wz)+(2*dimz);
}else
{
wx = 0;
wy = 0;
wz = 0;
}
LX->Caption = wx;
LY->Caption = wy;
LZ->Caption = wz;
maybe someone has/had the same problem!
Thanks
Laird
Do you have MFC? If so, I have a demo on my site that might be what you''re looking for. I notice you''re doing math to change coordinates, I didn''t do any of that, I just did it straight and it seems to work.
Love means nothing to a tennis player
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement