We compute here the two angles in spherical coordinates, the angle of longitude and the angle of latitude, and store the values in the variables currentTheta and currentPhi. We compute these values from the location of the current eyepoint.
The angle of longitude is measure along the "equator." Since the angle zero is at the z-axis, we measure from the vector (0.0, 0.0, 1.0). Thus, we project the vector consisting of the coordinates of the current eyepoint onto the x-z coordinate plane. The projection is accomplished by simply setting the y-coordinate of the currentEyePoint to 0. Note that the dot product of the vector (0.0, 0.0, 1.0) and the normalized projection vector is the cosine of the angle between the two vectors. Thus, the arccosine of the z-coordinate of the normalized projection vector is the angle of longitude, which we store in the variable currentTheta. Last, reversing the sign of the angle when x-coordinate of the current eyepoint is negative creates a smooth transition when the angle crossing over 180 degrees (i.e., the international dateline).
The angle of latitude is the angle between the vector of the current eyepoint and its projection vector. Again, the dot product of the two normalized vectors gives us the cosine of the angle. In turn, the arccosine of the dot product is the angle.