PDA

View Full Version : Intersection with arbitrary solid


hamishl
2004.09.17, 11:16 AM
I think this is a simple problem, but I am not sure. I have arbitary solids, and need to find out if and where a ray intsects them. I don't think I can do it mathmatically because I am using an API to import these solids. But there must be something in Opengl that says where something intersects.
To sum up, if I give a x and y location, I need the z locations where the solid is bounded.
Thanks,

phydeaux
2004.09.17, 05:31 PM
It is possible to do this with OpenGL- you can use the selection buffer. You basically set your viewport to look down the ray you want (basically you will use an ortho projection with a very small width and height) and then you make a call to glRenderMode(GL_SELECT); Now, you draw your object. You then get the result in your selection buffer, and you can find the point closest to the viewer, which will be your intersection. They explain how to do this in the Red Book, though I can try to help you if you're having trouble with it.

However, I would recommend you not do this in OpenGL, and instead use one of the very many collision libraries out there. For example, OPCODE http://www.codercorner.com/Opcode.htm is the one used by ODE (ode has a decent interface to doing collision itself as well.) Why? You get considerably more accuracy and flexibility, as you can do collisions between two solids, a solid and a ray, plane, point, etc. what have you.

The OpenGL route however may be faster for rays, depending on how complex your object is- I'd have to know exactly what you're doing.

codemattic
2004.09.17, 05:41 PM
Are you looking to do selection and picking?

http://www.rush3d.com/reference/opengl-redbook-1.1/chapter12.html