Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Interactive multi-selection with OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2001

    Interactive multi-selection with OpenGL

    I have worked in a scene where users can interacte thought the mouse.
    By clicking, a "3D object" should me selected (just painted in other color) on the screen.
    The problem is that sometimes OpenGL returns more than one object, so my question is how could select the "nearest" object on the screen ?!
    Below some code I have done:

    // selection buffer
    GLuint buffer[128];
    glSelectBuffer( 128, buffer );

    // chance render mode

    // switch to projection and save the matrix

    // get the viewport
    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);

    // new clipping volume, a small
    //square around mouse´s cursor
    gluPickMatrix( pos.X(), viewport[3]-pos.Y(), 2, 2, viewport); // pos is a Point from mouse click



    // collect the hits
    GLint hits = glRenderMode(GL_RENDER);


    So, when "hits > 1" how can I get the nearest object selected ??!!
    Thanks a lot in advance.
    [ ]'s


  2. #2
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    S41.16.25 E173.16.21

    Re: Interactive multi-selection with OpenGL

    >>so my question is how could select the "nearest" object on the screen ?!<<

    check all the 'selected' objects and see which ones closest by
    A/compare the object Boundingshapes, or if not good enuf, cast a ray from the into the scene on that point and find the closest triangle it intersects.
    B/draw each triangl/object in a different color, read back the pixel under the mouse, see what color it is, u now know what is the closest triangle under the mouse (unless u have depth fighting or something)
    *watch out turn off dithering, + in 16bit color youre limited to the number of different 'objects'

Posting Permissions

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