Commit 43643072 authored by David Adam's avatar David Adam Committed by Alexandre Julliard

d3dx8: Implement D3XMatrixInverse.

parent f6833c4d
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
@ stdcall D3DXMatrixfDeterminant(ptr) @ stdcall D3DXMatrixfDeterminant(ptr)
@ stdcall D3DXMatrixMultiply(ptr ptr ptr) @ stdcall D3DXMatrixMultiply(ptr ptr ptr)
@ stdcall D3DXMatrixTranspose(ptr ptr) @ stdcall D3DXMatrixTranspose(ptr ptr)
@ stub D3DXMatrixInverse @ stdcall D3DXMatrixInverse(ptr ptr ptr)
@ stdcall D3DXMatrixScaling(ptr long long long) @ stdcall D3DXMatrixScaling(ptr long long long)
@ stdcall D3DXMatrixTranslation(ptr long long long) @ stdcall D3DXMatrixTranslation(ptr long long long)
@ stdcall D3DXMatrixRotationX(ptr long) @ stdcall D3DXMatrixRotationX(ptr long)
......
...@@ -47,6 +47,45 @@ FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm) ...@@ -47,6 +47,45 @@ FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm)
return det; return det;
} }
D3DXMATRIX* WINAPI D3DXMatrixInverse(D3DXMATRIX *pout, FLOAT *pdeterminant, CONST D3DXMATRIX *pm)
{
int a, i, j;
D3DXVECTOR4 v, vec[3];
FLOAT cofactor, det;
det = D3DXMatrixfDeterminant(pm);
if ( !det ) return NULL;
if ( pdeterminant ) *pdeterminant = det;
for (i=0; i<4; i++)
{
for (j=0; j<4; j++)
{
if (j != i )
{
a = j;
if ( j > i ) a = a-1;
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];
}
}
D3DXVec4Cross(&v, &vec[0], &vec[1], &vec[2]);
for (j=0; j<4; j++)
{
switch(j)
{
case 0: cofactor = v.x; break;
case 1: cofactor = v.y; break;
case 2: cofactor = v.z; break;
case 3: cofactor = v.w; break;
}
pout->u.m[j][i] = pow(-1.0f, i) * cofactor / det;
}
}
return pout;
}
D3DXMATRIX* WINAPI D3DXMatrixLookAtLH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup) D3DXMATRIX* WINAPI D3DXMatrixLookAtLH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup)
{ {
D3DXVECTOR3 right, rightn, up, upn, vec, vec2; D3DXVECTOR3 right, rightn, up, upn, vec, vec2;
......
...@@ -149,10 +149,11 @@ static void D3DXColorTest(void) ...@@ -149,10 +149,11 @@ static void D3DXColorTest(void)
static void D3DXMatrixTest(void) static void D3DXMatrixTest(void)
{ {
D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3; D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
LPD3DXMATRIX funcpointer;
D3DXQUATERNION q; D3DXQUATERNION q;
D3DXVECTOR3 at, axis, eye; D3DXVECTOR3 at, axis, eye;
BOOL expected, got; BOOL expected, got;
FLOAT angle, expectedfloat, gotfloat; FLOAT angle, determinant, expectedfloat, gotfloat;
U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
...@@ -181,6 +182,18 @@ static void D3DXMatrixTest(void) ...@@ -181,6 +182,18 @@ static void D3DXMatrixTest(void)
gotfloat = D3DXMatrixfDeterminant(&mat); gotfloat = D3DXMatrixfDeterminant(&mat);
ok(fabs( gotfloat - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat); ok(fabs( gotfloat - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
/*____________D3DXMatrixInverse______________*/
expectedmat.m[0][0] = 16067.0f/73944.0f; expectedmat.m[0][1] = -10165.0f/147888.0f; expectedmat.m[0][2] = -2729.0f/147888.0f; expectedmat.m[0][3] = -1631.0f/49296.0f;
expectedmat.m[1][0] = -565.0f/36972.0f; expectedmat.m[1][1] = 2723.0f/73944.0f; expectedmat.m[1][2] = -1073.0f/73944.0f; expectedmat.m[1][3] = 289.0f/24648.0f;
expectedmat.m[2][0] = -389.0f/2054.0f; expectedmat.m[2][1] = 337.0f/4108.0f; expectedmat.m[2][2] = 181.0f/4108.0f; expectedmat.m[2][3] = 317.0f/4108.0f;
expectedmat.m[3][0] = 163.0f/5688.0f; expectedmat.m[3][1] = -101.0f/11376.0f; expectedmat.m[3][2] = -73.0f/11376.0f; expectedmat.m[3][3] = -127.0f/3792.0f;
expectedfloat = -147888.0f;
D3DXMatrixInverse(&gotmat,&determinant,&mat);
expect_mat(expectedmat,gotmat);
ok(fabs( determinant - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, determinant);
funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
/*____________D3DXMatrixIsIdentity______________*/ /*____________D3DXMatrixIsIdentity______________*/
expected = FALSE; expected = FALSE;
got = D3DXMatrixIsIdentity(&mat3); got = D3DXMatrixIsIdentity(&mat3);
......
...@@ -260,6 +260,7 @@ typedef struct D3DXCOLOR ...@@ -260,6 +260,7 @@ typedef struct D3DXCOLOR
} D3DXCOLOR, *LPD3DXCOLOR; } D3DXCOLOR, *LPD3DXCOLOR;
FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm); FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm);
D3DXMATRIX* WINAPI D3DXMatrixInverse(D3DXMATRIX *pout, FLOAT *pdeterminant, CONST D3DXMATRIX *pm);
D3DXMATRIX* WINAPI D3DXMatrixLookAtLH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup); D3DXMATRIX* WINAPI D3DXMatrixLookAtLH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup);
D3DXMATRIX* WINAPI D3DXMatrixLookAtRH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup); D3DXMATRIX* WINAPI D3DXMatrixLookAtRH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup);
D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *pm1, CONST D3DXMATRIX *pm2); D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *pm1, CONST D3DXMATRIX *pm2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment