polar coordinates problem

Hi to everyone. I have a small problem. I finally created a program that I can move the camera around a specified center, using polar coordinates. My problem is the up vector. If for example my camera is at 0, 0, 200 and is looking at 0, 0, 0 and I press up, the y gradually increases and z is decreased. But when the camera passes point 0, 200, 0 towards say 0, 199, -1 the objects in the scene are turned because of the up vector of gluLookAt. How can I find out when to set the up vector to (0, 1, 0) and when to (0, -1, 0)?
Thanks for your time, cheers

Still problems. I’ve found a solution. Here is the code:

cameraUp.x = cameraPos.x - cameraLook.x;
camserUp.z = cameraPos.z - cameraLook.z;
cameraUp.y = cameraPos.y + radius * sin(theta + (pi / 2.0) / 180.0);

Most of the time, it works great, but in distinct position I get the wrong up vector. It’s kind of annoying, while rotating my camera, for one frame I get the wrong orientation, then back right on the next.
Can someone give me a clue?

LookAt works by crossing the to-vector with the up-vector, completing a basis for the camera. As you know, the cross product of 2 parallel vectors is the zero vector. You must make certain that this case does not arise.

A question was posed in the math forum recently that may be of interest to you.