Picking a zone of the screen, but visible objects only

Started by
5 comments, last by Floating 21 years, 6 months ago
Hi, I implemented a picking function which allows to select all objects touching the inside of a specified zone of my view (with gluPickMatrix). The only problem is that everything in that zone gets selected (also objects which can''t be seen because hidden by others). So my question: is there an easy way of selecting only visible objects in my zone?? I was thinking of rendering a scene with indexes colors indicating the object''s ID, then going through all rendered pixels. How can this be easily achieved? Is there a better/easier way?? Thanks
Advertisement
>>So my question: is there an easy way of selecting only visible objects in my zone?? I was thinking of rendering a scene with indexes colors indicating the object''s ID, then going through all rendered pixels. How can this be easily achieved? Is there a better/easier way??<<

yes this is an easy way, watch out though if u have dithering enabled

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Thanks for the quick reply.
How do I switch to indexed colors?
u dont need to, just draw each primative (object) in a different color watch out though with 16bit color window u are limited to 65535 different objects though with 32bit u can do 4billion.

heres basically what u do (16 bit will need to be treated differently)

drawobject()
{
warning these bit operations are most likely wrong but it should give u the idea
r = indexcounter%256; // or &255
g = (indexcounter<<8)%256;
b = (indexcounter<<16)%256;

glcolorub(r,g,b)
draw the object
indexcounter++
}

indexcounter=0;
drawobject()
drawobject()
drawobject()



(btw ive used this method to pick objects when theres been over 2million different on the screen so it does scale very well)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Thanks a lot Zedzeek
When using this method be sure to disable lighting, set the shading model to GL_FLAT, and disable dithering as zedzeek suggested (dithering is enabled by default, so be sure to disable it during selection if you haven''t done so already).

Be aware of the bit depth of your current platform. If the number of IDs required is greater than the number of colors possible at that bit depth you''ll have to do selection in two or more passes. The Red Book has a good explanation of this method on page 572.
The above should read "Be aware of the bit depth your game is running at".

This topic is closed to new replies.

Advertisement