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

Thread: picking and redraw question

  1. #1
    Guest

    picking and redraw question

    Hi, I have a picking problem by using selection mechanism. There are 2 objects (say, A and B) rendered on the screen. When I click/pick object A, it works fine to make a selection hit, and then I translate some distance it by pressing a key. After that, when I try to click object B, the object A is drawn back to the original place.
    This run the same situation when I click on the area out of these 2 objects (i.e. no selection hit and both 2 objects go back original place)...

    It seems that we can only redraw that object when it make a selection hit. How can I redraw the whole scene once a selection hit is made? or What's wrong with that?

    Thanks for any input.

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

    Re: picking and redraw question

    Could you post some code?

    From what you are saying, I would look at how you draw your objects in the first place, do you translate them after a selection, if so are you recalculating the object using the original coordinates?

  3. #3
    Guest

    Re: picking and redraw question

    Here is my code, most from red book...Thx.

    void render(GLenum mode)
    {

    glPushMatrix();
    glTranslated(0.0, 0.0, (GLdouble) translate);
    glPushMatrix();
    if (mode == GL_SELECT)
    glLoadName(1);
    if (selected == 1)
    glRotated((GLdouble) rot_angle1, 1.0, 0.0, 0.0);
    glCallList(CHAIR01);
    glPopMatrix();

    glTranslated(100.0 , 0.0, 0.0);

    glPushMatrix();
    if (mode == GL_SELECT)
    glLoadName(2);
    if (selected == 2)
    glRotated((GLdouble) rot_angle2, 1.0, 0.0, 0.0);
    glCallList(TABLE01);
    glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
    }

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    render(GL_RENDER);
    glFlush();
    }

    void proces****s (GLint hits, GLuint buffer[])
    {
    unsigned int i, j;
    GLuint ii, jj, names, *ptr;

    printf ("hits = %d\n", hits);
    if (hits == 0)
    selected = 0;

    ptr = (GLuint *) buffer;
    for (i = 0; i < hits; i++) { /* for each hit */
    names = *ptr;
    printf (" number of names for this hit = %d\n", names);
    ptr++;
    printf(" z1 is %g;", (float) *ptr/0x7fffffff); ptr++;
    printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++;
    printf (" names are ");
    for (j = 0; j < names; j++) { /* for each name */
    printf ("%d ", *ptr);
    selected = *ptr;
    ptr++;
    }
    printf ("\n");
    }
    }

    void keyboard(unsigned char key, int x, int y)
    {
    switch (key) {
    case 'm':
    if (selected == 1)
    translate1 = (translate1 + 10) % 360;
    if (selected == 2)
    translate2 = (translate2 + 10) % 360;
    glutPostRedisplay();
    break;
    default:
    break;
    }
    }

    void mouse(int button, int state, int x, int y)
    {
    GLuint selectBuf[512];
    GLint hits;
    GLint viewport[4];

    if (button != GLUT_LEFT_BUTTON &#0124; &#0124; state != GLUT_DOWN)
    return;

    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(512, selectBuf);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

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

    gluPickMatrix((GLdouble) x, (GLdouble) viewport[3] - y, 5.0, 5.0, viewport);
    gluPerspective(90.0, (GLfloat) 500/ (GLfloat) 500, 10.0, 1500.0);

    render(GL_SELECT);

    glPopMatrix();

    hits = glRenderMode (GL_RENDER);
    proces****s (hits, selectBuf);

    glFlush();
    glutPostRedisplay();
    }

  4. #4
    Guest

    Re: picking and redraw question

    oh..I have just found out the problem....totally my stupid coding...
    "if (selected == 1)" and "if (selected == 2) shouldn't be added in void render(GLenum mode)....
    Anyway, thx for ur hint.

Posting Permissions

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