/// <a href="http://bit.ly/2Os3WLf">One person's left is another person's up. More importantly the gyroscope in the phone sees forward as the Z axis while Unity likes to use Y for that. This function also changes the chirality (handedness).</a> public static Quaternion SwitchAxis(this Quaternion q, Trig.Direction pivot) { q.Set(-q.x, -q.y, -q.z, -q.w); // change chirality int left = otherAxes[pivot.Ord, 0], right = otherAxes[pivot.Ord, 1]; float swap = q[left]; q[left] = q[right]; q[right] = swap; return(q.Normalise()); }
/// <a href="http://bit.ly/2RhdaZl">Rotate quaternion around an axis by a specified number of degrees then normalise</a> public static Quaternion AroundAxis(this Quaternion q, Trig.Direction axis, float degrees) { var rotateBy = Quaternion.AngleAxis(degrees, axis.Vector); return(rotateBy * q); }
/// <a href="http://bit.ly/2RezNxw">Gyro is right-handed while Unity is left-handed - so change chirality</a> public static Quaternion RightToLeftHanded(this Quaternion q, Trig.Direction axis) { q[axis.Ord] = -q[axis.Ord]; q.w = -q.w; return(q); }