float t = matrix.m00 + matrix.m11 + matrix.m22 + 1;  if (t > FastMath.FLT_EPSILON * 3) { float s = 0.5f / FastMath.sqrt(t); w = 0.25f / s; x = (matrix.m21 - matrix.m12) * s; y = (matrix.m02 - matrix.m20) * s; z = (matrix.m10 - matrix.m01) * s; } else if ((matrix.m00 > matrix.m11) && (matrix.m00 > matrix.m22)) { float s = FastMath .sqrt(1.0f + matrix.m00 - matrix.m11 - matrix.m22) * 2; x = 0.25f * s; y = (matrix.m01 + matrix.m10) / s; z = (matrix.m02 + matrix.m20) / s; w = (matrix.m12 - matrix.m21) / s; } else if (matrix.m11 > matrix.m22) { float s = FastMath .sqrt(1.0f + matrix.m11 - matrix.m00 - matrix.m22) * 2; x = (matrix.m01 + matrix.m10) / s; y = 0.25f * s; z = (matrix.m12 + matrix.m21) / s; w = (matrix.m02 - matrix.m20) / s; } else { float s = FastMath .sqrt(1.0f + matrix.m22 - matrix.m00 - matrix.m11) * 2; x = (matrix.m02 + matrix.m20) / s; y = (matrix.m12 + matrix.m21) / s; z = 0.25f * s; w = (matrix.m01 - matrix.m10) / s; }
fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, matrix.m22);
    public void fromRotationMatrix(Matrix3f matrix) {        float t = matrix.m00 + matrix.m11 + matrix.m22 + 1;        if (t > FastMath.FLT_EPSILON * 3) {            float s = 0.5f / FastMath.sqrt(t);            w = 0.25f / s;            x = (matrix.m21 - matrix.m12) * s;            y = (matrix.m02 - matrix.m20) * s;            z = (matrix.m10 - matrix.m01) * s;        } else if ((matrix.m00 > matrix.m11) && (matrix.m00 > matrix.m22)) {            float s = FastMath                    .sqrt(1.0f + matrix.m00 - matrix.m11 - matrix.m22) * 2;            x = 0.25f * s;            y = (matrix.m01 + matrix.m10) / s;            z = (matrix.m02 + matrix.m20) / s;            w = (matrix.m12 - matrix.m21) / s;        } else if (matrix.m11 > matrix.m22) {            float s = FastMath                    .sqrt(1.0f + matrix.m11 - matrix.m00 - matrix.m22) * 2;            x = (matrix.m01 + matrix.m10) / s;            y = 0.25f * s;            z = (matrix.m12 + matrix.m21) / s;            w = (matrix.m02 - matrix.m20) / s;        } else {            float s = FastMath                    .sqrt(1.0f + matrix.m22 - matrix.m00 - matrix.m11) * 2;            x = (matrix.m02 + matrix.m20) / s;            y = (matrix.m12 + matrix.m21) / s;            z = 0.25f * s;            w = (matrix.m01 - matrix.m10) / s;        }    }