Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Picking


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 VitaliBR   Members   -  Reputation: 147

Like
0Likes
Like

Posted 21 August 2012 - 04:34 AM

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:
Posted Image

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!

Sponsor:

#2 larspensjo   Members   -  Reputation: 1557

Like
2Likes
Like

Posted 21 August 2012 - 05:53 AM

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.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#3 Goran Milovanovic   Members   -  Reputation: 1104

Like
2Likes
Like

Posted 21 August 2012 - 07:07 AM

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 |
+---------------------------------------------------------------------+

#4 FXACE   Members   -  Reputation: 182

Like
0Likes
Like

Posted 21 August 2012 - 07:13 PM

Well, I suggest you to use "color picking" if you planning (in near future) to pick objects with alpha testing.

Best wishes, FXACE.

#5 Wilhelm van Huyssteen   Members   -  Reputation: 1002

Like
0Likes
Like

Posted 22 August 2012 - 03:36 AM

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.

Edited by Wilhelm van Huyssteen, 22 August 2012 - 04:06 AM.


#6 RobTheBloke   Crossbones+   -  Reputation: 2349

Like
0Likes
Like

Posted 22 August 2012 - 04:33 AM

**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).

#7 larspensjo   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 22 August 2012 - 05:39 AM

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.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#8 RobTheBloke   Crossbones+   -  Reputation: 2349

Like
0Likes
Like

Posted 22 August 2012 - 06:16 AM

If you have a game running at decent FPS, say 40, then doing a color selection would take at most 1/40=25 ms.

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.

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.

And you see this as justification to use an inefficient technique?

#9 kloffy   Members   -  Reputation: 930

Like
0Likes
Like

Posted 22 August 2012 - 08:02 AM

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).

#10 VitaliBR   Members   -  Reputation: 147

Like
0Likes
Like

Posted 23 August 2012 - 10:06 AM

The Color picking would that be?

http://content.gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs

#11 larspensjo   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 23 August 2012 - 10:17 AM

The Color picking would that be?

http://content.gpwik...nique_Color_IDs

Yes, the principles are right, but implemented using deprecated legacy OpenGL.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#12 VitaliBR   Members   -  Reputation: 147

Like
0Likes
Like

Posted 24 August 2012 - 08:59 AM


The Color picking would that be?

http://content.gpwik...nique_Color_IDs

Yes, the principles are right, but implemented using deprecated legacy OpenGL.


What is deprecated? glReadPixels?

#13 japro   Members   -  Reputation: 887

Like
0Likes
Like

Posted 24 August 2012 - 09:04 AM

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?

Usually you can get away with ray tracing against a simplified geometry (circles, ellipses, boxes...).

#14 larspensjo   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 24 August 2012 - 12:44 PM



The Color picking would that be?

http://content.gpwik...nique_Color_IDs

Yes, the principles are right, but implemented using deprecated legacy OpenGL.


What is deprecated? glReadPixels?

No, that is valid. The old ways are the use of glBegin(), glTranslatef(), glColor(), etc. It called "immediate mode", as you define the geometry on-the-fly. The correct way is to use Vertex Buffer Objects (VBO) and Vertex Array Objects (VAO). You will also have to define your own shader. At first glance, it looks much harder. And it is harder, to begin with.

For a general tutorial about OpenGL 3+, see Learning Modern 3D Graphics Programming or http://www.opengl-tutorial.org/.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#15 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 26 August 2012 - 07:14 AM

http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback_Mode
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#16 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 26 August 2012 - 08:17 AM

For the ray tracing method, here is a decent tutorial: http://schabby.de/picking-opengl-ray-tracing/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS