//////////////////////////////////////////////////////////////////////////// /// // Invert matrix void m3dInvertMatrix44(M3DMatrix44d mInverse, const M3DMatrix44d m) { int i, j; double det, detij; // calculate 4x4 determinant det = 0.0; for (i = 0; i < 4; i++) { det += (i & 0x1) ? (-m[i] * DetIJ(m, 0, i)) : (m[i] * DetIJ(m, 0,i)); } det = 1.0 / det; // calculate inverse for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { detij = DetIJ(m, j, i); mInverse[(i*4)+j] = ((i+j) & 0x1) ? (-detij * det) : (detij *det); } } }
//////////////////////////////////////////////////////////////////////////// /// // Invert matrix void gltInvertMatrix(const GLTMatrix m, GLTMatrix mInverse) { int i, j; float det, detij; // calculate 4x4 determinant det = 0.0f; for (i = 0; i < 4; i++) { det += (i & 0x1) ? (-m[i] * DetIJ(m, 0, i)) : (m[i] * DetIJ(m, 0,i)); } det = 1.0f / det; // calculate inverse for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { detij = DetIJ(m, j, i); mInverse[(i*4)+j] = ((i+j) & 0x1) ? (-detij * det) : (detij *det); } } }