#### Archived

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

# OpenGL single Point picking

This topic is 5458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002279
×