Beispiel #1
0
    /// <summary>
    /// 欧拉角(单位四元数有效)
    /// </summary>
    /// <returns></returns>
    public Vector3 ToEulers()
    {
        Vector3 euler = Vector3.zero;
        Matrix  m     = ToMatrix();

        if (MathS.Abs(m[1, 0]) <= Threshold &&
            MathS.Abs(m[1, 1]) <= Threshold)
        {
            euler.x = m[1, 2] <= 0 ? 90 : -90;
            euler.y = 0;
            euler.z = MathS.Atan2(-m[0, 1], m[0, 0]) * MathS.RadToDeg;
        }
        else
        {
            euler.x = MathS.Asin(-m[1, 2]);
            euler.y = MathS.Atan2(m[0, 2], m[2, 2]);
            euler.z = MathS.Atan2(m[1, 0], m[1, 1]);
            euler  *= MathS.RadToDeg;
        }
        return(euler);
    }