Jump to content
  • Advertisement
Sign in to follow this  
AlexAlex

Picking polylines

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings. I am developing a Direct3D application where I give the user an ability to pick objects. Some objects can be expressed as triangle strips, but there are also many polyline objects. A polyline is considered picked if the user clicked a location that was "close" to the polyline (the distance between the mouse location and the polyline drawn in the window is smaller then a specified threshold). I tried simulating something like OpenGL picking (creating a pick matrix, rendering to a small off-screen buffer and testing if something was rendered). It works, but I suppose it is not the most efficient way and there probably is a more accurate one. I also though of transforming everything to screen-space (using Project) and checking the distance from a 2D point to a 2D line, but it also seems not so efficient. Alex.

Share this post


Link to post
Share on other sites
Advertisement
You could unproject the picking ray from screenspace back to world space and do the intersection tests there. That's the way people typically seem to go about this. To do the intersection tests on the polyline object, an option would be to consider each segment of the line as a cylinder (or capsule if you fancy those) and intersect these with the ray. For efficiency it might be useful to intersect the ray with the bounding sphere from (multiple) segments first.

- more on object intersection

- more on unprojection (docs)


Hope this helps :)

Share this post


Link to post
Share on other sites
I'm going to move this to 'Maths & Physics' as I think you'll get a more appropriate answer from them [smile]

The way I did this was to perform a line-line intersection test. I completely forget the details now, but if you express lines parametrically, fit that into the pythagoras/distance equation you generate a quadratic function (except if they're parallel). You can then use calculus methods to solve for the global minimum.

I then projected the two coordinates from the local minimum back into screen-space and checked them against a 1-pixel threshold. This latter part could probably be improved with greater knowledge of the projection mathematics and hence eliminate the need for the projection-to-screen step...

Oh, fwiw - I'm not aware of there being any D3D/D3DX specific functionality that'll do this job for you.

hth
Jack

Share this post


Link to post
Share on other sites
remigius, your idea is great but I see a slight problem with it. If a polyline is far away the "tolarance" is greater than for polylines that are close. My picking tolerance is expressed in terms of pixels in the viewport window and not in terms of distance in world space.

Both ray/cylinder and ray/ray intersections are out of question (and calculating a different cylinder size for every polyline is also out of question).

However in the intersections table I saw something that could help. I could calculate a "pick matrix" like in OpenGL selection and test for intersection of polylines with the viewing frustum defined by this pick matrix.

Alex.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!