gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *objx, GLdouble *objy, GLdouble *objz)...{ double finalMatrix[16]; double in[4]; double out[4]; __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE); in[0]=winx; in[1]=winy; in[2]=winz; in[3]=1.0; /**//* Map x and y from window coordinates */ in[0] = (in[0] - viewport[0]) / viewport[2]; in[1] = (in[1] - viewport[1]) / viewport[3]; /**//* Map to range -1 to 1 */ in[0] = in[0] * 2 - 1; in[1] = in[1] * 2 - 1; in[2] = in[2] * 2 - 1; __gluMultMatrixVecd(finalMatrix, in, out); if (out[3] == 0.0) return(GL_FALSE); out[0] /= out[3]; out[1] /= out[3]; out[2] /= out[3]; *objx = out[0]; *objy = out[1]; *objz = out[2]; return(GL_TRUE);} static void __gluMultMatrixVecd(const GLdouble matrix[16], const GLdouble in[4], GLdouble out[4])...{ int i; for (i=0; i<4; i++) ...{ out[i] = in[0] * matrix[0*4+i] + in[1] * matrix[1*4+i] + in[2] * matrix[2*4+i] + in[3] * matrix[3*4+i]; }}