The viewing variables are declared in the global environment. The movingEyePoint is used in computing the viewing transformation and we set its value here. We set the coordinates of the currentEyePoint as those of the current movingEyePoint when the user intends to orbit the camera by pressing the left-mouse button. We use these coordinates as the "base point" and compute an amount of change to make to them, storing the new coordinates in movingEyePoint. We also set here the values of the other two viewing parameters, look-at point and up vector.

The radius is that of the sphere about which the eyepoint moves while orbiting the camera. The sphere is centered at the look-at-point, which is the origin for this example. The initial (moving) eyepoint is on this sphere. Therefore, the length of the vector consisting of the three coordinates of the initial eyepoint is the radius of the sphere. Since the radius does not vary, we compute it once in our init function.

Although the viewing transformation will change through user interaction, the projection method does not, Thus, we establish its transformation here.