PDA

View Full Version : Z in mouse selection!



silver_angel
11-29-2003, 07:32 AM
I don't know why, when I use GL_SELECT. The buffer[] alway return the z1 and z2 = 0 (The names is OK!).
Could you tell how can I use this for my program? How can I recognize which object is the nearest when I use selection?

My code for selection :

{
GLuint selectBuf[4096];
GLint hits;
GLint viewport[4];

glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (4096, selectBuf);

glRenderMode(GL_SELECT); glInitNames();
glPushName(-1);

glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
gluPickMatrix((GLdouble)x, (GLdouble) (viewport[3] -y), m_pickLessExact, m_pickLessExact, viewport);
gluPerspective(m_seeAngle,m_dblAspect,m_seeNearest ,m_seeFarthest);
glMatrixMode(GL_MODELVIEW);
m_tc.Draw(GL_SELECT);
glPopMatrix ();
glFlush ();

hits = glRenderMode (GL_RENDER);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,m_intWidth,m_intHeight);
gluPerspective(m_seeAngle,m_dblAspect,m_seeNearest ,m_seeFarthest);

int n=0;
if (hits)
{
double minz=selectBuf[1];
[0],selectBuf[1],selectBuf[2]);
for(int i=1;i<hits;i++)
{
if (selectBuf[1+i*4]<minz) {n=i;minz=selectBuf[1+i*4];}
}
*miss=FALSE;
}
else
{
*miss=TRUE;
return 0;
}
return selectBuf[3+n*4];
}
-> Does not return the nearest!