public Vector4d unproject(double winX, double winY, double winZ, int[] viewport, Vector4d dest) {
        double a = m00 * m11 - m01 * m10;
        double b = m00 * m12 - m02 * m10;
        double c = m00 * m13 - m03 * m10;
        double d = m01 * m12 - m02 * m11;
        double e = m01 * m13 - m03 * m11;
        double f = m02 * m13 - m03 * m12;
        double g = m20 * m31 - m21 * m30;
        double h = m20 * m32 - m22 * m30;
        double i = m20 * m33 - m23 * m30;
        double j = m21 * m32 - m22 * m31;
        double k = m21 * m33 - m23 * m31;
        double l = m22 * m33 - m23 * m32;
        double det = a * l - b * k + c * j + d * i - e * h + f * g;
        det = 1.0 / det;
        double im00 = ( m11 * l - m12 * k + m13 * j) * det;
        double im01 = (-m01 * l + m02 * k - m03 * j) * det;
        double im02 = ( m31 * f - m32 * e + m33 * d) * det;
        double im03 = (-m21 * f + m22 * e - m23 * d) * det;
        double im10 = (-m10 * l + m12 * i - m13 * h) * det;
        double im11 = ( m00 * l - m02 * i + m03 * h) * det;
        double im12 = (-m30 * f + m32 * c - m33 * b) * det;
        double im13 = ( m20 * f - m22 * c + m23 * b) * det;
        double im20 = ( m10 * k - m11 * i + m13 * g) * det;
        double im21 = (-m00 * k + m01 * i - m03 * g) * det;
        double im22 = ( m30 * e - m31 * c + m33 * a) * det;
        double im23 = (-m20 * e + m21 * c - m23 * a) * det;
        double im30 = (-m10 * j + m11 * h - m12 * g) * det;
        double im31 = ( m00 * j - m01 * h + m02 * g) * det;
        double im32 = (-m30 * d + m31 * b - m32 * a) * det;
        double im33 = ( m20 * d - m21 * b + m22 * a) * det;
        double ndcX = (winX-viewport[0])/viewport[2]*2.0-1.0;
        double ndcY = (winY-viewport[1])/viewport[3]*2.0-1.0;
        double ndcZ = winZ+winZ-1.0;
        double invW = 1.0 / (im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33);
        dest.x = (im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30) * invW;
        dest.y = (im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31) * invW;
        dest.z = (im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32) * invW;
        dest.w = 1.0;
        return dest;
    }
public Vector4d unproject ( double winX , double winY , double winZ , int [ ] viewport , Vector4d dest ) { double a = m00 * m11 - m01 * m10 ; double b = m00 * m12 - m02 * m10 ; double c = m00 * m13 - m03 * m10 ; double d = m01 * m12 - m02 * m11 ; double e = m01 * m13 - m03 * m11 ; double f = m02 * m13 - m03 * m12 ; double g = m20 * m31 - m21 * m30 ; double h = m20 * m32 - m22 * m30 ; double i = m20 * m33 - m23 * m30 ; double j = m21 * m32 - m22 * m31 ; double k = m21 * m33 - m23 * m31 ; double l = m22 * m33 - m23 * m32 ; double det = a * l - b * k + c * j + d * i - e * h + f * g ; det = 1.0 / det ; double im00 = ( m11 * l - m12 * k + m13 * j ) * det ; double im01 = ( - m01 * l + m02 * k - m03 * j ) * det ; double im02 = ( m31 * f - m32 * e + m33 * d ) * det ; double im03 = ( - m21 * f + m22 * e - m23 * d ) * det ; double im10 = ( - m10 * l + m12 * i - m13 * h ) * det ; double im11 = ( m00 * l - m02 * i + m03 * h ) * det ; double im12 = ( - m30 * f + m32 * c - m33 * b ) * det ; double im13 = ( m20 * f - m22 * c + m23 * b ) * det ; double im20 = ( m10 * k - m11 * i + m13 * g ) * det ; double im21 = ( - m00 * k + m01 * i - m03 * g ) * det ; double im22 = ( m30 * e - m31 * c + m33 * a ) * det ; double im23 = ( - m20 * e + m21 * c - m23 * a ) * det ; double im30 = ( - m10 * j + m11 * h - m12 * g ) * det ; double im31 = ( m00 * j - m01 * h + m02 * g ) * det ; double im32 = ( - m30 * d + m31 * b - m32 * a ) * det ; double im33 = ( m20 * d - m21 * b + m22 * a ) * det ; double ndcX = ( winX - viewport [ 0 ] ) / viewport [ 2 ] * 2.0 - 1.0 ; double ndcY = ( winY - viewport [ 1 ] ) / viewport [ 3 ] * 2.0 - 1.0 ; double ndcZ = winZ + winZ - 1.0 ; double invW = 1.0 / ( im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33 ) ; dest . x = ( im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30 ) * invW ; dest . y = ( im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31 ) * invW ; dest . z = ( im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32 ) * invW ; dest . w = 1.0 ; return dest ; }
/* (non-Javadoc)
@see org.joml.Matrix4dc#unproject(double, double, double, int[], org.joml.Vector4d)