Sign in to follow this  

Point Polygon collision

Recommended Posts

Hey all, I need to know if my cursor is over a polygon in 3d space. There's more than one polygon and I need to find the closest one that hits. The method I've come up with is: For each polygon Project the polygon vertices onto the screen (view, transform, projection matrices known) Using odd-even test, determine if cursor is in projected polygon. If it does then check the distance and compare to the distance of closest polygon found. I'm wondering if there was a better way to do it. Or if there's something wrong with the algorithm. Thanks in advance.

Share this post

Link to post
Share on other sites


The method you describe should work just fine.

Another way of doing the same thing is to create a 3d ray from the mouse pointer coordinates and do ray-triangle hit test for each polygon.

this thread describes how to get the ray.

You can google for the ray-triangle hit test.

This method is useful also for raytracing and is maybe a bit more efficient since you don't need to project your triangles.

Good luck!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this