PDA

View Full Version : Picking problems



04-08-2002, 06:50 AM
Hi guys, I'm implementing a picking simple program..
I've got two solid cubes (with glutSolidCube). When I pick the cube0 works fine, when I pick the cube1 works fine, but when I pick around the scene (where is nothing), the selection tell me that I pick the cube1, what does happend?... Anybody has an idea???...

later
shark_pilot

Tux
04-08-2002, 06:59 AM
if not picking cube0 or cube1 then picking nothing.

that must you say to the (stupid) computer.

ps: please don't talk with your pc, yust coding ;.

Obliviator
04-08-2002, 07:04 AM
Originally posted by shark_pilot:
Hi guys, I'm implementing a picking simple program..
I've got two solid cubes (with glutSolidCube). When I pick the cube0 works fine, when I pick the cube1 works fine, but when I pick around the scene (where is nothing), the selection tell me that I pick the cube1, what does happend?... Anybody has an idea???...

later
shark_pilot


have you pushed a NULL name to your selection stack before selection-rendering?

e.g: glPushName( 0 );
when doing so, none of your object should have the id '0'...

04-08-2002, 07:06 AM
This what I did in the code:

if(hits>0)
{
m_selection=selectBuff[3];
if(m_selection>=0)
{
switch(m_selection)
{
case CUBE0:
AfxMessageBox("Ha seleccionado el cube 0");
break;
case CUBE1:
AfxMessageBox("Ha seleccionado el cube 1");
break;
default:
break;
}
....
....
....
....

04-08-2002, 07:15 AM
This is my drawobjects...

void COpenGLViewAlex: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawObjects()
{
glColor3ub(200,150,50);
glInitNames();
glPushName(0);

if (TypePolygon == 1)
{
glPushMatrix();
glTranslatef(0,0,-50);
glRotatef(70,1,1,1);
glutSolidCube(xp);
glLoadName(1);
glPushName(1);
glPopName();
glPopMatrix();

glPushMatrix();
glTranslatef(30,0,-50);
glRotatef(20,0,0,1);
glutSolidCube(10);
glLoadName(2);
glPushName(2);
glPopName();
glPopMatrix();

}
if (TypePolygon == 2)
glutSolidCube(xp);
}

Is this the correct way to draw objects with stack names for picking selection??..

Obliviator
04-08-2002, 07:22 AM
Originally posted by shark_pilot:
This is my drawobjects...

void COpenGLViewAlex: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawObjects()
{
glColor3ub(200,150,50);
glInitNames();
glPushName(0);

if (TypePolygon == 1)
{
glPushMatrix();
glTranslatef(0,0,-50);
glRotatef(70,1,1,1);
glutSolidCube(xp);
glLoadName(1);
glPushName(1);
glPopName();
glPopMatrix();

glPushMatrix();
glTranslatef(30,0,-50);
glRotatef(20,0,0,1);
glutSolidCube(10);
glLoadName(2);
glPushName(2);
glPopName();
glPopMatrix();

}
if (TypePolygon == 2)
glutSolidCube(xp);
}

Is this the correct way to draw objects with stack names for picking selection??..

don't pop your names!

and call pushName( ) before your glutSolidCube( ), so that it also receives a name

04-08-2002, 07:44 AM
I did what you said, but it still doesn't work...

Furrage
04-08-2002, 11:45 AM
1) Use glPushName() only once (immediately after initialising the name stack with glInitNames()). Remove all the calls to glPopName().

2) Make your calls to glLoadName() before you draw the object, not after. Otherwise your names are going to come out wrong.

04-10-2002, 03:42 AM
You may need to set selectBuff[3] to 0. In other words, you do:
case CUBE1:
// do stuff
selectBuff[3] = 0;
break;
otherwise, selectBuff[3] will still have the last entrance down.

04-10-2002, 02:11 PM
Guys, I did all the things that you've said but still doesn't work...
I don't understand...

Furrage
04-11-2002, 05:24 AM
I think it might be better to set selectBuff[3] to 0 at the start of your picking code before any picking is done.

Originally posted by Unregistered:
You may need to set selectBuff[3] to 0. In other words, you do:
case CUBE1:
// do stuff
selectBuff[3] = 0;
break;
otherwise, selectBuff[3] will still have the last entrance down.

Post all your code called directly or indirectly when you do a mouse click.

04-11-2002, 05:53 AM
This is my drawobjects...

void COpenGLViewAlex: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawObjects()
{
glColor3ub(200,150,50);
glInitNames();
glPushName(0);

if (TypePolygon == 1)
{
glPushMatrix();
glTranslatef(0,0,-50);
glRotatef(70,1,1,1);
glLoadName(1); //name defined BEFORE drawing the object.
glutSolidCube(xp);
glPopMatrix();

glPushMatrix();
glTranslatef(30,0,-50);
glRotatef(20,0,0,1);
glloadname(2); //name defined BEFORE drawing the object.
glutSolidCube(10);
glPopMatrix();

}
if (TypePolygon == 2)
glloadname(3); //which name have to be this if typepolygon==2?
glutSolidCube(xp);
}

The initname and pushname(0) have to be defined just once before start drawing somthing.

Also note that when opengl give you the objects picked, MORE THAT ONE OBJECT COULD BE RETURNED, so if hit=3 mean that there are 3 object selected whit your last click.

This is becouse opengl will give all objects draw behind the object that you clicked.

tp.