[PATCH] Implement D3DXMatrixAffineTransformation with a test
David Adam
David.Adam at math.cnrs.fr
Mon Nov 12 04:27:13 CST 2007
---
dlls/d3dx8/d3dx8.spec | 2 +-
dlls/d3dx8/math.c | 38 ++++++++++++++++++++++++++++++++++++++
dlls/d3dx8/tests/math.c | 17 ++++++++++++++++-
include/d3dx8math.h | 1 +
4 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 82c9586..7578597 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -34,7 +34,7 @@
@ stdcall D3DXMatrixRotationQuaternion(ptr ptr)
@ stdcall D3DXMatrixRotationYawPitchRoll(ptr long long long)
@ stub D3DXMatrixTransformation
-@ stub D3DXMatrixAffineTransformation
+@ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr)
@ stdcall D3DXMatrixLookAtRH(ptr ptr ptr ptr)
@ stdcall D3DXMatrixLookAtLH(ptr ptr ptr ptr)
@ stdcall D3DXMatrixPerspectiveRH(ptr long long long long)
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 7f96583..15276fa 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -34,6 +34,44 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3dx8);
=20
/*_________________D3DXMatrix____________________*/
=20
+D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, float s=
caling, D3DXVECTOR3 *rotationcenter, D3DXQUATERNION *rotation, D3DXVECTOR3 *=
translation)
+{
+ D3DXMATRIX m1, m2, m3, m4, m5, p1, p2, p3;
+
+ D3DXMatrixScaling(&m1, scaling, scaling, scaling);
+ if ( !rotationcenter )
+ {
+ D3DXMatrixIdentity(&m2);
+ D3DXMatrixIdentity(&m4);
+ }
+ else
+ {
+ D3DXMatrixTranslation(&m2, -rotationcenter->x, -rotationcenter->y, -ro=
tationcenter->z);
+ D3DXMatrixTranslation(&m4, rotationcenter->x, rotationcenter->y, rotat=
ioncenter->z);
+ }
+ if ( !rotation )
+ {
+ D3DXMatrixIdentity(&m3);
+ }
+ else
+ {
+ D3DXMatrixRotationQuaternion(&m3, rotation);
+ }
+ if ( !translation )
+ {
+ D3DXMatrixIdentity(&m5);
+ }
+ else
+ {
+ D3DXMatrixTranslation(&m5, translation->x, translation->y, translation=
->z);
+ }
+ D3DXMatrixMultiply(&p1, &m1, &m2);
+ D3DXMatrixMultiply(&p2, &p1, &m3);
+ D3DXMatrixMultiply(&p3, &p2, &m4);
+ D3DXMatrixMultiply(pout, &p3, &m5);
+ return pout;
+}
+
FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm)
{
D3DXVECTOR4 minor, v1, v2, v3;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 65a0e5a..9e862ab 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -21,7 +21,7 @@
=20
#include "wine/test.h"
=20
-#define admitted_error 0.00001f
+#define admitted_error 0.0001f
=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
@@ -177,6 +177,21 @@ static void D3DXMatrixTest(void)
=20
angle =3D D3DX_PI/3.0f;
=20
+/*____________D3DXMatrixAffineTransformation______*/
+ expectedmat.m[0][0] =3D -459.239990f; expectedmat.m[0][1] =3D -576.7199=
71f; expectedmat.m[0][2] =3D -263.440002f; expectedmat.m[0][3] =3D 0.0f;
+ expectedmat.m[1][0] =3D 519.760010f; expectedmat.m[1][1] =3D -352.44000=
2f; expectedmat.m[1][2] =3D -277.679993f; expectedmat.m[1][3] =3D 0.0f;
+ expectedmat.m[2][0] =3D 363.119995f; expectedmat.m[2][1] =3D -121.04000=
1f; expectedmat.m[2][2] =3D -117.479996f; expectedmat.m[2][3] =3D 0.0f;
+ expectedmat.m[3][0] =3D -1239.0f; expectedmat.m[3][1] =3D 667.0f; expec=
tedmat.m[3][2] =3D 567.0f; expectedmat.m[3][3] =3D 1.0f;
+ D3DXMatrixAffineTransformation(&gotmat,3.56f,&at,&q,&axis);
+ expect_mat(expectedmat,gotmat);
+/* Test the NULL case */
+ expectedmat.m[0][0] =3D -459.239990f; expectedmat.m[0][1] =3D -576.7199=
71f; expectedmat.m[0][2] =3D -263.440002f; expectedmat.m[0][3] =3D 0.0f;
+ expectedmat.m[1][0] =3D 519.760010f; expectedmat.m[1][1] =3D -352.44000=
2f; expectedmat.m[1][2] =3D -277.679993f; expectedmat.m[1][3] =3D 0.0f;
+ expectedmat.m[2][0] =3D 363.119995f; expectedmat.m[2][1] =3D -121.04000=
1f; expectedmat.m[2][2] =3D -117.479996f; expectedmat.m[2][3] =3D 0.0f;
+ expectedmat.m[3][0] =3D 1.0f; expectedmat.m[3][1] =3D -3.0f; expectedma=
t.m[3][2] =3D 7.0f; expectedmat.m[3][3] =3D 1.0f;
+ D3DXMatrixAffineTransformation(&gotmat,3.56f,NULL,&q,&axis);
+ expect_mat(expectedmat,gotmat);
+
/*____________D3DXMatrixfDeterminant_____________*/
expectedfloat =3D -147888.0f;
gotfloat =3D D3DXMatrixfDeterminant(&mat);
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index c422565..5ccfd9b 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -58,6 +58,7 @@ typedef struct D3DXCOLOR
FLOAT r, g, b, a;
} D3DXCOLOR, *LPD3DXCOLOR;
=20
+D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, float s=
caling, D3DXVECTOR3 *rotationcenter, D3DXQUATERNION *rotation, D3DXVECTOR3 *=
translation);
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);
--=20
1.5.3.2
--=_2x3tnweuqdq8--
More information about the wine-patches
mailing list