openGL中的gluUnProject函数

时间:2009-11-27 19:09:01

标签: opengl

下面的代码给了我一个错误,我无法理解它。

GLdouble objX,objY,objZ;
GLdouble modelview1[4][4], projection1[4][4];
GLint viewport1[4]; 
glGetDoublev( GL_MODELVIEW_MATRIX, *modelview1 );
glGetDoublev( GL_PROJECTION_MATRIX, *projection1 );
glGetIntegerv( GL_VIEWPORT, viewport1 );

gluUnProject(x, y, z, modelview1, projection1, viewport1,  objX , objY ,  objZ);`

错误:

 error C2664: 'gluUnProject' : cannot convert parameter 4 from 'GLdouble [4][4]' to 'const GLdouble []'

1 个答案:

答案 0 :(得分:3)

似乎变量modelview1和projection1的类型错误。

我找到了以下代码段(此处http://www.3dkingdoms.com/selection.html):

// This function will find 2 points in world space that are on the line into the screen defined by screen-space( ie. window-space ) point (x,y)
   double mvmatrix[16];
   double projmatrix[16];
   int viewport[4];
   double dX, dY, dZ, dClickY; // glUnProject uses doubles, but I'm using floats for these 3D vectors

   glGetIntegerv(GL_VIEWPORT, viewport);    
   glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
   glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
   dClickY = double (g_WindowHeight - y); // OpenGL renders with (0,0) on bottom, mouse reports with (0,0) on top

   gluUnProject ((double) x, dClickY, 0.0, mvmatrix, projmatrix, viewport, &dX, &dY, &dZ);
   ClickRayP1 = Vector3 ( (float) dX, (float) dY, (float) dZ );
   gluUnProject ((double) x, dClickY, 1.0, mvmatrix, projmatrix, viewport, &dX, &dY, &dZ);
   ClickRayP2 = Vector3 ( (float) dX, (float) dY, (float) dZ );