Results 1 to 3 of 3

Thread: Anyone here know the pick/selection in OpenGL??

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2003

    Anyone here know the pick/selection in OpenGL??

    Hello Everyone:

    First of all, I feel guilty to post this question again here -- I have post the question in the advance group, but got no reply. If this duplication offends you, I apologize. If you know anything, please do help me. My question is --

    Hi, Everyone:
    I use MFC6.0 and OpenGL to write a Win32 application
    under Window XP (with SP1). For the pick/select problem,
    I have the following code:

    bool CView::PickObject(CPoint point)
    const int BUFSIZE = 100;
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    int ID;
    CString cts;


    (void) glRenderMode(GL_SELECT);



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

    glOrtho(Winleft, Winright, Winbottom, Wintop,Winnear, Winfar);


    for (i=0;i<total_mesh;i++)
    ID = get_mesh_id(i);

    glPopMatrix(); // For ModelView Matrix



    hits = glRenderMode(GL_RENDER);

    if (hits > 0) //something is picked
    cts.Format("hits=%d b0=%d b1=%d b2=%d b3=%d b4=%d b5=%d b6=%d b7=%d",hits,
    return true;
    return false;

    I test the code, it seems work fine. Yet, I am confusing with the explanation of the content of the selectBuf
    from the OpenGL FAQ 20.020. It says
    ---Begin quote ----
    "Each hit record contains the following information stored as unsigned ints:
    .Number of names in the name stack for this hit record
    .Minimum depth value of primitives (range 0 to 2 power 32 -1)
    .Maximum depth value of primitives (range 0 to 2 power 32 -1)
    .Name stack contents (one name for each unsigned int)
    ---End quote ---

    Exactly what does it try to explain? Can anyone explain it with more easy understanding way?
    I print out the hits and selectBuf as follows:

    hits=1 b0=2 b1=-2143505408 b2=-2143500032 b3=0 b4=1 b5=0 b6=0 b7=0
    hits=1 b0=2 b1=-2144751104 b2=-2144735488 b3=0 b4=2 b5=0 b6=0 b7=0
    hits=1 b0=2 b1=-2146665728 b2=-2146595840 b3=0 b4=4 b5=0 b6=0 b7=0
    hits=3 b0=2 b1=2142254848 b2=-2142262784 b3=0 b4=1 b5=2 b6=2144132864 b7=2145358080

    Will anyone tell me why the selectBuf[0] is always 2? After the pick,
    how will I know which entities are picked? (I can tell selectBuf[4] seems
    store the ID, but when the hits are 3, which are the three entities picked?

    Thanks for help.

  2. #2
    Junior Member Newbie
    Join Date
    Jun 2001

    Re: Anyone here know the pick/selection in OpenGL??


    Yes, picking method is a litle hard to make it works the first time.

    You have posted just 2th part code for the picking method, the code that need to be executed when the user do click somewhere,

    But inside the rutine (void) glRenderMode(GL_SELECT);

    each "selectable" object to be render need to be marked with the command glloadname()


    glloadname(1); //mark with value 1
    draw_objectA; //draw one object

    glloadname(2); //mark with value 2
    draw_objectB; //draw one object

    glloadname(3); //mark with value 3
    draw_objectC; //draw one object
    more objetcs if you want

    depending objects position and current camera position and orientation, when the user do click in the screen the mouse pointer could be over just 1, 2, 3 or all objects, if it was over just one object then only info for one object will be returned in the bufferselect, along with some other info you will found value "1" or "2" or "3" etc, if value "1" is found mean the user do click in objectA, i value "2" is found then ObjectB was clicked and so on.

    If the mouse pointer was over all 3 objects then the bufferselect will return info for 3 objects, along with the mark value info for each object you will also get the minimun and maximum "Z" coordinate value used when the objects is draw, so you have to choose the most front object (so the picked) inspecting all minZ (or maxZ, depending) in the bufferselect.

    good luck,

    Turbo Pascal

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2003

    Re: Anyone here know the pick/selection in OpenGL??

    Thanks for your reply. I appreciate.

Similar Threads

  1. Selection and pick object
    By dandosan in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 06-19-2013, 11:54 AM
  2. Pick Selection Editing by Points and Lines
    By Nick_Miller in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 06-24-2012, 11:32 AM
  3. Pick-ray selection and window reshape
    By charlie mac in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-24-2008, 11:53 PM
  4. vb&opengl coordination pick
    By zcfirst in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-08-2005, 06:37 PM
  5. Why does OpenGl always pick the primary card?
    By in forum OpenGL: User Software
    Replies: 0
    Last Post: 03-25-2000, 09:50 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