Still problem with gluUnProject

Hi,

I still can’t use the gluUnProject Method in my program. In fact it works perfectly with in glOrtho mode but it failed in gluPerspective mode… Here is the output of my matrix I printed:

300 303 // Point X Y clicked
Viewport: 0 0 600 600 // viewport matrix
MvMatrix: 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 //modelisation matrix
ProjMatrix: 11.430052757263184 0.0 0.0 0.0 0.0 11.430052757263184 0.0 0.0 0.0 0.0 -1.0 -1.0 0.0 0.0 0.0 0.0 //projection matrix
0 //value returned by gluUnproject = GL_FAILED
X:0.0 Y:0.0 Z:0.0 = Values of each point at 0

My function is :
glu.gluUnProject((double)X,(double)Y,0.2,mvmatrix,projmatrix,viewport,x,y,z) and I don’t need the pointer sign & because it’s Java

Is there anyone who has an idea
Thanks a lot
MAt

Hello,

your projection matrix is singular; that is, one of the rows is a linear combination of another, and so you’ve effectively “lost” one of your equations.

You said your proj matrix was this:

ProjMatrix: 11.430052757263184 0.0 0.0 0.0 0.0 11.430052757263184 0.0 0.0 0.0 0.0 -1.0 -1.0 0.0 0.0 0.0 0.0

which, if you write in a matrix like form, you get this:

11.4 0.0  0.0  0.0
0.0 11.4  0.0  0.0
0.0 0.0  -1.0  0.0
0.0 0.0  -1.0  0.0

(you need to transpose the matrix, btw; if you don’t, then you end up with w’==0.0 forall w!!). Unfortunately, your fourth column is a linear combination of the third: this means you cannot find an inverse for this matrix.

The opengl projection matrix SHOULD look like this:

const float projmatrix[16]={
    (2.0*n)/(r-l), 0.0,         (r+l)/(r-l),  0.0,
    0.0,           (2*n)/(t-b), (t+b)/(t-b),  0.0,
    0.0,           0.0,         -(f+n)/(f-n), -(2.0*f*n)/(f-n),
    0.0,           0.0,         -1.0,         0.0 
  };

so, you’d better check how you’re defining your matricies.

hope this helps
cheers
John