PDA

View Full Version : picking problem



newasun
05-24-2005, 02:16 AM
I have drawn two objects in opengl. I want to select the object by which I can zoom and move each object individually. Following is my code I couldnt get feedback from pick. Is it the right way to do it.


void CViewerView::display()
{
glInitNames();
glPushName(0);
glPushMatrix();
glLoadName(1);
draw_line();
glLoadName(2);
drawTri();
glPopMatrix();
glPopName();
}

void CViewerView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_RightButtonDown = TRUE;
m_RightDownPos= point;

glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(BUFSIZE,selectBuf);
glRenderMode(GL_SELECT);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix ((GLdouble) point.x/100, (GLdouble) point.y/100,1.0, 1.0, viewport);
gluPerspective(30.0, (GLfloat) 10/ (GLfloat) 10, 1.0, 10.0);

glMatrixMode(GL_MODELVIEW);
draw_line();
drawTri();
glPopMatrix ();
glFlush ();
//hits = glRenderMode (GL_RENDER);
//processHits (hits, selectBuf);
//glutPostRedisplay();
CView::OnRButtonDown(nFlags, point);
TRACE2("MOUSE DOWN! x=%d, y=%d\n",hits, point.y);
}

147-2
05-24-2005, 04:31 PM
Apparently, you are not sending the names in your picking code. Rather than doing a seperate draw, you should use the same code, just in a different mode. You are sending the names during your display run, but you need to do that for your picking run.

newasun
05-24-2005, 05:33 PM
I tried putting the display() code in button event but its not working. I tried following way but the object diappears when I click.



void CViewerView::drawPobj(GLenum mode)
{

if(mode==GL_SELECT)
glLoadName(1);
draw_line();
if(mode==GL_SELECT)
glLoadName(2);
drawTri();
InvalidateRect(NULL,FALSE);
}
void CViewerView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_RightButtonDown = TRUE;
m_RightDownPos= point;

glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(BUFSIZE,selectBuf);
(void)glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix ((GLdouble) point.x/100, (GLdouble) (viewport[3]-point.y/100),5.0, 5.0, viewport);
gluPerspective(30.0, (GLfloat) 10/ (GLfloat) 10, 1.0, 10.0);
// gluPerspective(30.0, 0.0, 1.0, 10.0);

drawPobj(GL_SELECT);
glMatrixMode(GL_MODELVIEW);
/*glLoadName(1);
draw_line();
glLoadName(2);
drawTri();*/
glPopMatrix ();
glFlush ();
hits = glRenderMode (GL_RENDER);
//processHits (hits, selectBuf);
//glutPostRedisplay();
CView::OnRButtonDown(nFlags, point);
TRACE2("MOUSE DOWN! x=%d, y=%d\n",hits, point.y);
}

mikael_aronsson
05-24-2005, 09:11 PM
Why /100 ???

"gluPickMatrix ((GLdouble) point.x/100, (GLdouble) (viewport[3]-point.y/100),5.0, 5.0, viewport);"

The X and Y to gluPickMatrix should be in window coordinates.

Mikael

newasun
05-24-2005, 09:23 PM
I removed 100 only opengl window is refreshing but still i cant get hit.