Jump to content
  • Advertisement
Sign in to follow this  

Selecting Objects... or not

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!