Contents / Previous / Next


gluPickMatrix - define a picking region

gluPickMatrix creates a projection matrix that can be used to restrict drawing to a small region of the viewport.
This is typically useful to determine what objects are being drawn near the cursor.
 void gluPickMatrix( GLdouble x, GLdouble y, 
                     GLdouble width, GLdouble height, 
                     GLint viewport[4] )

x, y: center of a picking region in window coordinates.	 	
width, height: width and height of the picking region in window coordinates.
viewport: The current viewport (view window size, as from a glGetIntegerv call). 

Use gluPickMatrix to restrict drawing to a small region around the cursor.
Then, enter selection mode (with glRenderMode) and rerender the scene.
All primitives that would have been drawn near the cursor are identified and stored in the selection buffer.

Example:When rendering a scene as follows:

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(...);
 glMatrixMode(GL_MODELVIEW);
 /* Draw the scene */
a portion of the viewport can be selected as a pick region by calling gluPickMatrix,
then a command (such as gluPerspective) to multiply the perspective matrix by the pick matrix:
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPickMatrix(x, y, width, height, viewport);
 gluPerspective(...);
 glMatrixMode(GL_MODELVIEW);
 /* Draw the scene */