[PATCH] Implement D3dxMatrixMultiply with a test
David Adam
David.Adam at math.cnrs.fr
Tue Oct 30 08:46:19 CDT 2007
---
dlls/d3dx8/d3dx8.spec | 2 +-
dlls/d3dx8/math.c | 14 ++++++++++++
dlls/d3dx8/tests/math.c | 52 +++++++++++++++++++++++++++++++++++++++++---=
--
include/d3dx8math.h | 1 +
4 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index d08fb9f..808e509 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -21,7 +21,7 @@
@ stdcall D3DXVec4BaryCentric(ptr ptr ptr ptr long long)
@ stdcall D3DXVec4Transform(ptr ptr ptr)
@ stdcall D3DXMatrixfDeterminant(ptr)
-@ stub D3DXMatrixMultiply
+@ stdcall D3DXMatrixMultiply(ptr ptr ptr)
@ stub D3DXMatrixTranspose
@ stub D3DXMatrixInverse
@ stub D3DXMatrixScaling
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index fa1a49e..3c46581 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -44,6 +44,20 @@ FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm)
return det;
}
=20
+D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *p=
m1, CONST D3DXMATRIX *pm2)
+{
+ int i,j;
+
+ for (i=3D0; i<4; i++)
+ {
+ for (j=3D0; j<4; j++)
+ {
+ pout->m[i][j] =3D pm1->m[i][0] * pm2->m[0][j] + pm1->m[i][1] * pm2->m=
[1][j] + pm1->m[i][2] * pm2->m[2][j] + pm1->m[i][3] * pm2->m[3][j];
+ }
+ }
+ return pout;
+}
+
/*_________________D3DXQUATERNION________________*/
=20
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq)
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index cda666a..fbfe46d 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -25,6 +25,31 @@
=20
#define expect_color(expectedcolor,gotcolor) ok((fabs(expectedcolor.r-gotco=
lor.r)<admitted_error)&&(fabs(expectedcolor.g-gotcolor.g)<admitted_error)&&(=
fabs(expectedcolor.b-gotcolor.b)<admitted_error)&&(fabs(expectedcolor.a-gotc=
olor.a)<admitted_error),"Expected Color=3D (%f, %f, %f, %f)\n , Got Color=3D=
(%f, %f, %f, %f)\n", expectedcolor.r, expectedcolor.g, expectedcolor.b, exp=
ectedcolor.a, gotcolor.r, gotcolor.g, gotcolor.b, gotcolor.a);
=20
+#define expect_mat(expectedmat,gotmat)\
+{ \
+ int i,j,equal=3D1; \
+ for (i=3D0; i<4; i++)\
+ {\
+ for (j=3D0; j<4; j++)\
+ {\
+ if (fabs(expectedmat.m[i][j]-gotmat.m[i][j])>admitted_error)\
+ {\
+ equal=3D0;\
+ }\
+ }\
+ }\
+ ok(equal, "Expected matrix=3D\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f=
\n %f,%f,%f,%f\n)\n\n" \
+ "Got matrix=3D\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,=
%f)\n", \
+ expectedmat.m[0][0],expectedmat.m[0][1],expectedmat.m[0][2],expected=
mat.m[0][3], \
+ expectedmat.m[1][0],expectedmat.m[1][1],expectedmat.m[1][2],expected=
mat.m[1][3], \
+ expectedmat.m[2][0],expectedmat.m[2][1],expectedmat.m[2][2],expected=
mat.m[2][3], \
+ expectedmat.m[3][0],expectedmat.m[3][1],expectedmat.m[3][2],expected=
mat.m[3][3], \
+ gotmat.m[0][0],gotmat.m[0][1],gotmat.m[0][2],gotmat.m[0][3], \
+ gotmat.m[1][0],gotmat.m[1][1],gotmat.m[1][2],gotmat.m[1][3], \
+ gotmat.m[2][0],gotmat.m[2][1],gotmat.m[2][2],gotmat.m[2][3], \
+ gotmat.m[3][0],gotmat.m[3][1],gotmat.m[3][2],gotmat.m[3][3]); \
+}
+
#define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<adm=
itted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector=
=3D (%f, %f)\n , Got Vector=3D (%f, %f)\n", expectedvec.x, expectedvec.y, go=
tvec.x, gotvec.y);
=20
#define expect_vec3(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<ad=
mitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expected=
vec.z-gotvec.z)<admitted_error),"Expected Vector=3D (%f, %f, %f)\n , Got Vec=
tor=3D (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.=
x, gotvec.y, gotvec.z);
@@ -123,7 +148,7 @@ static void D3DXColorTest(void)
=20
static void D3DXMatrixTest(void)
{
- D3DXMATRIX mat;
+ D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
BOOL expected, got;
FLOAT expectedfloat, gotfloat;
=20
@@ -134,6 +159,13 @@ static void D3DXMatrixTest(void)
U(mat).m[0][0] =3D 10.0f; U(mat).m[1][1] =3D 20.0f; U(mat).m[2][2] =3D =
30.0f;
U(mat).m[3][3] =3D -40.0f;
=20
+ mat2.m[0][0] =3D 1.0f; mat2.m[1][0] =3D 2.0f; mat2.m[2][0] =3D 3.0f;
+ mat2.m[3][0] =3D 4.0f; mat2.m[0][1] =3D 5.0f; mat2.m[1][1] =3D 6.0f;
+ mat2.m[2][1] =3D 7.0f; mat2.m[3][1] =3D 8.0f; mat2.m[0][2] =3D -8.0f;
+ mat2.m[1][2] =3D -7.0f; mat2.m[2][2] =3D -6.0f; mat2.m[3][2] =3D -5.0f;
+ mat2.m[0][3] =3D -4.0f; mat2.m[1][3] =3D -3.0f; mat2.m[2][3] =3D -2.0f;
+ mat2.m[3][3] =3D -1.0f;
+
/*____________D3DXMatrixfDeterminant_____________*/
expectedfloat =3D -147888.0f;
gotfloat =3D D3DXMatrixfDeterminant(&mat);
@@ -141,20 +173,28 @@ static void D3DXMatrixTest(void)
=20
/*____________D3DXMatrixIsIdentity______________*/
expected =3D FALSE;
- got =3D D3DXMatrixIsIdentity(&mat);
+ got =3D D3DXMatrixIsIdentity(&mat3);
ok(expected =3D=3D got, "Expected : %d, Got : %d\n", expected, got);
- D3DXMatrixIdentity(&mat);
+ D3DXMatrixIdentity(&mat3);
expected =3D TRUE;
- got =3D D3DXMatrixIsIdentity(&mat);
+ got =3D D3DXMatrixIsIdentity(&mat3);
ok(expected =3D=3D got, "Expected : %d, Got : %d\n", expected, got);
- U(mat).m[0][0] =3D 0.000009f;
+ U(mat3).m[0][0] =3D 0.000009f;
expected =3D FALSE;
- got =3D D3DXMatrixIsIdentity(&mat);
+ got =3D D3DXMatrixIsIdentity(&mat3);
ok(expected =3D=3D got, "Expected : %d, Got : %d\n", expected, got);
/* Test the NULL case */
expected =3D FALSE;
got =3D D3DXMatrixIsIdentity(NULL);
ok(expected =3D=3D got, "Expected : %d, Got : %d\n", expected, got);
+
+/*____________D3DXMatrixMultiply______________*/
+ expectedmat.m[0][0] =3D 73.0f; expectedmat.m[0][1] =3D 193.0f; expected=
mat.m[0][2] =3D -197.0f; expectedmat.m[0][3] =3D -77.0f;
+ expectedmat.m[1][0] =3D 231.0f; expectedmat.m[1][1] =3D 551.0f; expecte=
dmat.m[1][2] =3D -489.0f; expectedmat.m[1][3] =3D -169.0;
+ expectedmat.m[2][0] =3D 239.0f; expectedmat.m[2][1] =3D 523.0f; expecte=
dmat.m[2][2] =3D -400.0f; expectedmat.m[2][3] =3D -116.0f;
+ expectedmat.m[3][0] =3D -164.0f; expectedmat.m[3][1] =3D -320.0f; expec=
tedmat.m[3][2] =3D 187.0f; expectedmat.m[3][3] =3D 31.0f;
+ D3DXMatrixMultiply(&gotmat,&mat,&mat2);
+ expect_mat(expectedmat,gotmat);
}
=20
static void D3DXPlaneTest(void)
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 9dcf0a4..94a9cfd 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -59,6 +59,7 @@ typedef struct D3DXCOLOR
} D3DXCOLOR, *LPD3DXCOLOR;
=20
FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm);
+D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *p=
m1, CONST D3DXMATRIX *pm2);
=20
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq);
=20
--=20
1.5.3.2
--=_4vjp1d9uuois--
More information about the wine-patches
mailing list