mouseListeners in 3d?

Hi guys,

I was wondering if anyone could point me in the direction of how using mouseListeners would work on a GLCanvas. For example, how i might detect if a particular object is being clicked or say, the closest vertice to a click. Basically, if there’s a way to differentiate between the 2D representation of the screen and the 3D depth of the scene when clicking. Or perhaps a way of mapping the co-ords of objects into 2D so you can determine what someone might be clicking on?

Any pointers would be cool,

Thanks

Take a look at the source code for the gleem package in the jogl-demos workspace. This implements a few Open Inventor-style manipulators in 3D. It’s very inefficient but should show you the kind of linear algebra you need to write to get correct results.

You can use gluUnproject() to get the depth at a specific pixel.

Or you can look into using picking, http://www.lighthouse3d.com/opengl/picking/ to identify which object was selected.

For the use of gluunproject you may have a look to: http://nehe.gamedev.net/data/articles/article.asp?article=13

Jean-Baptiste