I have posted a question How can I get horizontal rotation angle whatever device orientation?
Please see the origin post to get the image of the direction of x, y and z axis.
- pitch: a pitch is a rotation around x-axis
- roll: a roll is a rotation around y-axis
- yaw: a yaw is a rotation around z-axis
When mobile phone is portrait, like the image showing, x-axis is horizontal and y-axis is vertical. So I can get horizontal angle by using the roll. (I can get a quaternion anytime when mobile rotating, then I can convert the quaternion to euler angle.)
But when mobile phone is landscape, x-axis is vertical and y-axis is horizontal. The roll is no more horizontal angle. So I don't know how to get is. I have tried to exchange x and y in the quaternion but no worked.
How can I get the horizontal angle? Is there a unified formula to produce the quaternion or rotation matrix?