Results 1 to 3 of 3

Thread: picking

  1. #1
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    2

    picking

    I am drawing a rectangle and I need to pick it. It works fine but if I rotate or translate the rectangle I cannot pick anymore.
    Here is the code.
    Code :
     void GLWidget::ProcessSelection(int x, int y)
    {
    	static GLuint selectBuffer[512];
    	GLint hits;
    	GLint viewport[4];
     
    	glSelectBuffer(512, selectBuffer);
    	glGetIntegerv(GL_VIEWPORT, viewport);
    	glMatrixMode(GL_PROJECTION);
    	glPushMatrix();
    	(void) glRenderMode(GL_SELECT);
    	glLoadIdentity();
    	gluPickMatrix(x, viewport[3]-y, 5, 5, viewport);
    	glOrtho(-1.5, 1.5, -1.5, 1.5, -1000, 1000);
    	glInitNames();
    	glPushName(0);
    	//Rectangle to pick
    	drawSliceRect(GL_SELECT);
    	hits = glRenderMode(GL_RENDER);
    	glMatrixMode(GL_PROJECTION);
    	glPopMatrix();
    	glMatrixMode(GL_MODELVIEW);
     
    	qDebug() << hits << endl;
    }
    And code for rectangle:
    Code :
     void GLWidget::drawSliceRect(GLenum mode)
    {
     
    	glEnable(GL_LINE_SMOOTH);
    	// displacement range [-1, 1];
    	glColor3f(1.0, 1.0, 1.0);
    	glPushMatrix();
    	if(mode == GL_SELECT)
    		glLoadName(1);
    	switch(mCurSliceDirection)
    	{
    		case X:
    			glRotatef(90, 0.0, 1.0, 0.0);
    			glTranslatef(0.0, 0.0, mSliceDisplacement);
    			break;
    		case Y:
    			glRotatef(90, 1.0, 0.0, 0.0);
    			glTranslatef( 0.0, 0.0, -mSliceDisplacement);
    			break;
    		case Z:
    			glTranslatef(0.0, 0.0, mSliceDisplacement);
    			break;
    		default:
    			glPopMatrix();
    			if(mode == GL_SELECT)
    				glPopName();
    			return;
    	} 
    	glBegin(GL_LINE_LOOP);
    	glVertex3f(-1.0, -1.0, 0.0);
    	glVertex3f(1.0, -1.0, 0.0);
    	glVertex3f(1.0, 1.0, 0.0);
    	glVertex3f(-1.0, 1.0, 0.0);
    	glEnd();
    	glDisable(GL_LINE_SMOOTH);
    	if(mode == GL_SELECT)
    		glPopName();
    	glPopMatrix();
    }
    I am not sure if it matters, I using Qt 4.0.
    qDebug() << hits << endl; gives 1 only in case Z when mSliceDisplacement is 0.0, otherwise prints zero.
    Thanks.

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

    Re: picking

    glMatrixMode( GL_MODELVIEW);.... what matrix are your glTranslate/glRotate messing with ?

  3. #3
    Junior Member Newbie
    Join Date
    May 2006
    Posts
    2

    Re: picking

    Thanks, I got it. Before drawing rectangle I had to put the sequence:
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(r*cos(prot*deg)*cos(trot*deg),r*sin(prot *deg),r*cos(prot*deg)*sin(trot*deg), 0,0,0, 0,1,0);

    which is executed during repainting.

    Sergey.

Similar Threads

  1. Z-buffer picking, gluUnProject picking not working
    By Icetigris in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-29-2008, 10:38 AM
  2. Picking in 3D - plz help
    By beautiful world in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-30-2002, 10:39 AM
  3. Picking
    By imported_Dominik in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-13-2002, 01:03 PM
  4. picking again.....
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-15-2002, 06:34 AM
  5. picking
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-14-2002, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean