Hi all. I'm having trouble with my camera class. All is well (walking, elevating, strafing) until I pitch up a bit and start yawing. What happens is, as I'm yawing, the camera seems to be rolling in the direction of the yaw on its own. This only happens when I have my camera type set to FPS, where I'm trying to limit to yawing on the world Y axis. The FREE type works as intended and yaws on it's own local Y (Up) axis. Any ideas
Before:
http://img435.imageshack.us/img435/2787/ss1ja1.jpg
After pitching about 35 degrees up and then yawing to the left several times around:
http://img282.imageshack.us/img282/4946/ss2aq7.jpg
I pasted my Yaw, Pitch, and BuildView methods below.
Yaw
public
void Yaw(float angle, float dt){
Matrix m = new Matrix(); // If camera is FPS style, create rotation around world Y if (m_Type == CamType.FPS){
m =
Matrix.CreateRotationY(angle * dt);}
// If camera is FREE style, create rotation around local Up axis else if (m_Type == CamType.FREE){
m =
Matrix.CreateFromAxisAngle(m_Up, angle * dt);}
// Transform Right and Look vectors by rotation matrixm_Right =
Vector3.Transform(m_Right, m);m_LookAt =
Vector3.Transform(m_LookAt, m);}
PITCH
public
void Pitch(float angle, float dt){
Matrix m = new Matrix(); // Create rotation around local Right axism =
Matrix.CreateFromAxisAngle(m_Right, angle * dt); // Transform Look and Up vectors by rotation matrixm_LookAt =
Vector3.Transform(m_LookAt, m);m_Up =
Vector3.Transform(m_Up, m);}
BuildView
public
void BuildView(){
// Building the matrix (right-handed) // rx, ux, fx, 0 // ry, uy, fy, 0 // rz, uz, fz, 0 // -r.p, -u.p, f.p, 1m_LookAt =
Vector3.Normalize(m_LookAt);m_Right =
Vector3.Cross(m_Up, m_LookAt);m_Right =
Vector3.Normalize(m_Right);m_Up =
Vector3.Cross(m_LookAt, m_Right);m_Up =
Vector3.Normalize(m_Up); // Build view matrix float x = -Vector3.Dot(m_Right, m_Pos); float y = -Vector3.Dot(m_Up, m_Pos); float z = -Vector3.Dot(m_LookAt, m_Pos);m_View.M11 = m_Right.X;
m_View.M12 = m_Up.X;
m_View.M13 = m_LookAt.X;
m_View.M14 = 0.0f;
m_View.M21 = m_Right.Y;
m_View.M22 = m_Up.Y;
m_View.M23 = m_LookAt.Y;
m_View.M24 = 0.0f;
m_View.M31 = m_Right.Z;
m_View.M32 = m_Up.Z;
m_View.M33 = m_LookAt.Z;
m_View.M34 = 0.0f;
m_View.M41 = x;
m_View.M42 = y;
m_View.M43 = z;
m_View.M44 = 1.0f;
}