Sign in to follow this  

openGL picking

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this