opengl拾取的问题
我要做的是拾取一个长方体,hits总是0,怎么回事啊。
是不是我的gluPerspective语句不对啊,该怎么设置?
Draw(GL_SELECT)这个函数是不是要在要选择的长方体所在位置重画啊?
谢谢!代码如下:
#define BUFFER_LENGTH 512
void ProcessSelection(CPoint point)
{
GLuint buffer[BUFFER_LENGTH];
GLint hits;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(BUFFER_LENGTH, buffer);
(void) glRenderMode(GL_SELECT);
glInitNames();
glPushName(-1);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble)point.x,(GLdouble)(viewport[3]-point.y),5.0f,5.0f,viewport);
gluPerspective(45.0f,(GLfloat)(viewport[2]-viewport[0])/(GLfloat)(viewport[3]-viewport[1]), 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW); glPushMatrix();
glLoadIdentity();
Draw(GL_SELECT);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
hits=glRenderMode(GL_RENDER);
}
void Draw(GLenum mode)
{
ArPose pose=m_Robot.getPose();
glPushMatrix();
if(mode==GL_SELECT)
glLoadName(1);
glTranslated(pose.getX(),pose.getY(),HEIGHT/2);//平移到长方体原来所在的位置
glRotatef(pose.getTh(),0,0,1);
auxSolidBox(300,300,500);
glPopMatrix();
}
[解决办法]
http://blog.csdn.net/xlzxlich/archive/2007/06/05/1639780.aspx