I am confused about rotating a camera around its own y-axis. I am using the OpenGL graphics library, so -z goes into the screen. Here is my code so far:
if (KEY_DOWN(F_WindowInfo.KeyStates['Q']))
{
float Yaw = -1.0f;
m3 RotationMatrix;
RotationMatrix.Rc[0][0] = Math_Cosine(Math_DegToRad(Yaw));
RotationMatrix.Rc[0][2] = Math_Sine(Math_DegToRad(Yaw));
RotationMatrix.Rc[1][1] = 1.0f;
RotationMatrix.Rc[2][0] = -Math_Sine(Math_DegToRad(Yaw));
RotationMatrix.Rc[2][2] = Math_Cosine(Math_DegToRad(Yaw));
F_WindowInfo.Camera->ForwardVector =
Math_Normalize(&(RotationMatrix * F_WindowInfo.Camera->ForwardVector));
}
if (KEY_DOWN(F_WindowInfo.KeyStates['E']))
{
float Yaw = 1.0f;
m3 RotationMatrix;
RotationMatrix.Rc[0][0] = Math_Cosine(Math_DegToRad(Yaw));
RotationMatrix.Rc[0][2] = Math_Sine(Math_DegToRad(Yaw));
RotationMatrix.Rc[1][1] = 1.0f;
RotationMatrix.Rc[2][0] = -Math_Sine(Math_DegToRad(Yaw));
RotationMatrix.Rc[2][2] = Math_Cosine(Math_DegToRad(Yaw));
F_WindowInfo.Camera->ForwardVector =
Math_Normalize(&(RotationMatrix * (F_WindowInfo.Camera->ForwardVector)));
}
F_WindowInfo.Camera->ViewMatrix = Math_LookAtMatrix(&F_WindowInfo.Camera->Position,
&(F_WindowInfo.Camera->Position + F_WindowInfo.Camera->ForwardVector),
&F_WindowInfo.Camera->UpVector);
and the Math_LookAtMatrix() function:
m4
Math_LookAtMatrix(v3* Eye, v3* Target, v3* Up)
{
v3 ZAxis = Math_Normalize(&(*Target - *Eye));
v3 XAxis = Math_Normalize(&Math_CrossProduct(&ZAxis, Up));
v3 YAxis = Math_CrossProduct(&XAxis, &ZAxis);
m4 Result;
Result.Rc[0][0] = XAxis.x;
Result.Rc[0][1] = YAxis.x;
Result.Rc[0][2] = ZAxis.x;
Result.Rc[1][0] = XAxis.y;
Result.Rc[1][1] = YAxis.y;
Result.Rc[1][2] = ZAxis.y;
Result.Rc[2][0] = -XAxis.z;
Result.Rc[2][1] = -YAxis.z;
Result.Rc[2][2] = -ZAxis.z;
Result.Rc[3][0] = -Math_InnerProduct(&XAxis, Eye);
Result.Rc[3][1] = -Math_InnerProduct(&YAxis, Eye);
Result.Rc[3][2] = Math_InnerProduct(&ZAxis, Eye);
Result.Rc[3][3] = 1.0f;
return Result;
}
Note that ForwardVector, UpVector, and Position are all 3 dimension vectors and RotationMatrix is a 3x3 matrix.
ForwardVector starts at (0.0f, 0.0f, -1.0f)
Upvector is (0.0f, 1.0f, 0.0f)
The problem I am having is that the rotation I am currently doing makes it look like the world is being moved around the world y-axis instead of the camera just rotating around its own local y-axis. Can someone please let me know what I am doing wrong?
EDIT: I believe my lookAtMatrix function is wrong, i removed the - signs from Result.Rc[3][0] and Result.Rc[3][1] and got the Q and E movement that I originally wanted. Now the x-axis is just backwards.