Skip to main content
gamedev.net
🔒 Locked

Object selection?

Started by Butter Feb 19, 2003 at 4:20 PM 6 replies 450+ views
Original Post
Butter
Butter
I need to implement an object selection method. In the past I have used OpenGL Picking with the selection buffer, but I have found that this is to slow. What is the best way to do object selection? Some kind of Ray Intersection? Can anyone provide a resource that would help me? Thanks.
Fantasio
Fantasio
You need to Get the inverse of Projection matrix, then transform the position of the mouse with this matrix. It compute the position of the mouse in 3d world coordinate. the vector from the Camera Position to the mouse pos 3d is the ray.

You need also a triangle-line intersection routine, then check if an object's triangle intersect with the ray.

you can begin to code

[edited by - Fantasio on February 19, 2003 6:27:59 PM]
JimH
JimH
Here is a ray-triangle intersection method with some source code:

http://astronomy.swin.edu.au/~pbourke/geometry/linefacet/

This doesn''t include the transformations you have to do to get your ray into the object''s local space.

On a side note, the second half of the method is to determine of the ray actually intersects the polygon (and not just the plane outside the polygon). This method uses the sum of the inverse cos. There is faster way described in Graphics Gems, if speed is critical.
Butter
Butter
Thanks for your help guys.

The objects that are being selected here are drawn as points. I think that what I want to do is use a bounding sphere? This sphere would have a radius that would be set to a "user-friendly" value. The first sphere that the ray intersects is selected.

I think that there will be other objects that will be selectable also. These may be drawn as lines - not sure yet. I''m thinking that these could use bounding rectangles?

Does this sound OK so far?

Then to do selection with all at once: calculate the distance to the closest sphere and the distance to the closest rectangle. The smaller one is the selected object?

Does this make sense?

Thanks.


Pragma
Pragma
I know its irrelevant to the thread, but that is probably the worst ray-triangle intersection routine I''ve ever seen. I hope nobody''s written a raytracer based on that.

"Math is hard" -Barbie
"Math is hard" -Barbie
JimH
JimH
quote:
Does this sound OK so far?


I would think so, since testing against a bounding volume would most likely be the first test you’d do anyway.

quote:
I know its irrelevant to the thread, but that is probably the worst ray-triangle intersection routine I''ve ever seen.


If you have handy a link to a better one, can you post it please?
Pragma
Pragma
Well, a quick google search turned up http://wscg.zcu.cz/wscg2001/Papers_2001/R75.pdf, which looks interesting. Any of those algorithms would probably work fine (the one I use is the Moller one that doesnt require you to store a normal). I just said it was a bad algorithm because there is really no excuse to have a sqrt() or an acos() in your triangle collision routine, especially not 3 or more of each.

"Math is hard" -Barbie
"Math is hard" -Barbie
JimH
JimH
Yeah, the acos method is the worst. But it’s easy to understand and I happened to have that link with source code. Badouel’s algorithm is the one in Graphic Gems. I guess there are plenty of resources around the web. Here’s another with source code, for the heck of it: http://geometryalgorithms.com/Archive/algorithm_0105/algorithm_0105.htm

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.