The interaction provided with this example allows the user to orbit the camera inside a sphere. Orbiting requires varing the camera's eyepoint. We create a smooth transition while the user drags the mouse by using two variables for the eyepoint, currentEyePoint and movingEyePoint.

As discussed in the tutorial Camera Animation, we change the eyepoint by moving it over a sphere centered at the look-at-point. Further, we calculate the rectangular coordinates (x, y and z) of the eyepoint from the spherical coordinates of the point. The spherical coordinates are the radius of the sphere and the angles of latitude and longitude of the point. The variables radius, currentTheta and currentPhi are used in computing these coordinates (see the Compute Angles and Update Functions).

Although the other viewing parameters (look-at-point and up-vector) do not vary in this example, we still use global variables to store their values. The values are initialized in our Init Function and are used in our Display Function.

The variable dragging is set to true when the user presses the mouse button. We use this value in the mouse motion function to test that the button is down and the user intends to have the eyepoint updated.

Other six variables (startX, startY, ...) are used in the Mouse and Mouse Motion Handlers to determine the amount of change that is made to the movingEyePoint in the Update Function.