Original Post
I'm trying to make an fps engine and have a problem that's keeping me busy. My camera's rotations/translations are working well except for one thing changing the camera's pitch up/down. This works until a certain point: when i try to rotate(jaw) the camera after a pitch the camera seems to roll which is not my intention. For example: when i set the camera to look 40° up and then rotate(jaw) for 180° the camera looks 40° down! What am i doing wrong? This is my code, after the rotate function i extract my left,up,dir vector from matrix to build my viewing matrix.
void rotate(float angle,float x, float y, float z)
{
CMatrix mx,my,mz;
mx = matrix.rotate(angle,x,0,0);
my = matrix.rotate(angle,0,1,0);
mz = matrix.rotate(angle,0,0,z);
CMatrix mt = mx*my*mz;
matrix = matrix*mt;
}
CMatrix rotate(double angle, int x, int y, int z)
{
CMatrix m;
float sine = (float)sin(angle);
float cosine = (float)cos(angle);
if(x)
{
m.matrix[5] = cosine;
m.matrix[6] = sine;
m.matrix[9] = -sine;
m.matrix[10] = cosine;
}
if(y)
{
m.matrix[0] = cosine;
m.matrix[2] = -sine;
m.matrix[8] = sine;
m.matrix[10] = cosine;
}
if(z)
{
m.matrix[0] = cosine;
m.matrix[1] = sine;
m.matrix[4] = -sine;
m.matrix[5] = cosine;
}
return m;
}