Results 1 to 5 of 5

Thread: Picking object problem!!!

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    23

    Picking object problem!!!

    I need to pick an object on the screen and it seems, it doesn't work. this is my code

    <CODE>
    CWindowsGLDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    CPaintDC dc(this);

    GLuint selectBuffer[BUFFSIZE];
    GLint hits;
    GLint viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);

    glSelectBuffer(BUFFSIZE, selectBuffer);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

    double size = 0.0, s;
    std::vector<Piece *>::iterator it;
    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++) {
    s = (*it)->size();
    if(s > size) size = s;
    }

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(point.x, viewport[3]-point.y, 1.0, 1.0, viewport);
    gluPerspective(30.0, 1.0, 0.01 * size, 30.0 * size);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    gluLookAt(0.0, 8.0*size, 6.0*size, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glRotated(angleYVue,1.0, 0.0, 0.0);
    glRotated(angleXVue,0.0,1.0,0.0);

    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++)
    (*it)->internalDraw(1);

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    hits = glRenderMode(GL_RENDER);

    int numPiece = Proces****s(hits, selectBuffer);

    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++)
    if( (*it)->getNumeroGL() == numPiece ){
    pDoc->pSelected = (*it);
    pDoc->pSelected->setSelected();
    }
    else{
    if((*it)->isSelected())
    (*it)->setSelected();
    }

    Invalidate(FALSE);
    </CODE>

    I'm using glLoadName() and to retrieve the object i'm using

    <CODE>

    int CWindowsGLView::Proces****s(GLint hits,GLuint buffer[])
    {
    int i;
    int j;
    int number;
    int name;
    GLint z1;
    GLint z2;
    int zMin = MAX_VALUE;
    GLuint *ptr;

    ptr = (GLuint *) buffer;

    for(i=0;i<hits;i++){ //for each hit
    number = *ptr;
    ptr++;
    z1 = *ptr;//zmin
    ptr++;
    z2 = *ptr;//zmax
    ptr++;

    if(z1<zMin){
    for(j=0;j<number;j++){ //for each name
    zMin = z1;
    name = *ptr;
    ptr++;
    }
    }
    }
    return name;
    }
    </CODE>

    Thanks .
    TORNIERI Christophe
    Ecole Supérieure en Sciences Informatiques

  2. #2
    Member Contributor bsperlin's Avatar
    Join Date
    Feb 2001
    Location
    VA
    Posts
    67

    Re: Picking object problem!!!

    Hi!
    Aren't you supposed to do a glLoadName or glPushName somewhere about here:

    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++) {
    s = (*it)->size();
    if(s > size) size = s;
    }

    How does the code identify what is picked?
    Barry

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    23

    Re: Picking object problem!!!

    Hi,

    Yes, in fact i'm making a glLoadName in the code that draws the objects. But in fact, my problem is the selection seems to work but when i'm rotating the camera, the selection does't work in some positions. For example, when i'm in front of the objects, the selection works perfectly but when the camera is at the left so i'm looking from the left the selection doesn't work anymore. It's very strange.

    Did you have an idea of the problem?

    Thans.
    TORNIERI Christophe
    Ecole Supérieure en Sciences Informatiques

  4. #4
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    23

    Re: Picking object problem!!!

    Hi,

    OK i've found the problem. I forgot to clear the buffer.

    Thanks. .
    TORNIERI Christophe
    Ecole Supérieure en Sciences Informatiques

  5. #5
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Posts
    174

    Re: Picking object problem!!!

    What do you mean by "clear the buffer" , because I'm having the same problem in some cases, maybe could be the same problem.

    Tnks
    Best regards
    Kurt

Similar Threads

  1. Picking an Object not working
    By Zubaja in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-02-2014, 01:24 AM
  2. picking object
    By newasun in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-24-2005, 01:21 AM
  3. Object Picking
    By Montoya in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-22-2003, 12:12 AM
  4. Problems picking the right object
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-06-2001, 08:04 PM
  5. Object picking...
    By Spotaszn in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-11-2000, 03:11 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