QuaternionNormalize() public static method

public static QuaternionNormalize ( Quaternion &q ) : void
q UnityEngine.Quaternion
return void
Ejemplo n.º 1
0
        public static Quaternion QuaternionFromMatrix(Matrix4x4 m)
        {
            Quaternion result = default(Quaternion);

            result.w  = Mathf.Sqrt(Mathf.Max(0f, 1f + m[0, 0] + m[1, 1] + m[2, 2])) / 2f;
            result.x  = Mathf.Sqrt(Mathf.Max(0f, 1f + m[0, 0] - m[1, 1] - m[2, 2])) / 2f;
            result.y  = Mathf.Sqrt(Mathf.Max(0f, 1f - m[0, 0] + m[1, 1] - m[2, 2])) / 2f;
            result.z  = Mathf.Sqrt(Mathf.Max(0f, 1f - m[0, 0] - m[1, 1] + m[2, 2])) / 2f;
            result.x *= Mathf.Sign(result.x * (m[2, 1] - m[1, 2]));
            result.y *= Mathf.Sign(result.y * (m[0, 2] - m[2, 0]));
            result.z *= Mathf.Sign(result.z * (m[1, 0] - m[0, 1]));
            MathUtils.QuaternionNormalize(ref result);
            return(result);
        }
Ejemplo n.º 2
0
        public static Quaternion QuaternionFromMatrix(Matrix4x4 m)
        {
            Quaternion q = new Quaternion();

            q.w  = Mathf.Sqrt(Mathf.Max(0.0f, 1f + m[0, 0] + m[1, 1] + m[2, 2])) / 2f;
            q.x  = Mathf.Sqrt(Mathf.Max(0.0f, 1f + m[0, 0] - m[1, 1] - m[2, 2])) / 2f;
            q.y  = Mathf.Sqrt(Mathf.Max(0.0f, 1f - m[0, 0] + m[1, 1] - m[2, 2])) / 2f;
            q.z  = Mathf.Sqrt(Mathf.Max(0.0f, 1f - m[0, 0] - m[1, 1] + m[2, 2])) / 2f;
            q.x *= Mathf.Sign(q.x * (m[2, 1] - m[1, 2]));
            q.y *= Mathf.Sign(q.y * (m[0, 2] - m[2, 0]));
            q.z *= Mathf.Sign(q.z * (m[1, 0] - m[0, 1]));
            MathUtils.QuaternionNormalize(ref q);
            return(q);
        }