Picking

Started by
5 comments, last by NewDeal 22 years, 8 months ago
Im trying to implement some form of selection in my app but without much luck. Anyways, ive stumbled over several methods for using the mouse to select objects in a 3D world (Picking, Selection, Feedback, ray-casting). Before i go any further i would like to know what the best/normal method is. Im working on a spacesim and will use this for selecting objects on a 3D map. I have zero experience with this so please enlighten me. Thanks in advance .
Advertisement
I myself have just started this, but i will give you the insight on what im trying.

It boils down to this.

When you click the wouse you want to redraw the scene, but without any lighting,textureing,dithering or anything that will affect the flat colors. and then when you draw the scene you give every pickable object a different color. Then use the command glReadPixels, supplying the mouse coords and all the proper values which writes to an array you specify as the last parameter.

You can then use this array to determine what object was clicked.
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.
I use ray-casting (but only because its easy to test for it in my already implemented collision detection routine)

One problem to ray-casting is that there has to be a cut-off point somewhere.. i have my rays being of length 100 units (so that i can select an object 100 units away from the player).

I find ray-casting probably as one of the easiest ways of implementing selection capabilities into your game - which is probably easier than specifying different colours/properties for every object in your game.
OK, thanks guys

Eber that sounds like a pretty neat way of doing it , ill give it a try.

wAV i wasnt able to find a decent tutorial on raycasting here on Gamedev. Any chance you could point me in the right direction (id like to know my options).

Thanks to both of you.
The glReadPixels method is by far the easiest way to do this (apart from OGL''s selection buffer of course!). It has the advantage of more accurate selection too. Raycasting works with bounding volumes (or simplified meshes of your objects) so will never be as accurate as reading the frame buffer.

It has the disadvantages of not being able to perform multiple selection easily (IE to do rubber banding you''d have to check every pixel in the selected area with glReadPixel) and frame buffer ops with most desktop GL implementations are pretty unoptimised - unless you''re running on nVidia hardware.

If you already have the collision detection in place, go with ray casting.

Paul Groves
pauls opengl page
Paul Grovespauls opengl page
The problem with the the colour ID method (glReadPixels) is it''s precision, actually it is too accurate. To select an object, you have to point the mouse _exactly_ on a rendered pixel belonging to that object. This can be very difficult, if the object is very small from the current point of view (remember the ''hunt-the-pixel'' syndrome in those old 2D adventure games ? Horrible )
Raycasting through oriented bounding boxes is far more intuitive for the player: he has to point the mouse near the object of interest, and it gets selected.

-AH
couldnt you read like a 3x3 grid of pixels when you click on something, then you would just have to check which color was in the array more times?
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.

This topic is closed to new replies.

Advertisement