I have a camera class in my code which stores two 4x4 matrices. One for the view matrix and one for the projection matrix. Originally, I had two floats in the class for pitch and yaw and these were updated based on keyboard and mouse input. Then on update I would do something like this to set the view matrix:
Matrix33 xRot = Matrix33::CreateRotationX(m_pitch); Matrix33 yRot = Matrix33::CreateRotationY(m_yaw); Matrix33 rot = xRot * yRot; const Vector3& rUp = rot.GetColumn1(); const Vector3& rForward = rot.GetColumn2(); m_viewMatrix = Matrix44::CreateLookAt(m_position, m_position + rForward, rUp);
However, I'm now wanting to add roll to the equation but I know that if I carry on using this method I'm going to run into gimbal lock. I do have a function in my maths library to rotate about an arbitrary axis. The function definition is:
static Matrix33 CreateRotation(const Vector3 &rAxis, const float rad);
But I'm not sure, based on pitch/yaw/roll how to create the arbitrary axis to rotate around. This got me thinking that perhaps pitch/yaw/roll isn't the best way to be doing it so I thought I'd ask on here about what might be the best way? I don't even have to use CreateLookAt(), it just seemed easier at the time :)
I don't have a quaternion class yet but I could add one if that would be the best way. I think ideally I'd rather do it with just matrices for now, though.
Any help would be much appreciated.