Pick-Through Multiple Selection

Hi! I'm developing a 3D scene arrangement tool in C# and I want to implement a feature for users where you can select objects behind other objects. I've searched the web for examples on how to get all of the meshes gathered from a pick ray (instead of only the nearest) but I haven't found any references on how to get or store that information. Are there any resources for this that I might have missed If not, may I get some advice or (bless your heart) some sample code Thank you in advance!


Answer this question

Pick-Through Multiple Selection

  • Sigfuss

    Thanks for the help! The last tip is especially useful. Once I've hashed out an implementation I'll clean it up and post for people to use.

  • R. F. Phillips

    One other quick addition...

    If you do create/find an algorithm that stores all intermediary intersection points be careful of back-facing triangles and complex meshes... The ray may enter (front face) and exit (back face) multiple times, thus you could generate multiple intersection points for a single mesh. Not strictly a problem, but if you specifically want the second/third/fourth mesh behind the front one you need to be careful - just taking the 2nd/3rd/4th intersection points may well still be the same mesh...

    hth
    Jack


  • DavidP

    I can't offer any example code as I'm not a C# developer, but the mathematical concepts should be sufficient...

    A picking algorithm needs to convert a 2D mouse (or whatever) coordinate into a 3D ray, simple mathematics states that a single 2D point generates an infinite number of 3D points (along the corresponding ray).

    The two types of algorithm you'll tend to find either traverse the ray from the screen (usually t=0) towards the back plane (usually t=1) and check for intersection along the way. The function finishes as soon as it hits something - as its also the closest. The other method (which is more robust) is to perform intersection tests on all possible objects (ideally in a hierarchical fashion) and then find the intersection with the lowest value of 't' - implying its the closest to the screen.

    You probably want to find an implementation of the latter type - an intermediary step should contain most (if not all) objects that the ray intersects along with the corresponding distances. You then need to tweak the code such that it returns the 2nd/3rd/4th (etc..) intersection instead of the first/front.

    I know you mention C#, but in C++ there is the D3DXIntersect() and D3DXIntersectTri() methods - both will do the hard work for you as well as return the distance (what I've referred to as 't'). I assume there are MDX/C# alternatives to these functions.

    Getting D3DX to do the hard work just means you need to gather the results in an array/container, sort them and then pick which one you want....

    hth
    Jack


  • SADave

    I take back my post about the code since it's ginormous, but I had to change my pick function so that it placed objects on a stack within the root node class of my scenes. Then my form event simply assigned the objects by popping them off the stack after making sure there was a stack to pop from.
  • Pick-Through Multiple Selection