※ Don’t mind the inaccurate illustrations
However, after I apply the rotation, I need to calculate a new center position for the camera such that the origin looks like it is still in the same position relative to the “camera”.
After many ideas and several coding mistakes (including using the z coordinate as the x which obviously lead to very wrong results), the final computation is as follows:
x' = rotation_matrix*x y' = rotation_matrix*y z' = rotation_matrix*z;
It looks so annoyingly simple, I can’t believe it took me three weeks to get this to work.
And of course, right after I solved that, I found out that the way I computed the rotation matrix was wrong! I am given an angle and a direction, but I wrongly assumed that the direction would always be along one of the axes. Apparently the rotation direction is based on the current orientation of an object that is in the world.
Thankfully, our project already had code that computes the new orientation matrix given a rotation angle in a certain direction. All I had to do was call that function. (In a previous assignment, though, I had to study and understand it because there were some computation errors. Even though the errors were in the function that computed the angles from the orientation matrix, it also helped me understand the reverse which is what I need now. Here is a helpful document that got me through that task.)
Once I had the new orientation matrix, it was only just a matter of computing the rotation matrix in order to apply what I had already figured out the first time around.
rotation_matrix = new_orientation*inverse(old_orientation)