PDA

View Full Version : Picking



marshiell
12-16-2010, 10:55 AM
Hello,
I try since few days to make the picking work on my program but it doesn't. The results are weird:


Slot 0: - Value: 1
Slot 1: - Value: -103863766
Slot 2: - Value: -103863766
Slot 3: - Value: 1
Slot 4: - Value: 0
Slot 5: - Value: 0
Slot 6: - Value: 0
Slot 7: - Value: 0
Slot 8: - Value: 0
Slot 9: - Value: 0
Slot 10: - Value: 0
Slot 11: - Value: 0
Slot 12: - Value: 0
Slot 13: - Value: 0
Slot 14: - Value: 0
Slot 15: - Value: 0
Slot 16: - Value: 0
Slot 17: - Value: 0
Slot 18: - Value: 0
Slot 19: - Value: 0
Slot 20: - Value: 0
Slot 21: - Value: 0
Slot 22: - Value: 0
Slot 23: - Value: 0
Buff size: 1
click on x:248,y:236
1 hits:
Number: 1
Min Z: 42
Max Z: 42
Name on stack: 1



though my code is this :

double x=clavier.getEvent().button.x;
double y=480-clavier.getEvent().button.y;

printf("click on x:%g,y:%g\n",x,y);

GLuint buff[64] = {0};
GLint hits, viewport[4];
glSelectBuffer(512, buff);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix(x, y, 1.0f, 1.0f, viewport);
gluPerspective(70, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);

glLoadName(1);
//draw a cube



glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

hits = glRenderMode(GL_RENDER);

list_hits(hits, buff);

gl_selall(hits, buff);




void Jeu::gl_selall(GLint hits, GLuint *buff)
{
GLuint *p;
int i;

terrain.dessinerPick();

p = buff;
for (i = 0; i < 6 * 4; i++)
{
printf("Slot %d: - Value: %d\n", i, p[i]);
}

printf("Buff size: %x\n", (GLbyte)buff[0]);
}


void list_hits(GLint hits, GLuint *names)
{
int i;
printf("%d hits:\n", hits);

for (i = 0; i < hits; i++)
printf( "Number: %d\n"
"Min Z: %d\n"
"Max Z: %d\n"
"Name on stack: %d\n",
(GLubyte)names[i * 4],
(GLubyte)names[i * 4 + 1],
(GLubyte)names[i * 4 + 2],
(GLubyte)names[i * 4 + 3]
);

printf("\n");
}



Thankyou :)

marshiell
12-17-2010, 08:07 AM
I think the problem comes from the position of the camera. How could I change it when I am picking?

marshiell
12-18-2010, 06:48 AM
do you guys have any idea?

mfort
12-18-2010, 10:18 AM
Why do you think it does not work?
The weird code is this:


(GLubyte)names[i * 4 + i]

Why are you casting it to byte? It is 32bit integer.

marshiell
12-19-2010, 04:47 AM
Yes but this part doesn't actually cause much trouble because the probleme is indeed earlier, when I try the picking. I mean, when I click somewhere on the screen it doesn't detect the object as well :(

mfort
12-19-2010, 10:30 AM
How do you set viewport array? I do not see any assignment.

marshiell
12-19-2010, 10:58 AM
You're right but even if I add this :
glGetIntegerv(GL_VIEWPORT,viewport); before gluPickMatrix(x, y, 1.0f, 1.0f, viewport);
It is still the same :(

marshiell
12-20-2010, 10:28 AM
No idea dude?