GlmSharp/GlmSharp5/Quat/quat.cs
/// <summary>
/// Creates a quaternion from the rotational part of a mat4.
/// </summary>
Creates a quaternion from the rotational part of a mat4.
Creates a quaternion from the rotational part of a mat4 .
public static quat FromMat3(mat3 m)
        {
            var fourXSquaredMinus1 = m.m00 - m.m11 - m.m22;
            var fourYSquaredMinus1 = m.m11 - m.m00 - m.m22;
            var fourZSquaredMinus1 = m.m22 - m.m00 - m.m11;
            var fourWSquaredMinus1 = m.m00 + m.m11 + m.m22;
            var biggestIndex = 0;
            var fourBiggestSquaredMinus1 = fourWSquaredMinus1;
            if(fourXSquaredMinus1 > fourBiggestSquaredMinus1)
            {
                fourBiggestSquaredMinus1 = fourXSquaredMinus1;
                biggestIndex = 1;
            }
            if(fourYSquaredMinus1 > fourBiggestSquaredMinus1)
            {
                fourBiggestSquaredMinus1 = fourYSquaredMinus1;
                biggestIndex = 2;
            }
            if(fourZSquaredMinus1 > fourBiggestSquaredMinus1)
            {
                fourBiggestSquaredMinus1 = fourZSquaredMinus1;
                biggestIndex = 3;
            }
            var biggestVal = Math.Sqrt((double)fourBiggestSquaredMinus1 + 1.0) * 0.5;
            var mult = 0.25 / biggestVal;
            switch(biggestIndex)
            {
                case 0: return new quat((float)((double)(m.m12 - m.m21) * mult), (float)((double)(m.m20 - m.m02) * mult), (float)((double)(m.m01 - m.m10) * mult), (float)(biggestVal));
                case 1: return new quat((float)(biggestVal), (float)((double)(m.m01 + m.m10) * mult), (float)((double)(m.m20 + m.m02) * mult), (float)((double)(m.m12 - m.m21) * mult));
                case 2: return new quat((float)((double)(m.m01 + m.m10) * mult), (float)(biggestVal), (float)((double)(m.m12 + m.m21) * mult), (float)((double)(m.m20 - m.m02) * mult));
                default: return new quat((float)((double)(m.m20 + m.m02) * mult), (float)((double)(m.m12 + m.m21) * mult), (float)(biggestVal), (float)((double)(m.m01 - m.m10) * mult));
            }
        }
public static quat FromMat3 ( mat3 m ) { var fourXSquaredMinus1 = m . m00 - m . m11 - m . m22 ; var fourYSquaredMinus1 = m . m11 - m . m00 - m . m22 ; var fourZSquaredMinus1 = m . m22 - m . m00 - m . m11 ; var fourWSquaredMinus1 = m . m00 + m . m11 + m . m22 ; var biggestIndex = 0 ; var fourBiggestSquaredMinus1 = fourWSquaredMinus1 ; if ( fourXSquaredMinus1 > fourBiggestSquaredMinus1 ) { fourBiggestSquaredMinus1 = fourXSquaredMinus1 ; biggestIndex = 1 ; } if ( fourYSquaredMinus1 > fourBiggestSquaredMinus1 ) { fourBiggestSquaredMinus1 = fourYSquaredMinus1 ; biggestIndex = 2 ; } if ( fourZSquaredMinus1 > fourBiggestSquaredMinus1 ) { fourBiggestSquaredMinus1 = fourZSquaredMinus1 ; biggestIndex = 3 ; } var biggestVal = Math . Sqrt ( ( double ) fourBiggestSquaredMinus1 + 1.0 ) * 0.5 ; var mult = 0.25 / biggestVal ; switch ( biggestIndex ) { case 0 : return new quat ( ( float ) ( ( double ) ( m . m12 - m . m21 ) * mult ) , ( float ) ( ( double ) ( m . m20 - m . m02 ) * mult ) , ( float ) ( ( double ) ( m . m01 - m . m10 ) * mult ) , ( float ) ( biggestVal ) ) ; case 1 : return new quat ( ( float ) ( biggestVal ) , ( float ) ( ( double ) ( m . m01 + m . m10 ) * mult ) , ( float ) ( ( double ) ( m . m20 + m . m02 ) * mult ) , ( float ) ( ( double ) ( m . m12 - m . m21 ) * mult ) ) ; case 2 : return new quat ( ( float ) ( ( double ) ( m . m01 + m . m10 ) * mult ) , ( float ) ( biggestVal ) , ( float ) ( ( double ) ( m . m12 + m . m21 ) * mult ) , ( float ) ( ( double ) ( m . m20 - m . m02 ) * mult ) ) ; default : return new quat ( ( float ) ( ( double ) ( m . m20 + m . m02 ) * mult ) , ( float ) ( ( double ) ( m . m12 + m . m21 ) * mult ) , ( float ) ( biggestVal ) , ( float ) ( ( double ) ( m . m01 - m . m10 ) * mult ) ) ; } }
Creates a quaternion from the rotational part of a mat4.
Creates a quaternion from the rotational part of a mat4 .
m
mat3