Original Post
I know, euler angles suck, but I''m doing a project on them (and quaternions) for school, so I have to demonstrate an euler angle camera. I have an axis-angle camera already, and I am trying to convert it to euler angle and quaternion. My euler angle cam is all screwy. It''ll work okay for a second, but then it does wierd stuff, like invert the mouse, or lock for a second and then unlock. I borrowed *some* of the camera code from gametutorials to do my testing, cause I figured maybe I had my mousemove function done badly. Here it is.
anybody got a fix?
void Camera::RotateCamera(double Yaw, double Pitch, double Roll)
{
Vector OriginView = View - Position, NewView;
Yaw = (Yaw * PI)/180;
Pitch = (Pitch * PI)/180;
Roll = (Roll * PI)/180;
double SinYaw = sin(Yaw);
double CosYaw = cos(Yaw);
double SinPitch = sin(Pitch);
double CosPitch = cos(Pitch);
double SinRoll = sin(Roll);
double CosRoll = cos(Roll);
NewView.x = CosRoll * CosYaw * OriginView.x;
NewView.x += (-SinRoll * CosPitch + CosRoll * SinYaw * SinPitch) * OriginView.y;
NewView.x += (-SinRoll * -SinPitch + CosRoll * SinYaw * CosPitch) * OriginView.z;
NewView.y = (SinRoll * CosYaw) * OriginView.x;
NewView.y += (CosRoll * CosPitch + SinRoll * SinYaw * SinPitch) * OriginView.y;
NewView.y += (CosRoll * -SinPitch + SinRoll * SinYaw * CosPitch) * OriginView.z;
NewView.z = -SinYaw * OriginView.x;
NewView.z += (CosYaw * SinPitch) * OriginView.y;
NewView.z += (CosYaw * CosPitch) * OriginView.z;
View = Position + NewView;
}
void Camera::SetViewByMouse(void)
{
int MouseX, MouseY;
int CenterX = SCREENWIDTH / 2;
int CenterY = SCREENHEIGHT / 2;
int DirectionX;
int DirectionY;
static double CurrentRotationY = 0.0;
SDL_GetMouseState(&MouseX, &MouseY);
if(MouseX == CenterX && MouseY == CenterY)
return;
SDL_WarpMouse(CenterX, CenterY);
DirectionX = (CenterX - MouseX)/10;
DirectionY = (CenterY - MouseY)/10;
CurrentRotationY -= DirectionY;
if(CurrentRotationY >= 50.0)
CurrentRotationY = 50.0;
else if(CurrentRotationY <= -50.0)
CurrentRotationY = -50.0;
else
RotateCamera(DirectionX, DirectionY, 0);
}