Results 1 to 4 of 4

Thread: picking with vertex arrays

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    2

    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?

    Somebody please help...
    Kyllan

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    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. #3
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    2

    Re: picking with vertex arrays

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

    Kyllan

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    880

    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

Similar Threads

  1. arrays of arrays as vertex output/fragment input
    By tsojtsoj in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-17-2018, 08:02 PM
  2. Vertex Arrays, interleaved arrays, mouseMove func
    By Nibirue in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-13-2012, 11:17 AM
  3. Performing Color Picking when using Vertex arrays
    By pontifikas in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-08-2010, 01:06 AM
  4. Vertex Arrays: Interleaved or seperated arrays?
    By Jan in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 06-21-2005, 05:25 AM
  5. Picking and Vertex arrays
    By hawn in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-15-2000, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean