Selecting Objects... or not

Started by
0 comments, last by Kincaid 18 years, 6 months ago
Hello I've been trying to implement picking in my 3d scene, but cant seem to get it to work properly. Still not clear on some details also about how things work. this is the code i use (it is triggered on leftmouse click) void Selection() { const int BUFSIZE = 512; GLuint Buffer [BUFSIZE]; int HITS = 0; GLint viewport [4]; glGetIntegerv (GL_VIEWPORT, viewport); glSelectBuffer (BUFSIZE, Buffer); glRenderMode (GL_SELECT); glInitNames ( ); glPushName (0); glMatrixMode ( GL_PROJECTION); glPushMatrix ( ); // save matrix glLoadIdentity ( ); // set up pickarea -> gluPickMatrix ( (GLdouble) mouse_x, (GLdouble) (viewport[3] - mouse_y), 5.0, 5.0, viewport); SetPerspective ( 45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glPushMatrix ( ); // render the view volume, so save matrix glLoadIdentity ( ); glLoadName (1); // load name for pickes object Project ( &OBJECT); //project the object via DisplayList CAM.TransLateAndRotate(); // move the camera according to where it actually is in de 3d scene HITS = glRenderMode ( GL_RENDER ); // get hitrecord processHits ( HITS, Buffer ); // function to process (now simply, when some hit , please tell me) // restore both matrices to go ahead a it was glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } What am I doing wrong ?? Am a little doubtfull about the enitre process... As far as I understand; - make buffer for hitrecord - save viewportsetting for perspective calculations - init and push name - ProjectionMode to set up pickarea, and set it up via gluPickMatrix and gluPerspective (save old matrix) - Mode that the scene is rendered in and render object to select, just like in the scene (translates and rotations incl.) - process hits - restore matrices Is this correct ? With this code i get nothing. I did get some evidence of hits by toying around with some things, but the hit area was totally of. [Edited by - Kincaid on October 8, 2005 12:19:02 PM]
Advertisement
anyone ?

This topic is closed to new replies.

Advertisement