I'm making a game with spherical terrain. So obviously, when walking on this terrain you can't use standard movement and camera code because the down vector is always pointing to the center of the planet relative to your position on the surface.

It's trivial to calculate the "down" vector: just normalize(position.xyz)...and of course simply aligning a model to this is also easy...vec_to_angle(my.pan,downvector).

The problem comes when trying to do this for a camera...when you align a camera angle to the planet surface, pan and tilt can't be used like when the surface is flat.

So does anyone understand the math for this?