Picking

Started by
14 comments, last by Rectangle 11 years, 7 months ago
Do you recommend I use this method?
http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking

I'm asking this, because I used it in my project and I have a problem.


My cube in the scene has ID 1:
nq3eo0.png

The red square on top of the cube was made by me in photoshop. It is to show the area where I click and returns the selected cube.
That is, the edges of the cube is shown by the function list_hits not selected anything, but I clicked on the edge of the cube!
http://mateusvitali.wordpress.com/
Advertisement

Do you recommend I use this method?
http://content.gpwik...torials:Picking

I'm asking this, because I used it in my project and I have a problem.

I would not recommend it. The reason is that it is based on deprecated legacy OpenGL. It is not the way OpenGL is used any longer. Well, it is obviously still supported, and it is quite easy to get going. There are two common ways to do picking these days. One is to do color picking, and the other is ray tracing.

Color picking is done with the help of OpenGL. The idea is to draw all objects with unique colors, and then read out the pixel at the position of the mouse. The color of that position will then identify the object. I had problems finding a good example based on modern OpenGL, but there is http://ogldev.atspace.co.uk/www/tutorial29/tutorial29.html. You may want to use different selection modes for faces, edges and corners, to make it easier to find what the user is clicking at.

Ray tracing is done manually. That is, you have to use mathematical libraries to trace a ray and check yourself for objects that are hit by the ray.
[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/
The "color picking" method is very interesting. However, ray tracing sounds more intuitive.

Also, with OpenGL being a graphics library, it seems a little hacky to use it for anything other than rendering ... It's probably a silly notion, but that's how I feel.

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+
Well, I suggest you to use "color picking" if you planning (in near future) to pick objects with alpha testing.

Best wishes, FXACE.
I was also wondering about this. For a game with a lot of selectable objects on screen and where you dont need to know wich triangle is under the cursor only wich object (lets say World of Warcraft) would it be best to use colour picking or ray tracing? I would assume colour picking would give you better performance when you have alot of objetcs but thats just my guess.
**NEVER** use the selection buffer. On all 3D hardware currently available, the selection buffer is implemented entirely in software. This is a massive ballache if you happen to use vertex or geometry shaders (i.e. everyone). On NVidia it will emulate that functionality in software (exceptionally slowly), and on ATI/Intel it will simply fail.

The colour buffer method is *slightly* better, however it's an extremely slow approach compared to rolling your own ray picking algorithms (people always forget that rasterising a tonne of triangles is actually very slow).

The colour buffer method is *slightly* better, however it's an extremely slow approach compared to rolling your own ray picking algorithms (people always forget that rasterising a tonne of triangles is actually very slow).


Can be true, but it depends on the situation. If you have a game running at decent FPS, say 40, then doing a color selection would take at most 1/40=25 ms. if you do the selection as a result from the player clicking, then it is no problem at all. The player will never notice the 25ms delay. Not only that, you maybe only need to draw the clickable objects and can skip everything else (depends on how the scene looks). Even better, the fragment shader for color selection is usually much simpler, it only draws a color (no need for lights and other effects).

But there are cases where it matters. If you want to continuously track where the pointer is, maybe highlighting the object behind the mouse pointer in every frame, then you would need to do the color picking much more frequently (maybe 30 times per second). If so, it can turn out costly and reduce the FPS significantly.

Ray tracing can be very easy and very hard, depending on the situation. If you only have a few monsters, and you want to find which one, then a simple bounding box can suffice. But there are more complicated use cases, where there are maybe millions of possible hits that have to be tested. That would require the use of an Octree,and other techniques.

So there is no single answer to this.
[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/
If you have a game running at decent FPS, say 40, then doing a color selection would take at most 1/40=25 ms.[/quote]
25ms is nothing to be proud of.

You are of course assuming that the players of your game have graphics hardware that's at least as good as yours, and not some integrated intel chip that struggles to render your game at 15fps....

The player will never notice the 25ms delay.[/quote]
Maybe not, but your physics/audio/networking systems will (and the player will notice problems there pretty quickly).

But there are more complicated use cases, where there are maybe millions of possible hits that have to be tested.[/quote]
And you see this as justification to use an inefficient technique?
I agree with most of what has been said. Color picking or ray/bounding-box testing are the way to go. A discussion about which technique is better makes little sense. They are fundamentally different approaches. If you need pixel perfect results, use color picking. If performance is more important, use ray/bounding-box picking. If you really want to, you can try a hybrid approach (select candidates with a ray/bounding-box test and render them using colors).
The Color picking would that be?

http://content.gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs
http://mateusvitali.wordpress.com/

This topic is closed to new replies.

Advertisement