gluUnProject() - how to get the right modelview matrix

Hi,

in my scene there is only one model. I would like to project a point onto this model - this works as long as I don’t move or rotate the model. How do I get the right matrix?? Because my point after rotating is always outside of the model and not anywhere where it is supposed to be.
What I do now is like that:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(GLTranslateX, 0.0, 0.0);
glTranslated(0.0, GLTranslateY, 0.0);
glTranslated(0.0, 0.0, GLTranslateZ );
glGetDoublev( GL_MODELVIEW_MATRIX, dmodel );
glPushMatrix();
glRotated(GLRotateX,1.0,0.0,0.0);
glRotated(GLRotateY,0.0,1.0,0.0);
// drawing here
glMultMatrixd(dmodel);
glGetDoublev( GL_MODELVIEW_MATRIX, dmodel );
glPopMatrix();//Transform
glPopMatrix();//Rotate

I tried several placements of glGetDoublev and glMultMatrixd but none of them gave me the right result.
I thought this is the way to go, since after each glPopMatrix I go one transformation back in the stack.
Hope somebody can help me out with this misery!

Martin

You should get the matrix at the same point as where you darw the model. In your code, you make some transformations (three translates and two rotates) before drawing your model, but then you apply even more transrformations before getting the matrix. You now have different matrices that will transform the object and the point to unproject (even though the unprojection is “backward” with the inverse of the matirces, but still different matrices), and no wonder you get strange result.

Remove the glMultMatrix call and see if it helps, cause this is the line, in this code, that mess up the matrix.

Hi,

thanks. I thought I need all the transformation matrices multiplied up, to get the right result. I will try whether it helps.

Martin