Considering example:

I have a mesh(es) on the OpenGL screen and would like to select a part of it (say for delete purpose). There is a clear way to do the selction via Ray Tracing, or via Selection provided by OpenGL itself.

But, for my users, considering that meshes can get wired surfaces, I need to implement a selection via a Arbitrary closed region, so all triangles that appears present inside that region has to be selected.

To be more clear, here is screen shot:

I want all triangles inside black polygon to be selected, identified, whatever in some way.

enter image description here

How can I achieve that ?


You need to use glUnProject, which allows you to map window coordinates (2D) to object coordinates (3D). You can basically implement a function that allows you to draw a 2D polygon on the screen, then project each its corners to 3D, and select all the vertices of your 3D mesh that lay inside the projected 2D corners.

NeHe has a tutorial about glUnProject, although I don't know how good or useful can be for you.

  • \$\begingroup\$ Unprojecting is not so complicated, instead how I gonna to check if specified vertex of the model is inside the polygon in 3D space? I tried to extrude the polygon in direction ov view vector, long enough that it intersects with the model plane itself. But the problem is, I can not find a reliable way to say Vertex a is inside extruded polygon. \$\endgroup\$
    – Tigran
    Sep 12 '12 at 12:45
  • \$\begingroup\$ There is many ways to to this I think. You can just check the Z value of the projected 2D point and see if it corresponds to the back clip plane or to the 3D object. You could also Project the 3D points of your mesh to 2D, and see which ones lay inside the drawn polygon. \$\endgroup\$
    – Dan
    Sep 12 '12 at 12:54
  • \$\begingroup\$ actually projecting seems the way to go. First I project mesh point to the PLANE of the polygon, after pick that projected vertex and check if it lays in the polygon in 2D surface. Seems working :) \$\endgroup\$
    – Tigran
    Sep 12 '12 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .