which is the fastest way to perform a selection?

i would like to know which is the fastest way to perform a selection, let say we have about 10000 polygon and each polygon consist of 10 point(3D point). If we use glLoadName() to assign an id to each polygon, when we select all the object, the hits record will store 10000 hits, and i use this method to check which polygons are in the selected area.

m_object// my list to store all the object
m_selection// list to store selected object

// draw object

POSITION pos=m_object.GetHeadPosition();

CDrawObj *pObj= m_object.GetNext(pos);


// selection
int id[40000];

GLuint buffer[BUF_SIZE];
glSelectBuffer (BUF_SIZE, buffer);

for(int i=0;i<40000;i++)

for(int i=0;i<hits;i++){

POSITION pos= m_object.GetHeadPosition();
CDrawObj *pObj=m_object.GetNext(pos);
// if buffer record equal to object id

i find that this method is slow when the number of object is increace. Does anyone know the better way to perform selection.

If the geometry is fairly static you could store it in an octree (or quadtree if it’s 2D), and them determine which nodes of the tree were hit by the selection point and only perform the selection on the polygons within those nodes.

i am doing a CAD program, and the list to store objects is declared dynamic. Which can be one object or even 100000 objects. i wonder autocad can do a selection very fast even with a big model. Does anyone know how autocad do it.

Hi !

One way is to keep a bounding box around all complex objects and do a picking on the bounding boxes, once you have found the object that was hit you can do a new picking but only render the object that was hit the first time.

This would cut down the amount of geometry you need to process for the picking.