GLdouble x=0; GLdouble y=0; GLdouble z=0; GLdouble model[16]; glGetDoublev(GL_MODELVIEW,model); GLdouble proj[16]; glGetDoublev(GL_PROJECTION,proj); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT,viewport); for(int i=0; i<4; i++) cout << "viewport [" << i << "] = " << viewport << endl; for(int i=0; i<16; i++) cout << "model [" << i << "] = " << model << endl; for(int i=0; i<16; i++) cout << "proj [" << i << "] = " << proj << endl; cout << "# Unprojecting win x: " << winX << " win y: " << winY<< " win z: " << 1 << endl; if(!gluUnProject(winX, winY, (GLdouble)1.0, model, proj, viewport, &x,&y,&z)){ cout << "Unprojection failed. " << endl; return new ThetaTriplet(0,0,0); }; cout << "x: " << x << " y: " << y << " z: " << z << endl;
here's the ouput: (i've edited theoutput tu make matrices easier to read but didn't change any value)
viewport
0,0, 640, 480
model
-0.229924, 0,-0.973209 0,
0, 1 0, 0,
0.973209, 0, -0.229924, 0
4.86604, 0, -1.14962, 1
proj
-2.38424e+11, 1.12335e-314, -2.38424e+11, -2.38424e+11
2.18976e-308, 2.85328e-306, 2.30959e-317, -3.01703e-273
2.29895e-307,-1.99692,-1.99692,-3.23797e-232
2.30959e-317, -3.01703e-273, -1.99692, 6.88044e-308
# Unprojecting win x: 290 win y: 157 win z: 1
results:
x: 0.233788 y: 5.02861e+272 z: -4.94477
if i click many times it continues this way, with different matrices depending on where the camera's looking at and different window coords depending on where i clicked, however when at a static location clicking on different window coords prints different win coords but same results.
ouput examples: (all at the same location and with the same matrices)
# Unprojecting win x: 524 win y: 361 win z: 1
x: 1.00004 y: 8.37584e-12 z: -5
# Unprojecting win x: 90 win y: 115 win z: 1
x: 1.00004 y: 8.37584e-12 z: -5
# Unprojecting win x: 501 win y: 145 win z: 1
x: 1.00004 y: 8.37584e-12 z: -5