void SetLookAt() {// do orbit camera vEye.x = fEyeRadius * cosf(fLat) * cosf(fLon); vEye.y = fEyeRadius * cosf(fLat) * sinf(fLon); vEye.z = fEyeRadius * sinf(fLat); glLoadIdentity(); gluLookAt(vEye.x, vEye.y, vEye.z, 0, 0, 0, 0, 0, -1);}
'fLat' and 'fLon' are updated as the mouse moves around the screen with the middle mouse button held down (using
glutMotionFunc). fLat is constrained to the range (-0.75, 0.75). The 'up' axis is along the negative z-axis, the object being looked at is always at (0, 0, 0).
It's essentially the same as your method except I calculate the vector on the fly. 'sin' and 'cos' aren't so expensive that it's worth precalculating and storing them for results I need at most 60 times a second.