Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void screenToWorld(int x, int y){
- GLint viewport[4];
- GLdouble projection[16];
- GLdouble pX, pY, pZ;
- GLfloat winx, winy, winz;
- glGetDoublev(GL_PROJECTION_MATRIX, projection);
- viewport[0] = 0;
- viewport[1] = 0;
- viewport[2] = window_width / 2;
- viewport[3] = window_height;
- winx = (float)x;
- winy = (float)viewport[3] - (float)y;
- //glReadPixels(x, int(winy), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winz);
- winz = 3000; // o far é 3000
- gluUnProject(winx, winy, winz, modelview, projection, viewport, &pX, &pY, &pZ);
- posFar[0] = pX;
- posFar[1] = pY;
- posFar[2] = pZ;
- winz = 1; // o near é 1
- gluUnProject(winx, winy, winz, modelview, projection, viewport, &pX, &pY, &pZ);
- posNear[0] = pX;
- posNear[1] = pY;
- posNear[2] = pZ;
- printf("NEAR: tela-> x: %d y: %d mundo-> x: %d y: %d z: %d\n", x, y, posNear[0], posNear[1], posNear[2]);
- printf("FAR: tela-> x: %d y: %d mundo-> x: %d y: %d z: %d\n", x, y, posFar[0], posFar[1], posFar[2]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement