The mouse callback function is responsible for handling mouse button clicks, both press and release. For our example, only left button events are handled by the callback function (keep in mind that the right button triggers a popup menu in the full example). GLUT passes to our function an integer identifying the button pressed (or released), the state of the button (up or down) and the x and y device location of the mouse when the button event occurred.

We use the mouse in our example to update the eyepoint in the viewing transformation. We start the process by first establishing the currentEyePoint and measure from this "base point" the changes to be made as the user drags the mouse. The changes are computed from the spherical coordinates radius, angle of longitude (theta) and angle of latitude (phi). The radius is fixed and computed in our Init Function. We compute here with a call to the Compute Angles Function the two angles. Further, we record in the variables startX and startY the x and y mouse coordinates when the user presses the left button and use these values in the motion handler to compute the amount of change to be made to the eye coordinates.