Results 1 to 8 of 8

Thread: Picking

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    6

    Picking

    Hello,
    I try since few days to make the picking work on my program but it doesn't. The results are weird:


    Slot 0: - Value: 1
    Slot 1: - Value: -103863766
    Slot 2: - Value: -103863766
    Slot 3: - Value: 1
    Slot 4: - Value: 0
    Slot 5: - Value: 0
    Slot 6: - Value: 0
    Slot 7: - Value: 0
    Slot 8: - Value: 0
    Slot 9: - Value: 0
    Slot 10: - Value: 0
    Slot 11: - Value: 0
    Slot 12: - Value: 0
    Slot 13: - Value: 0
    Slot 14: - Value: 0
    Slot 15: - Value: 0
    Slot 16: - Value: 0
    Slot 17: - Value: 0
    Slot 18: - Value: 0
    Slot 19: - Value: 0
    Slot 20: - Value: 0
    Slot 21: - Value: 0
    Slot 22: - Value: 0
    Slot 23: - Value: 0
    Buff size: 1
    click on x:248,y:236
    1 hits:
    Number: 1
    Min Z: 42
    Max Z: 42
    Name on stack: 1



    though my code is this :

    double x=clavier.getEvent().button.x;
    double y=480-clavier.getEvent().button.y;

    printf("click on x:%g,y:%g\n",x,y);

    GLuint buff[64] = {0};
    GLint hits, viewport[4];
    glSelectBuffer(512, buff);
    glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);

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

    gluPickMatrix(x, y, 1.0f, 1.0f, viewport);
    gluPerspective(70, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);

    glLoadName(1);
    //draw a cube



    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    hits = glRenderMode(GL_RENDER);

    list_hits(hits, buff);

    gl_selall(hits, buff);




    void Jeu::gl_selall(GLint hits, GLuint *buff)
    {
    GLuint *p;
    int i;

    terrain.dessinerPick();

    p = buff;
    for (i = 0; i < 6 * 4; i++)
    {
    printf("Slot %d: - Value: %d\n", i, p[i]);
    }

    printf("Buff size: %x\n", (GLbyte)buff[0]);
    }


    void list_hits(GLint hits, GLuint *names)
    {
    int i;
    printf("%d hits:\n", hits);

    for (i = 0; i < hits; i++)
    printf( "Number: %d\n"
    "Min Z: %d\n"
    "Max Z: %d\n"
    "Name on stack: %d\n",
    (GLubyte)names[i * 4],
    (GLubyte)names[i * 4 + 1],
    (GLubyte)names[i * 4 + 2],
    (GLubyte)names[i * 4 + 3]
    );

    printf("\n");
    }



    Thankyou

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    6

    Re: Picking

    I think the problem comes from the position of the camera. How could I change it when I am picking?

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    6

    Re: Picking

    do you guys have any idea?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    317

    Re: Picking

    Why do you think it does not work?
    The weird code is this:
    Code :
      (GLubyte)names[i * 4 + i]
    Why are you casting it to byte? It is 32bit integer.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    6

    Re: Picking

    Yes but this part doesn't actually cause much trouble because the probleme is indeed earlier, when I try the picking. I mean, when I click somewhere on the screen it doesn't detect the object as well

  6. #6
    Senior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    317

    Re: Picking

    How do you set viewport array? I do not see any assignment.

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    6

    Re: Picking

    You're right but even if I add this :
    glGetIntegerv(GL_VIEWPORT,viewport); before gluPickMatrix(x, y, 1.0f, 1.0f, viewport);
    It is still the same

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    6

    Re: Picking

    No idea dude?

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