The Industry's Foundation for High Performance Graphics

1. picking with vertex arrays

Hi
I am programming a nature simulator and in this simulator I am rendering a landscape.To do this I use Vertex arrays with triangle strips. Anyway, the problem is this: I need to be able to pick any of the vertexes with my mouse. How do I do this with vertex arrays. You need to give each vertex its own name, but since I am using vertex arrays this is a problem. Is it possible to put the names in an array and attach the names to the vertex array as I would attach say the colors of the vertexes?

Kyllan

2. Re: picking with vertex arrays

I wouldn't try to use the GL selection mechanism for this one (I can see some of the frequent contributors laughing !).

Here is what I would do:

1) When the user moves the mouse, get X and Y from Windows and get the Z coordinate from the GL depth buffer (first problem: if nothing has been drawn at this X,Y, you don't have a Z coordinate ! See 3)...).
2) Use gluUnproject to get the 3D coordinates of the point. Now, find the closest vertex in your arrays, based upon distance.
3) If nothing has been drawn (i.e. you do not have a proper Z coordinate), project your vertices on the screen (using gluProject) and find the closest one to (X,Y).

Using this kind of algorithm brutally will probably result in very slow response. You might want to find some ways to result the number of vertices to test (there are specialists of BSP/Quadtrees/Octrees here who may help you but I don't know whether this techniques apply easily to landscapes).

You may think that the GL selection mechanism could be better but keep in mind that it is most probably not an HW-accelerated function...

Anyway, I am quite interested to see what the others can propose to help you.

Regards.

Eric

[This message has been edited by Eric (edited 01-18-2002).]

3. Re: picking with vertex arrays

Thanks Eric
But my problem is using your technique with vertex arrays. Is it at all possible?

Kyllan

4. Re: picking with vertex arrays

Kyllan, the technique I gave you is independant of the way you render the landscape.

I understand you are using the OpenGL Vertex Arrays mechanism to render but you still have a copy of your arrays in RAM (at least you should, when you call glVertexPointer !).

When I say "find the closest vertex", I mean find it in this array you have in RAM.

Does that make things clearer ? If it doesn't, please tell me where these explanations are unclear.

Regards.

Eric

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•