GetEquivalentEulerAngles() public static method

public static GetEquivalentEulerAngles ( Quaternion quat ) : Vector3[]
quat UnityEngine.Quaternion
return Vector3[]
示例#1
0
        public static Vector3 GetEulerFromQuaternion(Quaternion q, Vector3 refEuler)
        {
            Vector3[] equivalentEulerAngles = QuaternionCurveTangentCalculation.GetEquivalentEulerAngles(q);
            for (int index = 0; index < equivalentEulerAngles.Length; ++index)
            {
                equivalentEulerAngles[index] = new Vector3((float)((double)Mathf.Repeat((float)((double)equivalentEulerAngles[index].x - (double)refEuler.x + 180.0), 360f) + (double)refEuler.x - 180.0), (float)((double)Mathf.Repeat((float)((double)equivalentEulerAngles[index].y - (double)refEuler.y + 180.0), 360f) + (double)refEuler.y - 180.0), (float)((double)Mathf.Repeat((float)((double)equivalentEulerAngles[index].z - (double)refEuler.z + 180.0), 360f) + (double)refEuler.z - 180.0));
                float num1 = Mathf.Repeat(equivalentEulerAngles[index].x, 360f);
                if ((double)Mathf.Abs(num1 - 90f) < 1.0)
                {
                    float num2 = equivalentEulerAngles[index].z - equivalentEulerAngles[index].y - (refEuler.z - refEuler.y);
                    equivalentEulerAngles[index].z = refEuler.z + num2 * 0.5f;
                    equivalentEulerAngles[index].y = refEuler.y - num2 * 0.5f;
                }
                if ((double)Mathf.Abs(num1 - 270f) < 1.0)
                {
                    float num2 = equivalentEulerAngles[index].z + equivalentEulerAngles[index].y - (refEuler.z + refEuler.y);
                    equivalentEulerAngles[index].z = refEuler.z + num2 * 0.5f;
                    equivalentEulerAngles[index].y = refEuler.y + num2 * 0.5f;
                }
            }
            Vector3 vector3 = equivalentEulerAngles[0];
            float   num     = (equivalentEulerAngles[0] - refEuler).sqrMagnitude;

            for (int index = 1; index < equivalentEulerAngles.Length; ++index)
            {
                float sqrMagnitude = (equivalentEulerAngles[index] - refEuler).sqrMagnitude;
                if ((double)sqrMagnitude < (double)num)
                {
                    num     = sqrMagnitude;
                    vector3 = equivalentEulerAngles[index];
                }
            }
            return(vector3);
        }
        public static Vector3 GetEulerFromQuaternion(Quaternion q, Vector3 refEuler)
        {
            Vector3[] equivalentEulerAngles = QuaternionCurveTangentCalculation.GetEquivalentEulerAngles(q);
            for (int i = 0; i < equivalentEulerAngles.Length; i++)
            {
                equivalentEulerAngles[i] = new Vector3(Mathf.Repeat(equivalentEulerAngles[i].x - refEuler.x + 180f, 360f) + refEuler.x - 180f, Mathf.Repeat(equivalentEulerAngles[i].y - refEuler.y + 180f, 360f) + refEuler.y - 180f, Mathf.Repeat(equivalentEulerAngles[i].z - refEuler.z + 180f, 360f) + refEuler.z - 180f);
                float num = Mathf.Repeat(equivalentEulerAngles[i].x, 360f);
                if (Mathf.Abs(num - 90f) < 1f)
                {
                    float num2 = equivalentEulerAngles[i].z - equivalentEulerAngles[i].y;
                    float num3 = refEuler.z - refEuler.y;
                    float num4 = num2 - num3;
                    equivalentEulerAngles[i].z = refEuler.z + num4 * 0.5f;
                    equivalentEulerAngles[i].y = refEuler.y - num4 * 0.5f;
                }
                if (Mathf.Abs(num - 270f) < 1f)
                {
                    float num5 = equivalentEulerAngles[i].z + equivalentEulerAngles[i].y;
                    float num6 = refEuler.z + refEuler.y;
                    float num7 = num5 - num6;
                    equivalentEulerAngles[i].z = refEuler.z + num7 * 0.5f;
                    equivalentEulerAngles[i].y = refEuler.y + num7 * 0.5f;
                }
            }
            Vector3 result = equivalentEulerAngles[0];
            float   num8   = (equivalentEulerAngles[0] - refEuler).sqrMagnitude;

            for (int j = 1; j < equivalentEulerAngles.Length; j++)
            {
                float sqrMagnitude = (equivalentEulerAngles[j] - refEuler).sqrMagnitude;
                if (sqrMagnitude < num8)
                {
                    num8   = sqrMagnitude;
                    result = equivalentEulerAngles[j];
                }
            }
            return(result);
        }