|
我想实现opengl场景中对象拾取功能,视点不变即初始场景时可以选取物体,但视点变化之后选中不了,各位高手帮我看看
void CScene: rocessSelection (CPoint point)
{
GLuint selectBuf[BUFSIZE];//create the selection buffer
GLint hits;
GLint viewport[4];//create a viewport
int x=0;
int y=0;
x=point.x;
y=point.y;
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (BUFSIZE, selectBuf);
(void) glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
glPopName();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//setup a pick matrix
gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
5, 5, viewport);
GLdouble aspect(0);
aspect=(GLdouble)viewport[2]/(GLdouble)viewport[3];
//gluPerspective(45.0f, aspect, .01f, 200.0f);
gluPerspective(45.0f, aspect, 0.1,10);
Render(GL_SELECT);// Draw to the pick matrix instead of our normal one
glMatrixMode (GL_PROJECTION);
glPopMatrix ();
glFlush ();
hits = glRenderMode (GL_RENDER);
ProcessObject (selectBuf);
} |
|