map window coordinate to texture mapped to polygon in 3D

Hi Everybody,

i am new to Jogl and OpenGL and i am trying to find a fast method to “convert” a window coordinate (~hit test with a ray cast from the window coordinate into view direction) into a coordinate of a texture mapped to a polygon in 3D. I tried to find solutions in this forum and in the FAQ but it seems i am still missing the right jargon to find anything.

The background is that i am trying to build a Jogl based gui library and would like to produce mouse events on the gui which is rendered to the texture.

Many thanks in advance
Jelly

For starters, I’m going to assume you know how to convert a window coordinate into the correct ray direction. Once you have your ray, you should look into triangle/ray intersection algorithms. With that algorithm in place, you can discover where the ray hits a triangle of your model (assuming it does hit something).

Now once you get your triangle, you can determine where the ray hits inside it. Then you’ll need to look up the texture coordinates assigned to each vertex and interpolate the texcoords based on the triangle collision. This should give you the tex coord and then you can look-up the color, etc.

Another option is to look into the source code of FengGUI since I believe they’ve done a lot of work to map Swing into 3d. I think it’s open source.

Also, I haven’t actually done any of this, it’s just theory but it should get you in the right direction.