Triangle Selection May 17, 2006
This is the second stage in my sample program. It demonstrates triangle selection from a single click or marquee area selection. If you want to you can review the first stage here, but it's not necessary.
What it does
This program loads a mesh made of vertices and triangles and displays the mesh in a viewport than can be dragged or rotated. It allows selection of triangles by clicking a point, or dragging for marquee selection. Here's a screenshot of the head mesh with the nose selected. (It's not too pretty, sometime I might waste time making it look nicer. ) It uses gluUnProject to get a world-space ray from the click location. Then tests this ray against the triangles of the mesh and sets a selection flag for the closest one. It can also generate a world-space frustum from a selection rectangle, and then test which triangles are at least partially in this frustum. See the code for details. You could also check my selection tutorial. Note: Although I think back-buffer selection might be simpler at this stage, because of specific plans for the next stages I'm doing everything mathematically. Using the Triangle Selector
Drag Right mouse button - rotate the view Drag Center button - pan the view Drag Shift+Center button- zoom in or out Left click - Selects the closest front facing triangle at that point of the screen Drag + Left button - selects all triangles at least partially within the selection rectangle Holding Ctrl - Adds to selection Holding Alt - Subtracts from selection Code Download
Sample2-Triangle_Selection.zip ( 25KB ) : See the readme.txt included in the zip file for details. A MSVC++ 6.0 project file is included in the zip.
|