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

Thread: Selection and pick object

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3

    Selection and pick object

    Hi everyone
    I would like to get information about a clicked object.
    Actually i would like to implement a sort of osnap function like in autocad (when the cursor
    get near a line and i click, i can get the information about that line).

    I think to do it with the glRenderMode(gl_select) but i don't know how to start...
    Someone could help me?
    Is this method right?
    or maybe it's better doing that with the gluunproject funtcion?

    I read tons of documentation but nothing for vb.net

    Thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659
    basically there are 3 ways to implement picking (at least 3 i know of)

    1. using the select buffer (your 1st idea)

    2. map your object to screen coordinates using gluProject and calculate the distance to the mouse pointer (your 2nd idea).
    this approach is very easy to implement. you have to keep in mind that for your OS which sends you a mouse event
    y=0 at the top of the screen, while for OpenGL y=0 at the bottom of the screen (or vice versa, i never remember that correctly).

    3. if your models consists of quads/trias and you want only to pick the quad/tria that is currently in front, you can draw the scene
    into the back buffer, using a different color for each quad/tria; then use glReadPixels() to read the color at the mouse position and
    calculate the quad/tria id from the color value. this is a slightly more complicated way.

  3. #3
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3
    Ok perfect.
    I read about the three ways you described but I'm quite sure that the 3rd is not good for me.
    I have to handle just lines for my project.
    The second one could be good. I already wrote a function that get the world coordinates
    form the screen coordinates. So I can do it just adding some geometric funciotn that calculates
    the distance form the cursor to the many lines rendered.
    You suggest to go on with the second way or with the select buffer?

    And about the select buffer, what I have to do to get informations form the clicked object.
    I can't understand what's the way...

    Thanks a lot!

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,077
    Quote Originally Posted by dandosan View Post
    And about the select buffer, what I have to do to get informations form the clicked object.
    I can't understand what's the way...
    Instead of paraphrasing, I would rather advise you to read the following. That is the 12th chapter of the old "Red book".

  5. #5
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3
    I yet read it many times but I can't understand how to start!

    Anyway I'm trying with the other way of glunproject and hope I can do what I need

  6. #6
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,077
    Quote Originally Posted by dandosan View Post
    I yet read it many times but I can't understand how to start!
    OpenGL Programming Guide is a well written book. I cannot realize what could be a problem.
    If you have a particular question, just ask. Otherwise, you should find answers by yourself.
    gluUnProject() only maps window coordinates to object coordinates, but does not answer on the question what object is clicked on. You should use it together with "pure color" rendering and glReadPixels(), or something like that.

Posting Permissions

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