Exemplo n.º 1
0
    public static Matrix4x4 InverseSubMatrix(this Matrix4x4 m)
    {
        float det = m.DeterminantSubMatrix();

        if (det == 0)
        {
            throw new System.ArgumentException("Cannot calculate inverse of the matrix since it is singular.");
        }

        float     detInv = 1 / det;
        Matrix4x4 output = m.AdjugateSubMatrix();

        output.m00 *= detInv;
        output.m01 *= detInv;
        output.m02 *= detInv;

        output.m10 *= detInv;
        output.m11 *= detInv;
        output.m12 *= detInv;

        output.m20 *= detInv;
        output.m21 *= detInv;
        output.m22 *= detInv;

        output.m30 = m.m30;
        output.m31 = m.m31;
        output.m32 = m.m32;
        output.m33 = m.m33;

        return(output);
    }