From 230eac4b5a2839a1f6a86d73694228da13563321 Mon Sep 17 00:00:00 2001 From: Nozomi Kodama Date: Sun, 24 Feb 2013 18:59:12 -1000 Subject: d3dx9: Avoid expensive computations --- dlls/d3dx9_36/math.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c index 69c3297..63c0607 100644 --- a/dlls/d3dx9_36/math.c +++ b/dlls/d3dx9_36/math.c @@ -273,32 +273,34 @@ D3DXMATRIX* WINAPI D3DXMatrixInverse(D3DXMATRIX *pout, FLOAT *pdeterminant, cons int a, i, j; D3DXMATRIX out; D3DXVECTOR4 v, vec[3]; - FLOAT det; + FLOAT det, signed_det; TRACE("pout %p, pdeterminant %p, pm %p\n", pout, pdeterminant, pm); det = D3DXMatrixDeterminant(pm); - if ( !det ) return NULL; - if ( pdeterminant ) *pdeterminant = det; - for (i=0; i<4; i++) + if (!det) + return NULL; + if (pdeterminant) + *pdeterminant = det; + + for (i = 0; i < 4; i++) { - for (j=0; j<4; j++) - { - if (j != i ) + for (j = 0; j < 4; j++) + if (j != i) { - a = j; - if ( j > i ) a = a-1; + a = (j > i)? j - 1: j; vec[a].x = pm->u.m[j][0]; vec[a].y = pm->u.m[j][1]; vec[a].z = pm->u.m[j][2]; vec[a].w = pm->u.m[j][3]; } - } + + signed_det = (i % 2)? -det: det; D3DXVec4Cross(&v, &vec[0], &vec[1], &vec[2]); - out.u.m[0][i] = pow(-1.0f, i) * v.x / det; - out.u.m[1][i] = pow(-1.0f, i) * v.y / det; - out.u.m[2][i] = pow(-1.0f, i) * v.z / det; - out.u.m[3][i] = pow(-1.0f, i) * v.w / det; + out.u.m[0][i] = v.x / signed_det; + out.u.m[1][i] = v.y / signed_det; + out.u.m[2][i] = v.z / signed_det; + out.u.m[3][i] = v.w / signed_det; } *pout = out; -- 1.7.10.4