Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: picking problem

  1. #1
    Junior Member Newbie
    Join Date
    May 2005
    Location
    ktm
    Posts
    12

    picking problem

    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.

    Code :
    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);
    }
    newasun

  2. #2
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    San Diego, CA, USA
    Posts
    209

    Re: picking problem

    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2005
    Location
    ktm
    Posts
    12

    Re: picking problem

    I tried putting the display() code in button event but its not working. I tried following way but the object diappears when I click.
    Code :
     
    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);
    }
    newasun

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: picking problem

    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

  5. #5
    Junior Member Newbie
    Join Date
    May 2005
    Location
    ktm
    Posts
    12

    Re: picking problem

    I removed 100 only opengl window is refreshing but still i cant get hit.
    newasun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •