#define matrix44_inverse(r, m, ambuf, detbuf)\ (ambuf)[0] = ((m)[5]*((m)[10]*(m)[15] - (m)[14]*(m)[11]) - (m)[9]*((m)[6]*(m)[15] - (m)[14]*(m)[7]) + (m)[13]*((m)[6]*(m)[11] - (m)[10]*(m)[7]));\ (ambuf)[1] = -((m)[4]*((m)[10]*(m)[15] - (m)[14]*(m)[11]) - (m)[8]*((m)[6]*(m)[15] - (m)[14]*(m)[7]) + (m)[12]*((m)[6]*(m)[11] - (m)[10]*(m)[7]));\ (ambuf)[2] = ((m)[4]*((m)[9]*(m)[15] - (m)[13]*(m)[11]) - (m)[8]*((m)[5]*(m)[15] - (m)[13]*(m)[7]) + (m)[12]*((m)[5]*(m)[11] - (m)[9]*(m)[7]));\ (ambuf)[3] = -((m)[4]*((m)[9]*(m)[14] - (m)[13]*(m)[10]) - (m)[8]*((m)[5]*(m)[14] - (m)[13]*(m)[6]) + (m)[12]*((m)[5]*(m)[10] - (m)[9]*(m)[6]));\ (ambuf)[4] = -((m)[1]*((m)[10]*(m)[15] - (m)[14]*(m)[11]) - (m)[9]*((m)[2]*(m)[15] - (m)[14]*(m)[3]) + (m)[13]*((m)[2]*(m)[11] - (m)[10]*(m)[3]));\ (ambuf)[5] = ((m)[0]*((m)[10]*(m)[15] - (m)[14]*(m)[11]) - (m)[8]*((m)[2]*(m)[15] - (m)[14]*(m)[3]) + (m)[12]*((m)[2]*(m)[11] - (m)[10]*(m)[3]));\ (ambuf)[6] = -((m)[0]*((m)[9]*(m)[15] - (m)[13]*(m)[11]) - (m)[8]*((m)[1]*(m)[15] - (m)[13]*(m)[3]) + (m)[12]*((m)[1]*(m)[11] - (m)[9]*(m)[3]));\ (ambuf)[7] = ((m)[0]*((m)[9]*(m)[14] - (m)[13]*(m)[10]) - (m)[8]*((m)[1]*(m)[14] - (m)[13]*(m)[2]) + (m)[12]*((m)[1]*(m)[10] - (m)[9]*(m)[2]));\ (ambuf)[8] = ((m)[1]*((m)[6]*(m)[15] - (m)[14]*(m)[7]) - (m)[5]*((m)[2]*(m)[15] - (m)[14]*(m)[3]) + (m)[13]*((m)[2]*(m)[7] - (m)[6]*(m)[3]));\ (ambuf)[9] = -((m)[0]*((m)[6]*(m)[15] - (m)[14]*(m)[7]) - (m)[4]*((m)[2]*(m)[15] - (m)[14]*(m)[3]) + (m)[12]*((m)[2]*(m)[7] - (m)[6]*(m)[3]));\ (ambuf)[10] = ((m)[0]*((m)[5]*(m)[15] - (m)[13]*(m)[7]) - (m)[4]*((m)[1]*(m)[15] - (m)[13]*(m)[3]) + (m)[12]*((m)[1]*(m)[7] - (m)[5]*(m)[3]));\ (ambuf)[11] = -((m)[0]*((m)[5]*(m)[14] - (m)[13]*(m)[6]) - (m)[4]*((m)[1]*(m)[14] - (m)[13]*(m)[2]) + (m)[12]*((m)[1]*(m)[6] - (m)[5]*(m)[2]));\ (ambuf)[12] = -((m)[1]*((m)[6]*(m)[11] - (m)[10]*(m)[7]) - (m)[5]*((m)[2]*(m)[11] - (m)[10]*(m)[3]) + (m)[9]*((m)[2]*(m)[7] - (m)[6]*(m)[3]));\ (ambuf)[13] = ((m)[0]*((m)[6]*(m)[11] - (m)[10]*(m)[7]) - (m)[4]*((m)[2]*(m)[11] - (m)[10]*(m)[3]) + (m)[8]*((m)[2]*(m)[7] - (m)[6]*(m)[3]));\ (ambuf)[14] = -((m)[0]*((m)[5]*(m)[11] - (m)[9]*(m)[7]) - (m)[4]*((m)[1]*(m)[11] - (m)[9]*(m)[3]) + (m)[8]*((m)[1]*(m)[7] - (m)[5]*(m)[3]));\ (ambuf)[15] = ((m)[0]*((m)[5]*(m)[10] - (m)[9]*(m)[6]) - (m)[4]*((m)[1]*(m)[10] - (m)[9]*(m)[2]) + (m)[8]*((m)[1]*(m)[6] - (m)[5]*(m)[2]));\ (detbuf) = (ambuf)[0]*(m)[0]+(ambuf)[4]*(m)[4]+(ambuf)[8]*(m)[8]+(ambuf)[12]*(m)[12];\ if(detbuf)\ {\ (r)[0] = (ambuf)[0] / (detbuf);\ (r)[1] = (ambuf)[4] / (detbuf);\ (r)[2] = (ambuf)[8] / (detbuf);\ (r)[3] = (ambuf)[12] / (detbuf);\ (r)[4] = (ambuf)[1] / (detbuf);\ (r)[5] = (ambuf)[5] / (detbuf);\ (r)[6] = (ambuf)[9] / (detbuf);\ (r)[7] = (ambuf)[13] / (detbuf);\ (r)[8] = (ambuf)[2] / (detbuf);\ (r)[9] = (ambuf)[6] / (detbuf);\ (r)[10] = (ambuf)[10] / (detbuf);\ (r)[11] = (ambuf)[14] / (detbuf);\ (r)[12] = (ambuf)[3] / (detbuf);\ (r)[13] = (ambuf)[7] / (detbuf);\ (r)[14] = (ambuf)[11] / (detbuf);\ (r)[15] = (ambuf)[15] / (detbuf);\ } #define matrix44_inverse2(r, m, ambuf, detbuf, cache) /* cache requires array of 17 elements | Ex: float cache[17]; */\ (ambuf)[0] = ((m)[5]*(cache[0] = ((m)[10]*(m)[15] - (m)[14]*(m)[11])) - (m)[9]*(cache[1] = ((m)[6]*(m)[15] - (m)[14]*(m)[7])) + (m)[13]*(cache[2] = ((m)[6]*(m)[11] - (m)[10]*(m)[7])));\ (ambuf)[1] = -((m)[4]*(cache[0]) - (m)[8]*(cache[1]) + (m)[12]*(cache[2]));\ (ambuf)[2] = ((m)[4]*(cache[3] = ((m)[9]*(m)[15] - (m)[13]*(m)[11])) - (m)[8]*(cache[4] = ((m)[5]*(m)[15] - (m)[13]*(m)[7])) + (m)[12]*(cache[5] = ((m)[5]*(m)[11] - (m)[9]*(m)[7])));\ (ambuf)[3] = -((m)[4]*(cache[6] = ((m)[9]*(m)[14] - (m)[13]*(m)[10])) - (m)[8]*(cache[7] = ((m)[5]*(m)[14] - (m)[13]*(m)[6])) + (m)[12]*(cache[8] = ((m)[5]*(m)[10] - (m)[9]*(m)[6])));\ (ambuf)[4] = -((m)[1]*(cache[0]) - (m)[9]*(cache[9] = ((m)[2]*(m)[15] - (m)[14]*(m)[3])) + (m)[13]*(cache[10] = ((m)[2]*(m)[11] - (m)[10]*(m)[3])));\ (ambuf)[5] = ((m)[0]*(cache[0]) - (m)[8]*(cache[9]) + (m)[12]*(cache[10]));\ (ambuf)[6] = -((m)[0]*(cache[3]) - (m)[8]*(cache[11] = ((m)[1]*(m)[15] - (m)[13]*(m)[3])) + (m)[12]*(cache[12] = ((m)[1]*(m)[11] - (m)[9]*(m)[3])));\ (ambuf)[7] = ((m)[0]*(cache[6]) - (m)[8]*(cache[13] = ((m)[1]*(m)[14] - (m)[13]*(m)[2])) + (m)[12]*(cache[14] = ((m)[1]*(m)[10] - (m)[9]*(m)[2])));\ (ambuf)[8] = ((m)[1]*(cache[1]) - (m)[5]*(cache[9]) + (m)[13]*(cache[15] = ((m)[2]*(m)[7] - (m)[6]*(m)[3])));\ (ambuf)[9] = -((m)[0]*(cache[1]) - (m)[4]*(cache[9]) + (m)[12]*(cache[15]));\ (ambuf)[10] = ((m)[0]*(cache[4]) - (m)[4]*(cache[11]) + (m)[12]*((m)[1]*(m)[7] - (m)[5]*(m)[3]));\ (ambuf)[11] = -((m)[0]*(cache[7]) - (m)[4]*(cache[13]) + (m)[12]*((m)[1]*(m)[6] - (m)[5]*(m)[2]));\ (ambuf)[12] = -((m)[1]*(cache[2]) - (m)[5]*(cache[10]) + (m)[9]*(cache[16] = ((m)[2]*(m)[7] - (m)[6]*(m)[3])));\ (ambuf)[13] = ((m)[0]*(cache[2]) - (m)[4]*(cache[10]) + (m)[8]*(cache[16]));\ (ambuf)[14] = -((m)[0]*(cache[5]) - (m)[4]*(cache[12]) + (m)[8]*((m)[1]*(m)[7] - (m)[5]*(m)[3]));\ (ambuf)[15] = ((m)[0]*(cache[8]) - (m)[4]*(cache[14]) + (m)[8]*((m)[1]*(m)[6] - (m)[5]*(m)[2]));\ (detbuf) = (ambuf)[0]*(m)[0]+(ambuf)[4]*(m)[4]+(ambuf)[8]*(m)[8]+(ambuf)[12]*(m)[12];\ if(detbuf)\ {\ (r)[0] = (ambuf)[0] / (detbuf);\ (r)[1] = (ambuf)[4] / (detbuf);\ (r)[2] = (ambuf)[8] / (detbuf);\ (r)[3] = (ambuf)[12] / (detbuf);\ (r)[4] = (ambuf)[1] / (detbuf);\ (r)[5] = (ambuf)[5] / (detbuf);\ (r)[6] = (ambuf)[9] / (detbuf);\ (r)[7] = (ambuf)[13] / (detbuf);\ (r)[8] = (ambuf)[2] / (detbuf);\ (r)[9] = (ambuf)[6] / (detbuf);\ (r)[10] = (ambuf)[10] / (detbuf);\ (r)[11] = (ambuf)[14] / (detbuf);\ (r)[12] = (ambuf)[3] / (detbuf);\ (r)[13] = (ambuf)[7] / (detbuf);\ (r)[14] = (ambuf)[11] / (detbuf);\ (r)[15] = (ambuf)[15] / (detbuf);\ }