I'm trying to achieve an orbiting camera using gluLookAt and spherical coordinates but I just can't get it right

#define PI 3.14159265 struct Camera{ float x, y, z; // Camera position float atX, atY, atZ; // Where is it looking float uX, uY, uZ; // Where is up Camera(){} }; Camera c; float rho = 5.; float phi = 0.; float theta = 0.; float toRadians(float degrees) { return degrees * (PI / 180.); } void draw() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // To Carthesian Coordinates c.x = rho * sin(toRadians(phi)) * cos(toRadians(theta)); c.y = rho * sin(toRadians(phi)) * sin(toRadians(theta)); c.z = rho * cos(toRadians(phi)); // Where the camera is looking c.atX = 0.; c.atY = 0.; c.atZ = 0.; // What the hell is this for? Can't remember <img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/sad.gif' class='bbc_emoticon' alt=':(' /> where I took this from c.uX = cos(toRadians(theta)); c.uY = sin(toRadians(theta)); c.uZ = 1; gluLookAt(c.x, c.y, c.z, c.atX, c.atY, c.atZ, c.uX, c.uY, c.uZ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutWireCube(1); glutSwapBuffers(); }

rho++ gets me a zoom in

rho-- gets me a zoom out

phi++ the camera goes 'up' but at a certain point it messes and it starts going down

phi-- the camera goes 'down' but at a certain point it messes and it starts going down

theta++ the camera rotates on z

theta-- the camera rotates on z

The main problem is when I modify phi I think that the problem is on UP vertex

Thanks for your help