public Matrix4f unprojectRay(float winX, float winY, int[] viewport, Vector3f originDest, Vector3f dirDest) {
        float a = m00 * m11 - m01 * m10;
        float b = m00 * m12 - m02 * m10;
        float c = m00 * m13 - m03 * m10;
        float d = m01 * m12 - m02 * m11;
        float e = m01 * m13 - m03 * m11;
        float f = m02 * m13 - m03 * m12;
        float g = m20 * m31 - m21 * m30;
        float h = m20 * m32 - m22 * m30;
        float i = m20 * m33 - m23 * m30;
        float j = m21 * m32 - m22 * m31;
        float k = m21 * m33 - m23 * m31;
        float l = m22 * m33 - m23 * m32;
        float det = a * l - b * k + c * j + d * i - e * h + f * g;
        det = 1.0f / det;
        float im00 = ( m11 * l - m12 * k + m13 * j) * det;
        float im01 = (-m01 * l + m02 * k - m03 * j) * det;
        float im02 = ( m31 * f - m32 * e + m33 * d) * det;
        float im03 = (-m21 * f + m22 * e - m23 * d) * det;
        float im10 = (-m10 * l + m12 * i - m13 * h) * det;
        float im11 = ( m00 * l - m02 * i + m03 * h) * det;
        float im12 = (-m30 * f + m32 * c - m33 * b) * det;
        float im13 = ( m20 * f - m22 * c + m23 * b) * det;
        float im20 = ( m10 * k - m11 * i + m13 * g) * det;
        float im21 = (-m00 * k + m01 * i - m03 * g) * det;
        float im22 = ( m30 * e - m31 * c + m33 * a) * det;
        float im23 = (-m20 * e + m21 * c - m23 * a) * det;
        float im30 = (-m10 * j + m11 * h - m12 * g) * det;
        float im31 = ( m00 * j - m01 * h + m02 * g) * det;
        float im32 = (-m30 * d + m31 * b - m32 * a) * det;
        float im33 = ( m20 * d - m21 * b + m22 * a) * det;
        float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;
        float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;
        float px = im00 * ndcX + im10 * ndcY + im30;
        float py = im01 * ndcX + im11 * ndcY + im31;
        float pz = im02 * ndcX + im12 * ndcY + im32;
        float invNearW = 1.0f / (im03 * ndcX + im13 * ndcY - im23 + im33);
        float nearX = (px - im20) * invNearW;
        float nearY = (py - im21) * invNearW;
        float nearZ = (pz - im22) * invNearW;
        float invFarW = 1.0f / (im03 * ndcX + im13 * ndcY + im23 + im33);
        float farX = (px + im20) * invFarW;
        float farY = (py + im21) * invFarW;
        float farZ = (pz + im22) * invFarW;
        originDest.x = nearX; originDest.y = nearY; originDest.z = nearZ;
        dirDest.x = farX - nearX; dirDest.y = farY - nearY; dirDest.z = farZ - nearZ;
        return this;
    }
public Matrix4f unprojectRay ( float winX , float winY , int [ ] viewport , Vector3f originDest , Vector3f dirDest ) { float a = m00 * m11 - m01 * m10 ; float b = m00 * m12 - m02 * m10 ; float c = m00 * m13 - m03 * m10 ; float d = m01 * m12 - m02 * m11 ; float e = m01 * m13 - m03 * m11 ; float f = m02 * m13 - m03 * m12 ; float g = m20 * m31 - m21 * m30 ; float h = m20 * m32 - m22 * m30 ; float i = m20 * m33 - m23 * m30 ; float j = m21 * m32 - m22 * m31 ; float k = m21 * m33 - m23 * m31 ; float l = m22 * m33 - m23 * m32 ; float det = a * l - b * k + c * j + d * i - e * h + f * g ; det = 1.0f / det ; float im00 = ( m11 * l - m12 * k + m13 * j ) * det ; float im01 = ( - m01 * l + m02 * k - m03 * j ) * det ; float im02 = ( m31 * f - m32 * e + m33 * d ) * det ; float im03 = ( - m21 * f + m22 * e - m23 * d ) * det ; float im10 = ( - m10 * l + m12 * i - m13 * h ) * det ; float im11 = ( m00 * l - m02 * i + m03 * h ) * det ; float im12 = ( - m30 * f + m32 * c - m33 * b ) * det ; float im13 = ( m20 * f - m22 * c + m23 * b ) * det ; float im20 = ( m10 * k - m11 * i + m13 * g ) * det ; float im21 = ( - m00 * k + m01 * i - m03 * g ) * det ; float im22 = ( m30 * e - m31 * c + m33 * a ) * det ; float im23 = ( - m20 * e + m21 * c - m23 * a ) * det ; float im30 = ( - m10 * j + m11 * h - m12 * g ) * det ; float im31 = ( m00 * j - m01 * h + m02 * g ) * det ; float im32 = ( - m30 * d + m31 * b - m32 * a ) * det ; float im33 = ( m20 * d - m21 * b + m22 * a ) * det ; float ndcX = ( winX - viewport [ 0 ] ) / viewport [ 2 ] * 2.0f - 1.0f ; float ndcY = ( winY - viewport [ 1 ] ) / viewport [ 3 ] * 2.0f - 1.0f ; float px = im00 * ndcX + im10 * ndcY + im30 ; float py = im01 * ndcX + im11 * ndcY + im31 ; float pz = im02 * ndcX + im12 * ndcY + im32 ; float invNearW = 1.0f / ( im03 * ndcX + im13 * ndcY - im23 + im33 ) ; float nearX = ( px - im20 ) * invNearW ; float nearY = ( py - im21 ) * invNearW ; float nearZ = ( pz - im22 ) * invNearW ; float invFarW = 1.0f / ( im03 * ndcX + im13 * ndcY + im23 + im33 ) ; float farX = ( px + im20 ) * invFarW ; float farY = ( py + im21 ) * invFarW ; float farZ = ( pz + im22 ) * invFarW ; originDest . x = nearX ; originDest . y = nearY ; originDest . z = nearZ ; dirDest . x = farX - nearX ; dirDest . y = farY - nearY ; dirDest . z = farZ - nearZ ; return this ; }
/* (non-Javadoc)
@see org.joml.Matrix4fc#unprojectRay(float, float, int[], org.joml.Vector3f, org.joml.Vector3f)