Results 1 to 3 of 3

Thread: Picking big problem!!!

  1. #1
    Member Newbie
    Join Date
    Oct 2002
    Location
    Amsterdam
    Posts
    36

    Picking big problem!!!

    Hi!

    I have a big problem. I'm trying to pick a sphere in a 3D environment.

    In my scene I have a wing, some other stuff (an isosurface) and my sphere.

    This is my code

    My display function call this function

    PaintIso(GLenum mode)
    {
    setupMatrices();
    iso->setCamera(from,at,up);
    iso->setOrientation(P, V*R);
    iso->Render();
    if (SNmode == NAVIGATION_MODE)
    glColor4f(RedS, GreenS, BlueS, .5);
    else
    glColor4f(0., 1., 0., .5);
    if (mode == GL_SELECT)
    glPushName(1);
    glutSolidSphere(SphereRay, 10, 10);
    }


    This is the function that get the picked objects.
    I call this one inside my mouseFunction

    void PickObject(int x, int y);
    {
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    GLint viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(BUFSIZE, selectBuf);
    (void) glRenderMode(GL_SELECT);
    glInitNames();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 25., 25., viewport);

    PaintIso(GL_SELECT);

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glFlush();

    hits = glRenderMode(GL_RENDER);
    if (hits != 0)
    {
    GLint i, j, numberOfNames;
    GLuint names, *ptr, minZ,*ptrNames;

    ptr = (GLuint *) selectBuf;
    minZ = 0xffffffff;
    for (i = 0; i < hits; i++) {
    names = *ptr;
    ptr++;
    if (*ptr < minZ) {
    numberOfNames = names;
    minZ = *ptr;
    ptrNames = ptr+2;
    }

    ptr += names+2;
    }
    if (numberOfNames > 0) {
    printf ("You picked the sphere ");
    if (SNmode == NAVIGATION_MODE)
    SNmode = SPHERE_MODE;
    else
    SNmode = NAVIGATION_MODE;
    ptr = ptrNames;
    for (j = 0; j < numberOfNames; j++,ptr++) {
    printf ("%d ", *ptr);
    }
    }
    else
    printf("You didn't pick the sphere!");
    printf ("\n");
    }

    glutPostRedisplay();
    }

    It seems very easy to use, but of course, it doen't work.

    If I push a name for the wing I obtain that clicking everywhere in the viewport I'm selecting the wing, even if it's not in the clipping area!!!

    I know there's something pretty wrong, but I don't know what...

    Please, help me!

    Thank you very much,
    Remedios

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2002
    Posts
    1

    Re: Picking big problem!!!

    May be you can try this:
    call glPushName(0) just after glInitNames() and use glLoadName(1) instead of glPushName(1) in PaintIso(GLenum mode).
    That's the way I'm doing picking (http://nehe.gamedev.net/) and it's work.
    Hope this help,
    Stef.

  3. #3
    Member Newbie
    Join Date
    Oct 2002
    Location
    Amsterdam
    Posts
    36

    Re: Picking big problem!!!

    Thank you for the advice, now I'm using glPushName, and I figured out that my viewport was redimensionated automatically (because I'm using GLUI) and now it works, thanks!

Similar Threads

  1. Picking problem
    By steppo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-10-2010, 06:49 AM
  2. picking problem
    By newasun in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-24-2005, 10:23 PM
  3. Picking problem
    By Jon723 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-23-2004, 07:08 PM
  4. PICKING PROBLEM
    By nstod in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-30-2002, 03:56 PM
  5. Problem with Picking
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-27-2002, 01:18 PM

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