Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to implement scene picking (for mouse clicks, moves, etc.). What is the best, fastest way? I used to use glSelectBuffer and glRenderMode with GL_SELECT and then render whole scene again (of course with boost, without textures, heavy shaders, etc.).

It's too slow render recursively all nodes and geometries for one number (geometry ID) on every mouse click, move and drag. Does anybody know better way?

EDIT: Solution with reading depth buffer seems fain, but what if I don't want to pick some geometries and they are already drown to buffer? Finding box which contains point can be imprecisely, since point can be in multiple boxes.

Is it possible to write into two frame buffers, depth buffers in one draw? Then I can write geometry id to one buffer through shader. And what about speed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
533 views
Welcome To Ask or Share your Answers For Others

1 Answer

In the past I've used glReadPixels( xf, yf, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &zf); to read the value of the depth buffer at a point (xf, yf) in screen space. You can then unproject this point back into world coordinates (multiply by the inverse of the modelview and projection matrices. This can be done with gluUnProject provided you're happy including the GLU library in your application.

This gives you a coordinate, you then need to search through your objects to find one that has a bounding box that contains this coordinate. This object is the one selected.

I'd recommend searching for information on Unprojecting if you want more information about this, also https://www.opengl.org/archives/resources/faq/technical/selection.htm is helpful (and suggests other techniques you could use).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...