PDA

View Full Version : opengl selection problem



maximian
12-31-2003, 08:47 PM
I took the example code in the Opengl Bible and
integrated it into my application. However I have a problem.

No matter how small I set the pick volume, it still returns large numbers of results. In fact it looks like it returns the same number of hits, say 29 for a point on my model(9000 polys). It is fairly accurate in detecting if I hit the model, or white space. So it seems like the code is working.

I tried this for the gluPickMatrix

(x,viewport[3]-y, .01, .01, viewport)

When, I apply this to my regular renderer, it correctly zooms in to a single polygon.

But for the same point, when I do selection, it returns a large number of values.

Any suggestions would be helpful. I can post my selection code if need be, but it is the same as blue book.

mikael_aronsson
01-01-2004, 12:32 AM
Hi !

You are settings the names correct ? just so you don't push many names on the stack or something like that ?

Mikael

maximian
01-01-2004, 02:54 PM
This problem happens when I push my regular hierarchy of names, as well as when I push names only for the primitives.

Ie

for all triangles
glPushName(i);
glBegin(GL_TRIANGLES);
...
glEnd();
glPopName();

The rendering code is fine.

KreK
01-03-2004, 03:28 AM
I recently worked on a program with OpenGL selection. We used display lists.
Each object in a display lists was 'marked' with a glLoadName( objID ); where objID
is some unique integer for every selectable object.

We used a relatively large selection buffer, something like
GLuint selectionBuffer[128];

Each selected object takes 4 entries in that buffer ( hits number, z1, z2 and name ID ).
When exiting from selection mode to render mode, we would always get multiple selection
hits. Basically, all objects under selection cursor would get selected, even when stacked
one over the other.

So we had to perform filtering of selection buffer, to find the closest entry:




GLint hits = glRenderMode( GL_RENDER );
if( hits > 0 )
{
if( 1 == hits )
{
pickedObjID = selectionBuffer[3];
}
else
{
float z = 100000;
pickedObjID = 0;

for( int hit = 0; hit < hits; ++hit )
{
if( z > (float)selectionBuffer[4*hit + 1]/0x7fffffff )
{
z = (float)selectionBuffer[4*hit + 1]/0x7fffffff;
pickedObjID = selectionBuffer[4*hit + 3];
}
}
}
}


After the above code block, we would end-up with a correct 'pickedObjID'.
That is the same ID we used for glLoadName( objID ); when creating display lists.

maximian
01-03-2004, 03:00 PM
Thank you. But my problem is more fundemental.

I am doing hit testing per polygon. Assigning a
name for each polygon in the model. Polygons are not stacked, and I am sure I am selecting only one.

The funny thing is, If I select toward the left edge of model, I will either get 0,1 hit. As I move to the right across the surface of the model, the number of elements returned in selection increases linearly and relatively equivalent to the number of polygons to the left of my pointer. It seems almost cumulative.

I am completely confused.

maximian
01-05-2004, 09:30 AM
Okay, so I tried selection with GL_POINTS.

for all vertices
glPushName(i)
glBegin(GL_POINTS);
glVertex3fv(...
glEnd(GL_POINTS);
glPopName().

I get exactly one hit when I click on a point. 0 if I click in space.

And it seems to work fine. It seems the problem is with polygons. What is going on?
I am so confused, if any one has a suggestion please help. Thanks.

EDIT: I checked with a larger model, and the hit selection is hit or miss. No matter the size of glu pick matrix, for some points
it will return 1 hit, other 0. Even though a point is fully visible, it seems to not return a hit. However, at least it is not return multiple hit records.

EDIT: Never mind, all problems are now fixed.
Sorry to be a bother.

[This message has been edited by maximian (edited 01-05-2004).]

[This message has been edited by maximian (edited 01-05-2004).]