PDA

View Full Version : Finding location on a polygon?



wgj000
09-07-2006, 02:56 PM
What I need to do is to find the location on a polygon where I click with the mouse. Is this possible with openGL commands? What I need is the location in texture space (S and T).

I'm fairly certain I can do this manually by finding where a ray created via the projection matrix intercepts with the selected polygon. However, this seems like something that would be commonly needed and so there is probably an existing solution somewhere. I can't find it though. Can someone point the way?

Zengar
09-08-2006, 01:10 AM
What do you mean by "location in the texture space"? If you need the texture coordinates for selected polygon, you must find them manually by inspecting your model. OpenGL does not store information about polygons, they just get rendered. You should probably look into selection and feedback mode of GL, I never use them so I can't tell you the details. Hovewer, your solution by raytracing seems most fast and stable to me.

wgj000
09-08-2006, 06:35 AM
OK. That's what I figured. I just didn't want to do a lot of work only to find out later that there was a gluGetInterceptCoord command. Thanks.

Relic
09-08-2006, 08:33 AM
Actually the simplest method is to map your object with a special texture which encodes the uv-space in the color, well, or use a fragment shader writing that directly and readback the single pixel where you clicked with the mouse.
If you have multiple independent objects to click, encode their ID in another output component.
Then decode the color and you get your ID and uv-coords in modelspace without any complicated 3D math and exactly how the hardware mapped it.
That's how some 3D paint tools do it.

Be careful with the image's color resolution, FSAA and other color changing features. Rendering the data directly into a framebuffer object with floating point data would make sense to overcome pixelownership and color conversion issues.