UrhoSharp中Quaternion转Euler Angle角度符号反转问题咨询
Hey there! Let's break down why you're seeing that -45° instead of +45° when converting your Quaternions to Euler angles in UrhoSharp — this is all about engine-specific conventions, not a mistake in your code or math!
1. UrhoSharp's Coordinate System & Rotation Direction Rules
First, UrhoSharp uses a left-handed coordinate system by default (Y-axis up, X-axis right, Z-axis forward). For rotation directions:
- When you use
Quaternion.FromAxisAngle(Vector3.UnitY, +45f), the+45fangle refers to a clockwise rotation around the Y-axis (use the left-hand rule: point your left thumb up along the Y-axis, and your curled fingers show the positive rotation direction). - But when you call
ToEulerAngles(), the Y-axis component (called "yaw") of the returned Euler angles uses the opposite direction convention: positive values represent counterclockwise rotations (from the same top-down view of the Y-axis).
So a clockwise 45° rotation (what your quaternion represents) directly translates to a counterclockwise -45° in the Euler angle output — that's the core reason for the sign flip.
2. The Quaternion Constructor Behavior
Your second example new Quaternion(0f, +45f, 0f) follows the same logic. This constructor takes three values that map to pitch (X-axis), yaw (Y-axis), roll (Z-axis) Euler angles. When you pass +45f as the yaw value, it creates a quaternion for a clockwise 45° Y-axis rotation — which, again, converts back to -45° when you call ToEulerAngles() due to the direction convention mismatch in the conversion method.
A Quick Fix If You Need Positive Angles
If you want the Euler angle output to match the sign you used to create the quaternion, you can simply invert the Y-axis component of the result:
var correctedYaw = -outputAngle.Y; // correctedYaw will be +45° for both your examples
This works because you're just flipping the direction convention to match your original input's sign.
内容的提问来源于stack exchange,提问作者Soumya Kar

