I came across this thread and wanted to point a couple things out.
Let Q be a Quaternion, and dQ be a Quaternion that represents a change in rotation. Another way of thinking of these is Q is an orientation and dQ is a rotation.
Q * dQ applies dQ to Q in the global coordinate system (GCS). That is, it doesn’t matter what the orientation of Q is relative to the GCS, the rotation applied to it will be based upon the GCS.
dQ * Q applies dQ to Q in Q’s local coordinate system (LCS). For example, if Q represents a rotation around the Y axis, then it’s X axis is rotated relative to the GCS’ X axis. So if dQ applies a rotation around the X axis, that rotation will be applied to Q’s X axis, not the global X axis.
Now go back up and reread what I said about Q * dQ to better understand how dQ rotates Q in GCS.
The code comment in an earlier post in this thread said:
//(delta + B)
//so what if we want to rotate childGO locally for 10degree more, was 30, so plus 10 will be 40
//childGO.transform.localRotation = Quaternion.AngleAxis(10, Vector3.up) * childGO.transform.localRotation; //(10+30)=40
Think about what it said and what it did not say. In their example, it didn’t matter which came first, because the results would be the same, because they both included only spins around a single axis. But I also wanted to point out that it says that their dQ is lhs, not rhs as some posts above state.
Why is this important?
If you want to apply pitch and yaw to, say, your camera, but you want to prevent roll from being introduced, the easiest way to do this is:
camera.orientation = dPitch * camera.orientation * dYaw
The camera’s orientation is rotated first by dYaw in GCS so that any pitch it has in it already doesn’t produce roll. Then it is rotated by dPitch in its LCS so that what ever pitch it already has is adjusted without producing roll.
You can say dPitch adds rotation to camera.orientation in camera.orientation’s LCS, and then camera.orientation adds rotation to dYaw in dYaw’s LCS. This is literally what happens as the C/C++ ops are performed left to right.
You can also say dYaw adds rotation to camera.orientation in GCS, then camera.orientation adds rotation to dPitch in GCS.