Selecting solids and faces of solids in the screen

Hello,

In the application I am currently writting I have come across the question of how I can select faces of objects rendered on the screen or the objects themselves.

I am using wxWidgets and as with any other GUI lib I can easily get click Coordinates on the GLCanvas. The problem is how I can understand where on the openGL world the click was. I guess this must be a pretty common question but I can already understand that the answer can’t be simple and must depend on how I keep the solids data structure in my program. I would really value any hints or pointers towards the right direction though!

One additional question would be about rendering solids on the screen. I read somewhere that GL_TRIANGLES is the easiest surface for openGL to draw. Is that true? And if it is so then wouldn’t it be wise for an application to try and draw everything with triangles only?

To “convert” canvas coords to your world you can use gluUnproject (see my post here ). This gives you approximate 3d coordinates or a 3d-ray from the camera location into the scene which you can use manually to compute intersections with objects you want to select.

A more direct approach to select objects / primitives in your scene is provided by the selection mechanism or e.g. color based picking. See here for details.

Regarding your last question - GL_TRIANGLES is probably the easiest method in the sense that it is easy to understand: Three vertices, one triangle at a time. However, there are further methods starting with GL_TRIANGLE_FAN/STRIP that are more efficient because only one additional vertex needs to be specified for each triangle after the first one. Much faster and more advanced methods like vertex arrays also exist.

x57 thank you very much. I tried it and the method with gluUnproject works like a charm. Now it will be my app’s responsibility of course to see whether the user’s click is on an object or not.

Also thanks for your advice on drawing. I have read about vertex arrays too. Since I strive (in the end) for my app to be as fast as possible I will have to take a much more extensive look at them.