Skip to main content
GameDev.net gamedev.net
🔒 Locked

about SelectBuffer?

Started by doilathekg Feb 26, 2008 at 4:15 AM 1 replies 600+ views
Original Post
doilathekg
doilathekg
This is the code how to get Object ID. But i don't known how to get (x,y,z) coord(3D) of Object by mouse select? EveryOne help me!. Thank All. int RetrieveObjectID(int x, int y) { int objectsFound = 0; unsigned int selectBuffer[32] = {0}; glSelectBuffer(32, selectBuffer); // Setup our selection buffer to accept object ID's glGetIntegerv(GL_VIEWPORT, viewportCoords); glMatrixMode(GL_PROJECTION); glPushMatrix(); glRenderMode(GL_SELECT); glLoadIdentity(); gluPickMatrix(x, viewportCoords[3] - y, 2, 2, viewportCoords); gluPerspective(45.0f,(float)g_rRect.right/(float)g_rRect.bottom,0.1f,150.0f); glMatrixMode(GL_MODELVIEW); RenderScene(); objectsFound = glRenderMode(GL_RENDER); // glMatrixMode(GL_PROJECTION); // Put glPopMatrix(); glMatrixMode(GL_MODELVIEW); if (objectsFound > 0) { int selectedObject = selectBuffer[3]; for(int i = 1; i < objectsFound; i++) { if(selectBuffer[(i * 4) + 1] < lowestDepth) { lowestDepth = selectBuffer[(i * 4) + 1]; selectedObject = selectBuffer[(i * 4) + 3]; } } return selectedObject; } return 0; } [Edited by - doilathekg on February 26, 2008 4:45:24 AM]
polymorphed
polymorphed
Check out this GLU function:

gluUnProject

It maps 2D window coordinates to 3D object space, but you have to supply it with modelview and projection matrices.
while (tired) DrinkCoffee();
_the_phantom_
_the_phantom_
Just as an aside; the selection buffer is considered legacy and in newer hardware practically kills the framerate.

In short; don't use it, do your own selection in software instead.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.