PDA

View Full Version : How to select objects while they are overlapping each other?



jiangerlai
03-24-2003, 11:51 PM
How to know which one is most near to you when you click on them,using select or feedback? Any guide or source code will be greatly appreciated!

mikael_aronsson
03-25-2003, 01:29 AM
Hi !

Depth information is included in the pick buffer when you use selection:

This is the code I use to process the pick buffer returned from selection, the one closest to the viewer is returned here (as an index)

DWORD handle_selection_func( GLuint *pickbuffer, int nhits)
{
DWORD d1;
DWORD d2;
DWORD n;
DWORD zmin;
DWORD zmax;
int i;
int sel = 0;

for( i = 0, zmin = zmax = 4294967295U; nhits > 0; i += n + 3, nhits--)
{
n = pickbuffer[ i];
d1= pickbuffer[ i + 1];
d2= pickbuffer[ i + 2];

if( pickbuffer[ i + 3] != 0)
a hit is found ( pickbuffer[ i + 3]);

if( d1 < zmin | | (d1 == zmin && d2 <= zmax))
{
zmin = d1;
zmax = d2;
sel = i;
}
}

return( pickbuffer[ sel + 3]);
}

Mikael


[This message has been edited by mikael_aronsson (edited 03-25-2003).]

[This message has been edited by mikael_aronsson (edited 03-25-2003).]