PDA

View Full Version : Picking and glRotate



Dominik
04-16-2002, 08:05 AM
Hi,

i got a little problem here.

on init o do:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,500.0f);
glMatrixMode(GL_MODELVIEW);

on my frame-rendering i do:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-75.0f);
glRotatef(pitch,1.0f,0.0f,0.0f);
glRotatef(heading,0.0f,1.0f,0.0f);
glTranslatef(xtra,ytra,zoom);

no i need to implement picking.

what do i need beside the picking part (init of the buffer and switching to GL_SELECT) where to put my rotate stuf to place me at the right point in the world:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y), 1.0f, 1.0f, viewport);
// Apply The Perspective Matrix
gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
drawmydatawiththeglloadname();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

Furrage
04-17-2002, 05:56 AM
Have you looked through the red book. It's pretty clear on what to do. You can get a copy in PDF format from http://www.ime.usp.br/~massaro/opengl/redbook/

Also I noticed that the depths specified in gluPerspective differ between the one to initialise and the one to pick. You need to keep them the same or you may miss some items you draw when picking.

Dominik
04-17-2002, 05:59 AM
OH man as you said the 500/100 was the problem in the z.

thanks a lot!