Skip to main content
gamedev.net
🔒 Locked

Mouse Picking

Started by MirekMalysz Jul 12, 2005 at 7:48 PM 2 replies 900+ views
Original Post
MirekMalysz
MirekMalysz
ok i have a problem, i used the tutorial on nehe's site for mouse picking, but the problem is that i have 2 objects on the screen, and wen i click on one, how can i differinciate which one i have clicked on? here is my code for creating the objects: //the first object glPopMatrix(); glLoadIdentity(); glPushName(1); DrawOb1(); glPushMatrix(); //the second object glPushName(1); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(6.5f ,-4.5f,-14.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(7.0f ,-4.5f,-14.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(7.0f ,-5.0f,-14.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(6.5f ,-5.0f,-14.0f); glEnd(); //My mouse event GLint hits; GLuint selectBuffer[512]; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(512, selectBuffer); (void) glRenderMode(GL_SELECT); glInitNames(); glPushName(1); 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); // Select The Modelview Matrix DrawOb1(); // Render The Targets To The Selection Buffer Move_Btn(); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glPopMatrix(); // Pop The Projection Matrix glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix hits=glRenderMode(GL_RENDER); // Switch To Render Mode, Find Out How Many if (hits> 0){ int choose = buffer[3]; // Make Our Selection The First Object int depth = buffer[1]; // Store How Far Away It Is PlaySound("click.wav",NULL,SND_ASYNC); }
BladeWise
BladeWise
If you are calling about Selection (as far as I know it's different from picking, but maybe I'm wrong), you need to associate a "name" to your objects, using glPushName and glPopName, so you'll be able to read that data into the selection buffer, as specified in the tutorial... names are integer values...
MirekMalysz
MirekMalysz
ahhh alrite thx, ill try it out
Kalidor
Kalidor
Quote:
Original post by MirekMalysz
//the first objectglPopMatrix();    <--glLoadIdentity();glPushName(1);DrawOb1();	glPushMatrix();   <--
You probably want to swap those two lines as well, unless you're doing something unconventional.

Topic Locked

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

Sign in to reply to this topic.