Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. void screenToWorld(int x, int y){
  2.  
  3.     GLint viewport[4];
  4.     GLdouble projection[16];
  5.     GLdouble pX, pY, pZ;
  6.     GLfloat winx, winy, winz;
  7.    
  8.     glGetDoublev(GL_PROJECTION_MATRIX, projection);
  9.    
  10.  
  11.     viewport[0] = 0;
  12.     viewport[1] = 0;
  13.     viewport[2] = window_width / 2;
  14.     viewport[3] = window_height;
  15.  
  16.    
  17.     winx = (float)x;
  18.     winy = (float)viewport[3] - (float)y;
  19.    
  20.     //glReadPixels(x, int(winy), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winz);
  21.  
  22.    
  23.     winz = 3000; // o far é 3000
  24.  
  25.     gluUnProject(winx, winy, winz, modelview, projection, viewport, &pX, &pY, &pZ);
  26.  
  27.  
  28.     posFar[0] = pX;
  29.     posFar[1] = pY;
  30.     posFar[2] = pZ;
  31.  
  32.     winz = 1; // o near é 1
  33.  
  34.     gluUnProject(winx, winy, winz, modelview, projection, viewport, &pX, &pY, &pZ);
  35.     posNear[0] = pX;
  36.     posNear[1] = pY;
  37.     posNear[2] = pZ;
  38.  
  39.     printf("NEAR: tela-> x: %d y: %d mundo-> x: %d y: %d z: %d\n", x, y, posNear[0], posNear[1], posNear[2]);
  40.     printf("FAR: tela-> x: %d y: %d mundo-> x: %d y: %d z: %d\n", x, y, posFar[0], posFar[1], posFar[2]);
  41.  
  42.  
  43.  
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement