target/generated-sources/template/com/flowpowered/math/imaginary/Quaternionf.java
public static Quaternionf fromRotationMatrix(Matrix3f matrix) {
        final float trace = matrix.trace();
        if (trace < 0) {
            if (matrix.get(1, 1) > matrix.get(0, 0)) {
                if (matrix.get(2, 2) > matrix.get(1, 1)) {
                    final float r = (float) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                    final float s = 0.5f / r;
                    return new Quaternionf(
                            (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            0.5f * r,
                            (matrix.get(1, 0) - matrix.get(0, 1)) * s);
                } else {
                    final float r = (float) Math.sqrt(matrix.get(1, 1) - matrix.get(2, 2) - matrix.get(0, 0) + 1);
                    final float s = 0.5f / r;
                    return new Quaternionf(
                            (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                            0.5f * r,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            (matrix.get(0, 2) - matrix.get(2, 0)) * s);
                }
            } else if (matrix.get(2, 2) > matrix.get(0, 0)) {
                final float r = (float) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                final float s = 0.5f / r;
                return new Quaternionf(
                        (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                        (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                        0.5f * r,
                        (matrix.get(1, 0) - matrix.get(0, 1)) * s);
            } else {
                final float r = (float) Math.sqrt(matrix.get(0, 0) - matrix.get(1, 1) - matrix.get(2, 2) + 1);
                final float s = 0.5f / r;
                return new Quaternionf(
                        0.5f * r,
                        (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                        (matrix.get(2, 0) - matrix.get(0, 2)) * s,
                        (matrix.get(2, 1) - matrix.get(1, 2)) * s);
            }
        } else {
            final float r = (float) Math.sqrt(trace + 1);
            final float s = 0.5f / r;
            return new Quaternionf(
                    (matrix.get(2, 1) - matrix.get(1, 2)) * s,
                    (matrix.get(0, 2) - matrix.get(2, 0)) * s,
                    (matrix.get(1, 0) - matrix.get(0, 1)) * s,
                    0.5f * r);
        }
    }
public static Quaternionf fromRotationMatrix(Matrix3f matrix) {
        final float trace = matrix.trace();
        if (trace < 0) {
            if (matrix.get(1, 1) > matrix.get(0, 0)) {
                if (matrix.get(2, 2) > matrix.get(1, 1)) {
                    final float r = (float) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                    final float s = 0.5f / r;
                    return new Quaternionf(
                            (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            0.5f * r,
                            (matrix.get(1, 0) - matrix.get(0, 1)) * s);
                } else {
                    final float r = (float) Math.sqrt(matrix.get(1, 1) - matrix.get(2, 2) - matrix.get(0, 0) + 1);
                    final float s = 0.5f / r;
                    return new Quaternionf(
                            (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                            0.5f * r,
                            (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                            (matrix.get(0, 2) - matrix.get(2, 0)) * s);
                }
            } else if (matrix.get(2, 2) > matrix.get(0, 0)) {
                final float r = (float) Math.sqrt(matrix.get(2, 2) - matrix.get(0, 0) - matrix.get(1, 1) + 1);
                final float s = 0.5f / r;
                return new Quaternionf(
                        (matrix.get(2, 0) + matrix.get(0, 2)) * s,
                        (matrix.get(1, 2) + matrix.get(2, 1)) * s,
                        0.5f * r,
                        (matrix.get(1, 0) - matrix.get(0, 1)) * s);
            } else {
                final float r = (float) Math.sqrt(matrix.get(0, 0) - matrix.get(1, 1) - matrix.get(2, 2) + 1);
                final float s = 0.5f / r;
                return new Quaternionf(
                        0.5f * r,
                        (matrix.get(0, 1) + matrix.get(1, 0)) * s,
                        (matrix.get(2, 0) - matrix.get(0, 2)) * s,
                        (matrix.get(2, 1) - matrix.get(1, 2)) * s);
            }
        } else {
            final float r = (float) Math.sqrt(trace + 1);
            final float s = 0.5f / r;
            return new Quaternionf(
                    (matrix.get(2, 1) - matrix.get(1, 2)) * s,
                    (matrix.get(0, 2) - matrix.get(2, 0)) * s,
                    (matrix.get(1, 0) - matrix.get(0, 1)) * s,
                    0.5f * r);
        }
    }
Creates a new quaternion from the rotation matrix. The matrix will be interpreted as a rotation matrix even if it is not.

@param matrix The rotation matrix
@return The quaternion defined by the rotation matrix