# Correct order on accumulating rotations

Suppose I have an Arcball camera that rotates up/down and sideways based on mouse input. After doing some research, I discovered that the correct way of calculating the new orientation is to do it the following way

// qy is a rotation (in quaternion) around the y-axis
// qx ~ around the x-axis
Quaternion orientation = (qy * old_orientation * qx);


However, I am not sure why switching the order of qx and qy introduces unwanted roll.

One answer from this post brushes on the subject.

The answer stated and I quote

When working with Quaternions, order does matter, as it always does with 3D rotations. In my example, "Direction *= newRotation" is the same as "Direction = Direction * newRotation". But, with left and right rotations, we want it the other way around. This makes it not dependent on the up and down tilt, which causes roll.

Based on my understanding, orientation does the complete opposite of what they described. qy depends on qx since we apply qx to some vector first. What did I miss or what did I misunderstand?

• This previous Q&A may help build some intuition — I have some animated gifs showing sequences of rotations, and how multiplying on the left vs right means rotating around global vs local axes. Commented Sep 12, 2023 at 22:03
• @DMGregory Your post does a brilliant job at explaining why we need to sperate the two rotations. But, I am still confused about why "Pitch Locally, Yaw Globally" is the order. Why does it stop working when we do "Yaw Locally, Pitch Globally"? Commented Sep 13, 2023 at 0:48
• See the bottom example for that. Yaw locally, pitch globally is the order you want if you're manipulating a spinning globe, and you want it to always yaw around ITS north & south poles, but pitch toward/away from YOU (here taken as a fixed observer in global space). When controlling the viewpoint, you want to do the opposite: pitch around YOUR x axis (running from your left to right ear, for example), but yaw around the WORLD's y axis (parallel to the gravity vector) Commented Sep 13, 2023 at 0:55