This topic is now archived and is closed to further replies.


OpenGL single Point picking

Recommended Posts

Laird    122
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

Share this post

Link to post
Share on other sites