Jump to content
  • Advertisement
Sign in to follow this  

openGL picking

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

I am using the NeHe tutorial with some modifactions, with it i got picking too work, but then i need to be able to place objects after i picked them up, so for that i needed to use glOrtho(0,640,480,0,-1,1); so that i could use the mouse coords to place the object. So now i have decided that i may as well just draw everything with glOrtho(0,640,480,0,-1,1); but now picking does not work correctly, no matter where i click on the screen it detects a collision with my object, here is my selection code: void Selection(void) { GLuint buffer[512]; GLint hits; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(512, buffer); (void) glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y), 1.0f, 1.0f, viewport); gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); DrawTargets(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits=glRenderMode(GL_RENDER); if (hits > 0) { int choose = buffer[3]; x+=0.02f; pickedObject = choose; if (!object[choose].hit) { object[choose].x += 0.5; } } } I am still new to openGL so i am not sure how i need to modify my code to work, if anyone can help my out that would be great. Thanks

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.

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!