Jump to content
  • Advertisement
Sign in to follow this  
domorchard

OpenGL Selection problem (in 3D)

This topic is 4009 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

Hi, I am trying to use the GL selection/picking method for selecting cubes in a 3d environment but am having a lot of trouble getting OpenGL to actually pick the cubes, there are some various translations and rotations that have to be performed first. The following is my selection/picking function: void startPicking(int x, int y) { GLint hits, viewport[4]; GLuint selectBuf[128]; // Hook select buffer glSelectBuffer (128, selectBuf); // Enter select mode glRenderMode (GL_SELECT); glMatrixMode(GL_PROJECTION); glPushMatrix(); // activate 3D transformation glLoadIdentity(); // Pick 1x1 area glGetIntegerv(GL_VIEWPORT,viewport); gluPickMatrix((GLdouble) x,(GLdouble)(viewport[3]-y),1.0f,1.0f,viewport); // 3D compute 3D transformation glScalef(pos.GetScale(),pos.GetScale(),pos.GetScale()); glTranslatef(pos.GetTransX(), pos.GetTransY(), 0.0f); glRotatef(pos.GetRotX(), 1.0f, 0.0f, 0.0f); glRotatef(pos.GetRotY(), 0.0f, 1.0f, 0.0f); glRotatef(pos.GetRotZ(), 0.0f, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glInitNames(); // draw wire frame function with naming drawWireFrame(true); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glFlush(); hits = glRenderMode (GL_RENDER); // Process hits if (hits != 0){ processHits2(hits,selectBuf); } } Essentially I am using this function to select all the nearest objects on the screen by looping through each pixel and calling this method, however this method (even when hooked up to the cursor) fails to select correctly. I have seen LOTS of examples of this and have tried quite a lot of variations but still have no leads. Any thoughts would be welcome this is for an urgent project. Thanks.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!