Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  Tigran Sep 12 '12 at 12:45
    
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. –  Dan Sep 12 '12 at 12:54
    
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 :) –  Tigran Sep 12 '12 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.