Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. Vector3<double> getOGLPos(int x, int y)
  2. {
  3. GLint viewport[4];
  4. GLdouble modelview[16];
  5. GLdouble projection[16];
  6. GLfloat winX, winY, winZ;
  7. GLdouble posX, posY, posZ;
  8.  
  9. glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
  10. glGetDoublev( GL_PROJECTION_MATRIX, projection );
  11. glGetIntegerv( GL_VIEWPORT, viewport );
  12.  
  13. winX = (float)x;
  14. winY = (float)viewport[3] - (float)y;
  15. glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
  16.  
  17. gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
  18.  
  19. return Vector3<double>(posX, posY, posZ);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement