public static void GetAxisAngleFromQuaternion(ref Quaternion q, out Vector3 axis, out float angle)
{
#if !WINDOWS
axis = new Vector3();
#endif
float qx = q.X;
float qy = q.Y;
float qz = q.Z;
float qw = q.W;
if (qw < 0)
{
qx = -qx;
qy = -qy;
qz = -qz;
qw = -qw;
}
if (qw > 1 - 1e-6)
{
axis = Toolbox.UpVector;
angle = 0;
}
else
{
angle = 2 * (float)Math.Acos(qw);
float denominator = 1 / (float)Math.Sqrt(1 - qw * qw);
axis.X = qx * denominator;
axis.Y = qy * denominator;
axis.Z = qz * denominator;
}
}