problems making a rotating camera using vector math

Hi OF.
I’m trying to make a camera that could rotate around the center of the image on both the X and Y axes. I’m using the ofVec3f class to calculate the coordinates of the camera but i’m having a couple issues.

I made a camera class based on the ofCamera class found here…-t=ofcamera

so far the code looks like this:

Cam::Cam(int _centroX, int _centroY, int _raio){  
	center = ofVec3f(_centroX, _centroY, 0);  
	raio = _raio;  
	position = ofVec3f(0,0,raio);  
	fieldOfView = 65.0f;  
	yon = 1000.0f;  
	hither = 0.5f;  
	int w, h;  
	w = glutGet(GLUT_WINDOW_WIDTH);  
	h = glutGet(GLUT_WINDOW_HEIGHT);  
	aspectRatio = (float)w/(float)h;  
	rotX = rotY = 0;  
void Cam::move(int mouseX, int mouseY){  
rotX = (mouseY-center.y)/1000;  
rotY = (mouseX-center.x)/1000;  
position.rotate(rotX, ofVec3f(1, 0, 0));  
position.rotate(rotY, ofVec3f(0, 1, 0));  
cout << position.length() << endl;  
camX = center.x + position.x;  
camY = center.y + position.y;  
camZ = center.z + position.z;  
void Cam::putInPlace(){  
	gluPerspective(fieldOfView, aspectRatio, hither, yon);  
	gluLookAt(camX, camY, camZ, center.x, center.y, center.z, 0, 1, 0);  

The first issue is that the length of the vector starts decreasing as it rotates. Shoudn’t it remain the same as i rotate? am i doing something wrong?
I’ve been trying to rotate the camera around a simple cube created with glut and the cube slowly gets closer and closer.
The second issue is that the rotation is kinda weird, for example the camera will never perform a full rotation around the X axis, it will just go up to a point and then down again. I think that probably has to do with the math involved, i remember trying to do this mathematically and getting the same behaviour. Anyway, does anyone know a way around this?
in processing i managed to get this effect by using the BeginCamera() comand wich allows me to aply matrix translations and rotations directly to the camera. Does anyone know of a way to do the same in opengl?
thanks a lot.