PDA

View Full Version : picking and vertex array



guju
06-04-2002, 06:58 AM
Hi There!
I create my fe-mesh with vertex arrays. To define the rotation center the user can pick any vertex. But my problem is, that i do not know how to define my name stack? I can program my one code for picking with the z-buffer. But the next step is to let the user select some elements in an defined box! What is best for this two problems??
Thanks
Juergen

martin_marinov
06-04-2002, 08:02 AM
Hi,
I dont think you can use select mode to select a vertex from a mesh which you draw with few calls to glDrawElements and etc.
Maybe I'm wrong... Instead you may assign an unique color to each of your vertices, to draw offscreen and to pick the selection (the so called color picking trick...)
Regards
Martin

guju
06-04-2002, 07:49 PM
That means, i should enter first the selection mode, draw the vertices with unique colors and then pick the color with glreadpixels. How can i use this process for selection of more vertices in an bounding volume?
Thanks
Juergen

martin_marinov
06-05-2002, 02:41 AM
You dont need to enter selection mode - you just need to render offsceen the scene (the object). For a bounding rect selection you just need to see which vertices (colors) are in the rect. Don't draw triangles, quads, lines, just draw points.
I think you can find more info by searching the forum archives. this was discussed here before.
Regards
Martin

guju
06-05-2002, 05:06 AM
I am not that expert, so what does it mean:render offsceen the scene ?
Now i only call the following code:
glBegin(GL_POINTS);
for(int i=0;i<numVertices;i++){
glColor3ub( i&0xff, (i>>8)&0xff, (i>>16)&0xff );
glVertex3f(vertices[i*3],vertices[i*3+1],vertices[i*3+2]);
}
glEnd();
glReadPixels( xRot_old, MyGLWidget::height()-yRot_old,5, 5, GL_RGB, GL_UNSIGNED_BYTE, pixel);
glReadPixels( xRot_old, MyGLWidget::height()-yRot_old,5, 5, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
but GlPixels also returns the color of the lines, which i do not draw, only nodes??
Thanks

ScottManDeath
06-05-2002, 05:19 AM
Hi

perhaps you can use the feedback buffer to accomplish your problem.

At first render your vertices into feedback buffer as GL_POINTS. When you read it out you get the points as transformed window coordinates. Then you can loop from your mouse position through the feedback returned points and find that with the minimal distance. When you found it, you know which index it has you know which vertex it was. Pay attention to the mouse y coordinate beeing inverted.

Im not sure if vertex arrays render the points in order but you can use a feedback render pass only when mouse click occured, so it would be not such a pain to use a loop over glvertex*

Bye
ScottManDeath

guju
06-05-2002, 06:50 AM
If i am in double buffer mode and i draw some vertices, they are drawn in the back buffer. Do i have to make first a swap buffer?
Then i make
glReadBuffer(GL_BACK);
glReadPixels( xRot_old, MyGLWidget::height()-yRot_old,20, 20, GL_RGB, GL_UNSIGNED_BYTE, pixel);
to get my colors of the nodes. Is this correct??

martin_marinov
06-05-2002, 07:13 AM
Originally posted by guju:
I am not that expert, so what does it mean:render offsceen the scene ?
Now i only call the following code:
glBegin(GL_POINTS);
for(int i=0;i<numVertices;i++){
glColor3ub( i&0xff, (i>>8)&0xff, (i>>16)&0xff );
glVertex3f(vertices[i*3],vertices[i*3+1],vertices[i*3+2]);
}
glEnd();
glReadPixels( xRot_old, MyGLWidget::height()-yRot_old,5, 5, GL_RGB, GL_UNSIGNED_BYTE, pixel);
glReadPixels( xRot_old, MyGLWidget::height()-yRot_old,5, 5, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
but GlPixels also returns the color of the lines, which i do not draw, only nodes??
Thanks

Hi, it seems that I misunderstood you...
I thought that you use glDrawElements() or glDrawArrays() to render your scene. If you render the things as above, you can use select mode. If you still want to use color picking, just draw the scene without calling SwapBuffers - (this is what I mean under offscreen rendering). Try really to search the forum archives about selection mode - you may find usefull info there.

Regards
Martin

NordFenris
06-05-2002, 08:08 AM
I have addressed this in another thread - search for my user name to find it.

However, what you want to do is to loop through all your vertices, use gluProject on them, and then store all the projected (2D) coordinates of all your vertices in an array. Then, you click, save the mouse position (don't forget to invert Y axis) and then sift through your array to find a match. This way, you can easily do sweep selections and such.

BTW, the thread's name was "sweep selection".