的在opengl下從鼠標座標轉換到三維座標的方法

通常用來拾取物體: fPoint CMy3D_SurfaceView::Get_3D_pos(CPoint Tpoint) {     CMy3D_SurfaceDoc *pDoc=(CMy3D_SurfaceDoc*)GetDocument();     fPoint Rp;     GLint viewport[4];     GLdouble modelview[16];     GLdouble projection[16];     GLfloat winX,winY,winZ;     GLdouble posX,posY,posZ;     glPushMatrix();     glTranslatef(TransVect[0],TransVect[1],TransVect[2]);     if(pDoc->Init)roty=0.0f;     glRotatef(roty+20.0f,0.0f,1.0f,0.0f);     glScalef(scalx,scaly,scalz);     glGetIntegerv(GL_VIEWPORT,viewport);     glGetDoublev(GL_MODELVIEW_MATRIX,modelview);     glGetDoublev(GL_PROJECTION_MATRIX,projection);     glPopMatrix();     winX=(float)Tpoint.x;     winY=viewport[3]-(float)Tpoint.y;     glReadPixels((int)winX,(int)winY,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&winZ);//獲取鼠標屏幕座標處像素的深度Z     gluUnProject(winX,winY,winZ,modelview,projection,viewport,&posX,&posY,&posZ);          Rp.x=posX;     Rp.y=posY;     Rp.z=posZ;     return Rp; }  
相關文章
相關標籤/搜索