A little rotation buglet...

I’m using the following routine to rotate the view around the camera on a selected axis with a set angle:

struct str_vector {GLfloat x,y,z;};

str_vector XYZRotate(str_vector Rotator,str_vector Rotatee,str_vector axes,GLfloat angle)
{
str_vector rotation_matrix[3]={0};
str_vector dist={0};
str_vector newv={0};
dist = SubtractVectors(Rotator,Rotatee);
GLfloat ca = cos(angle);
GLfloat sa = sin(angle);
if (axes.x == 0 && axes.y == 1 && axes.z == 0)
{
rotation_matrix[0] = SetVector(ca,0,sa);
rotation_matrix[1] = SetVector(0,1,0);
rotation_matrix[2] = SetVector(-sa,0,ca);
}
else if (axes.x == 1 && axes.y == 0 && axes.z == 0)
{
rotation_matrix[0] = SetVector(1,0,0);
rotation_matrix[1] = SetVector(0,ca,-sa);
rotation_matrix[2] = SetVector(0,sa,ca);
}
else if (axes.x == 0 && axes.y == 0 && axes.z == 1)
{
rotation_matrix[0] = SetVector(ca,-sa,0);
rotation_matrix[1] = SetVector(sa,ca ,0);
rotation_matrix[2] = SetVector(0 , 0 ,1);
}
newv.x = VectorDotProduct(rotation_matrix[0],dist);
newv.y = VectorDotProduct(rotation_matrix[1],dist);
newv.z = VectorDotProduct(rotation_matrix[2],dist);
return newv;
}

It works wonderfully for rotations on the y axis but the x axis seems to loop and double back on itself when it gets so far. I would have thought it would continue in a circle.

I’m using the following code to carry out the rotations. Any idea why it would do this and how I can get it to rotate properly.

``````if (m_bKeys[VK_LEFT]) view = XYZRotate(view,camera,SetVector(0,1,0),0.05);
if (m_bKeys[VK_RIGHT]) view = XYZRotate(view,camera,SetVector(0,1,0),-0.05);
if (m_bKeys[VK_DOWN]) view  = XYZRotate(view,camera,SetVector(1,0,0),0.05);
if (m_bKeys[VK_UP]) view = XYZRotate(view,camera,SetVector(1,0,0),-0.05);
``````