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???..
Originally posted by shark_pilot:
[b]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[/b]
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’…
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.
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.
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.