Lots of things to answer..
Given that I haven't implemented it, I don't have data structures for it yet; however, I plan to do something like the following pseudo-code if I can the intersection question answered via some API.
Assumptions:
- Mouse will always be interacting from a 2D screen so this will not work with any cool 3D headsets, etc.
- Pickray is a 1D vector in 3D space
Pseudo-code goes something like this:
Map<BoundingBox,Object> regions = createRegions();
...
for( Map.Entry<BoundingBox,Object> entry : regions.entrySet() )
{
if( entry.getKey().containsPoint( point ) )
{
// do something of user interest
break;
}
}
Since I already know what Shape3D was chosen and each Shape3D will only have a few local regions, this O(n) search shouldn't be too bad. If the algorithm needs to be generalized and optimized, there are obviously techniques to do so.
Well, what I was interested in was precisely the BoudingBox. So all regions are boxes ? How could a more complex shape be implemented ?
I agree with Panth. It does indeed sound like the center point which is not useful for the purpose I described above.
The Javadoc is wrong. I fixed it.
Oh, I just thought of something that might be more compatible with the picking code itself. The interface could simply be the vertices of the polygon the ray intersects. From my side, it would be even faster to use Map<Triangle,Object> because I could just call map.get( triangle ).
Obviously, there are variants on this idea such as float[] vertices, etc. The only important thing is that the data structure used consistently generate the same hashCode for the same vertices regardless of order OR that the vertices arrive in a deterministic order so that the hashCode will be stable.
Other than that, this is even easier, faster, and probably closer to the internals of the picking code that has to confirm ray.intersects( triangle ) anyway.
I think this is not possible with OpenGL-way picking code because it doesn't deal with triangles data structure. On the other hand, it's perfectly possible with the PickingLibrary since it goes through each triangle.. You would just have to find the nearest point to the intersection point in the intersected triangle and you have what you want.
--------------
I have just implemented the getFaceIndex() method in PickResult. Please use it only with PickingLibrary, or it will throw an Exception.