Hi all,

I am trying to make a camera using spherical coordinates, as the title implies. I believe I have a problem with the up vector, but here is the code anyways:

Code :
        float eyeX = gs.vDist * ( (float) cos(gs.theta) ) * ( (float) sin(gs.phi) );
        float eyeY = gs.vDist * ( (float) sin(gs.theta) ) * ( (float) cos(gs.phi) );
        float eyeZ = gs.vDist * ((float) cos(gs.phi));
 
        eye = new Vector(eyeX, eyeY, eyeZ);
        center = gs.cnt;
 
        Vector V = eye.subtract(center).normalized();        
 
        up = new Vector( (float) cos(gs.theta), (float) sin(gs.theta), 1);

gs is a Global State variable that houses all the required information.
gs.theta is the angle between the point projection on the vertical plane and the x-axis, and gs.phi is the angle with z-axis. gs.vDist is the distance between the origin and the point on the sphere (radius).

The camera should be able to move in any direction using left click drag. I understand that in order to do that, z coordinate of the up vector cannot be 1, but should be adjusted accordingly. I just don't know what it should be.

What changes should I make in order for it to work?

Just as the side note, all the parameters are later added to gluLookAt(...).

Thank you in advance!