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 6 of 6

Thread: Object Selection

  1. #1
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Object Selection

    hi All,

    Im having problems with object selection using the 'GL_SELECT' method, it works some of the time but sometimes selecting a blank area of the screen gets 'hits' which relate to a particular object, also sometimes clicking an object doesnt work.

    Im using glPerspective projection with gluLookAt (i had real problems until I used gluLookAt), I specify these when drawing the objects and when using 'GL_SELECT'

    Thanks

  2. #2
    Advanced Member Frequent Contributor cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    913

    Re: Object Selection

    Are you using gluPickMatrix(...) or something similar to shrink your view volume around the mouse position?
    Cass Everitt -- cass@xyzw.us

  3. #3
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Object Selection

    Yes, my area is 2x2 around the mouse pointer, just as an aside, is this 2x2 pixels?

  4. #4
    Advanced Member Frequent Contributor cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    913

    Re: Object Selection

    Hmm... maybe you could post some example code?
    Cass Everitt -- cass@xyzw.us

  5. #5
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Object Selection

    this is the mouse click code..


    void mouseclick(int button, int state, int x1, int y1)
    {
    GLuint selectBuf[512];
    GLint hits;
    GLint viewport[4];

    if (button != GLUT_LEFT_BUTTON | | state != GLUT_DOWN)
    return;

    glGetIntegerv(GL_VIEWPORT, viewport);

    glSelectBuffer(512, selectBuf);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    // 2x2 picking region
    gluPickMatrix((GLdouble) x1, (GLdouble) viewport[3]-y1, 5.0, 5.0, viewport);

    gluPerspective(45,(GLfloat)800/(GLfloat)600,1,900);
    gluLookAt(0,0,800,0,0,0,0,1,0);

    env.DrawScene (GL_SELECT);

    glPopMatrix();
    glFlush();

    hits=glRenderMode(GL_RENDER);

    if (hits >0 )
    env.Proces*hitss (hits,selectBuf);

    env.MouseMove(button, state, x1, y1);
    }

    this is the process hits code.


    environment::Proces****s (GLint hits,GLuint buffer[])
    {
    unsigned int i, j;
    selected = NULL;
    GLuint names, *ptr, ind;
    brick *bptr;

    ptr = (GLuint *) buffer;

    names = *ptr;
    bptr = start;
    //selected = bptr;

    ptr++;
    ptr++;
    ptr++;
    //ptr++;
    names = *ptr;

    while(bptr != NULL)
    {
    ind = bptr->GetIndex ();

    if (names != ind)
    i=-1;
    else
    selected = bptr;

    bptr = bptr->next ;
    }
    }

    and this is the display code...


    environment: rawScene (GLenum mode)
    {

    float *rgbv;
    int scale,pos[3];
    GLuint index;


    glPushMatrix();
    rgbv = start ->GetColour ();
    scale = start ->GetSize ();
    index = start ->GetIndex ();

    start ->GetPosition (pos);
    glTranslatef(pos[0]-100,pos[1],pos[2]);
    glColor3fv(rgbv);
    glScalef(scale, scale, scale);
    if(mode == GL_SELECT)
    glLoadName(1);


    glCallList(index);
    glPopMatrix();

    current = start->next ;



    glPushMatrix();

    rgbv = current ->GetColour ();
    scale = current ->GetSize ();
    index = current ->GetIndex ();


    current ->GetPosition (pos);
    glTranslatef(pos[0],pos[1],pos[2]);
    glColor3fv(rgbv);
    glScalef(scale, scale, scale);
    if(mode == GL_SELECT)
    glLoadName(2);

    glCallList(index );
    glPopMatrix();

    }

    Hope you can help


    [This message has been edited by David (edited 02-12-2000).]

  6. #6
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Object Selection

    oh, Ive just found out why,

    I needed to set to MODELVIEW mode before calling the GL_SELECT command, it now works, but I got the code from the red book... Strange...

    Thanks for the help anyway!!

Posting Permissions

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