Hi i have been having this problem for a while now…my program records a hit when certain areas on the scene are clicked, but does not record a hit when any of the models are clicked, and is highly inaccurate, don’t know what else I can do, read probably every article on picking still cant figure out what the problem is…please I need your ideas on what could be causing this problem
this is what my code looks like
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glLoadIdentity();
//glPushMatrix();
//glTranslatef(0.0, 0.0, -500.0);
glPushMatrix();
glTranslatef(-pan_x,-pan_y, -500.0);
/*
//rotate about y axis now the x axis is changed.
glRotatef(angle[0], 1, 0, 0);
glRotatef(angle[1], 0, 1 ,0 );
glRotatef(angle[1], 0, 0 ,1 );
*/
gltbMatrix();
//draw the object
drawReflector(GL_RENDER);
glPopMatrix();
glPushMatrix();
glTranslatef(-pan_x,-pan_y, -500.0);
gltbMatrix();
drawMast(GL_RENDER);
glPopMatrix();
glPushMatrix();
glTranslatef(-pan_x,-pan_y, -500.0);
gltbMatrix();
drawReceiver(GL_RENDER);
glPopMatrix();
glPushMatrix();
glTranslatef(-pan_x,-pan_y, -500.0);
gltbMatrix();
drawConnector(GL_RENDER);
glPopMatrix();
glPushMatrix();
glTranslatef(-pan_x,-pan_y, -500.0);
gltbMatrix();
drawChessPawn(GL_RENDER);
glPopMatrix();
glPushMatrix();
glTranslatef(-pan_x,-pan_y, -500.0);
gltbMatrix();
drawStand(GL_RENDER);
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void selection(int x, int y)
{
GLuint buff[512] = {0};
GLint hits, view[4];
glSelectBuffer(256, buff); //This chooses the buffer where store the values for the selection data
glGetIntegerv(GL_VIEWPORT, view); //This retrieve info about the viewport
glRenderMode(GL_SELECT); // Switching in selecton mode
glInitNames();// Clearing the name's stack
glPushName(0); //filling the stack with one element
glMatrixMode(GL_PROJECTION); // Now modify the vieving volume, restricting selection area around the cursor
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble)x,(GLdouble) (view[3] - y),1.0,1.0,view);
gluPerspective(45.0f,(float)view[2]/(float)view[3],1.0,1500.0);
//gluPickMatrix((GLdouble)x,(GLdouble) (view[3] - y),1.0,1.0, view); //restrict the draw to an area around the cursor
//gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f);
glMatrixMode(GL_MODELVIEW); // Draw the objects onto the screen
glutSwapBuffers(); //draw only the names in the stack, and fill the array
render(GL_SELECT);
//drawReflector(GL_SELECT);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
/*
this will help us get the number of objects drawed in that area
and return to render mode
*/
hits = glRenderMode(GL_RENDER);
list_hits(hits, buff); // Print a list of the objects
//selectAll(hits, buff);
glMatrixMode(GL_MODELVIEW);
}
thank you very much for your help