D = Quaternion.Euler(T, 0, 0)
This creates a unit quaternion, a point on a four-dimensional sphere with three of those dimensions being imaginary numbers. The four components of the quaternion x, y, z, and w are NOT angles.
D.x * 360f
This takes one of those imaginary axis values and multiplies it by 360. This does NOT make it an angle. It's geometrically meaningless.
D.x
is the sine of an angle, but it may not be exactly the angle that you want at the end of the day. Because the total angle in the quaternion will always be -180 to +180, and that means if you have rotation on the y or z axes, the x alone won't hit those extremes.
To extract out "I just care about the rotation angle in this specific plane," you can do something a bit like this:
// Turn your Euler angle offset into a quaternion.
var offset = Quaternion.Euler(offset_angles);
// Reverse this quaternion to "undo" the offset.
var correction = Quaternion.Inverse(offset);
// Apply the correction to the quaternion - this behaves more consistently
// than trying to add/subtract Euler angles.
var correctedAttitude = Input.gyro.attitude * correction;
// Now we can use this attitude to transform the world up vector
// into the phone's local coordinate system.
var sensedUp = Quaterntion.Inverse(correctedAttitude) * Vector3.up;
// And you can use the components of that vector to discern an orientation
// angle in the plane of your choosing.
var degreeAngle = Mathf.Atan2(sensedUp.y, sensedUp.x) * Mathf.Rad2Dag;
Depending on which axis of rotation you care about, whether you want clockwise or counterclockwise rotation to be positive, and where you want 0 degrees to sit within the circle, you might choose a different reference vector or use different components inside Atan2
.
correctedAttitude = Input.gyro.attitude; and tried to output degreeAngle as it is.
As a result, a specific axis? Even though it rotates about 10 degrees, it becomes -120 degrees... -60 degrees ... -10 degrees.
It seems that I may have misunderstood something.
I don't seem to have properly grasped what degreeAngle means
– TaengGuRiMon Aug 11 '21 at 12:13