Picking a zone of the screen, but visible objects only
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
>>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
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
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
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement