I'm using XNA to create an FPS camera that uses a Direction vector instead of a Target vector control the camera's orientation.
I'm having trouble with the math for looking up and down when the camera is rotated about the Y axis. No problems looking left and right.
Here's my code:
Vector3 LookDirection {get;set;}
public void LookLeft(float scale)
{
LookDirection = Vector3.Transform(LookDirection, Matrix.CreateRotationY(MathHelper.ToRadians(scale)));
}
public void LookRight(float scale)
{
LookDirection = Vector3.Transform(LookDirection, Matrix.CreateRotationY(MathHelper.ToRadians(-scale)));
}
public void LookUp(float scale)
{
//doesn't work when camera is rotated into the X axis
LookDirection = Vector3.Transform(LookDirection, Matrix.CreateRotationZ(MathHelper.ToRadians(scale)));
}
public void LookDown(float scale)
{
//doesn't work when camera is rotated into the X axis
LookDirection = Vector3.Transform(LookDirection, Matrix.CreateRotationZ(MathHelper.ToRadians(-scale)));
}
I know I need to manipulate both the X and Z components when looking up and down, I just can't figure out exactly what to do. Thanks