[PATCH] Implement D3DXMatrixTransformation with a test
David Adam
David.Adam at math.cnrs.fr
Wed Nov 21 10:23:13 CST 2007
---
dlls/d3dx8/d3dx8.spec | 2 +-
dlls/d3dx8/math.c | 80 ++++++++++++++++++++++++++++++++++++++++++++=
+++
dlls/d3dx8/tests/math.c | 16 ++++++++-
include/d3dx8math.h | 1 +
4 files changed, 96 insertions(+), 3 deletions(-)
diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 52fa008..28b772e 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -33,7 +33,7 @@
@ stdcall D3DXMatrixRotationAxis(ptr ptr long)
@ stdcall D3DXMatrixRotationQuaternion(ptr ptr)
@ stdcall D3DXMatrixRotationYawPitchRoll(ptr long long long)
-@ stub D3DXMatrixTransformation
+@ stdcall D3DXMatrixTransformation(ptr ptr ptr ptr ptr ptr ptr)
@ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr)
@ stdcall D3DXMatrixLookAtRH(ptr ptr ptr ptr)
@ stdcall D3DXMatrixLookAtLH(ptr ptr ptr ptr)
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 9f7522e..04072bf 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -480,6 +480,86 @@ D3DXMATRIX* WINAPI D3DXMatrixShadow(D3DXMATRIX *pout, C=
ONST D3DXVECTOR4 *plight,
return pout;
}
=20
+D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *p=
scalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *ps=
caling, CONST D3DXVECTOR3 *protationcenter, CONST D3DXQUATERNION *protation,=
CONST D3DXVECTOR3 *ptranslation)
+{
+ D3DXMATRIX m1, m2, m3, m4, m5, m6, m7, p1, p2, p3, p4, p5;
+ D3DXQUATERNION prc;
+ D3DXVECTOR3 psc, pt;
+
+ if ( !pscalingcenter )
+ {
+ psc.x =3D 0.0f;
+ psc.y =3D 0.0f;
+ psc.z =3D 0.0f;
+ }
+ else
+ {
+ psc.x =3D pscalingcenter->x;
+ psc.y =3D pscalingcenter->y;
+ psc.z =3D pscalingcenter->z;
+ }
+ if ( !protationcenter )
+ {
+ prc.x =3D 0.0f;
+ prc.y =3D 0.0f;
+ prc.z =3D 0.0f;
+ }
+ else
+ {
+ prc.x =3D protationcenter->x;
+ prc.y =3D protationcenter->y;
+ prc.z =3D protationcenter->z;
+ }
+ if ( !ptranslation )
+ {
+ pt.x =3D 0.0f;
+ pt.y =3D 0.0f;
+ pt.z =3D 0.0f;
+ }
+ else
+ {
+ pt.x =3D ptranslation->x;
+ pt.y =3D ptranslation->y;
+ pt.z =3D ptranslation->z;
+ }
+ D3DXMatrixTranslation(&m1, -psc.x, -psc.y, -psc.z);
+ if ( !pscalingrotation )
+ {
+ D3DXMatrixIdentity(&m2);
+ D3DXMatrixIdentity(&m4);
+ }
+ else
+ {
+ D3DXMatrixRotationQuaternion(&m4, pscalingrotation);
+ D3DXMatrixInverse(&m2, NULL, &m4);
+ }
+ if ( !pscaling )
+ {
+ D3DXMatrixIdentity(&m3);
+ }
+ else
+ {
+ D3DXMatrixScaling(&m3, pscaling->x, pscaling->y, pscaling->z);
+ }
+ if ( !protation )
+ {
+ D3DXMatrixIdentity(&m6);
+ }
+ else
+ {
+ D3DXMatrixRotationQuaternion(&m6, protation);
+ }
+ D3DXMatrixTranslation(&m5, psc.x - prc.x, psc.y - prc.y, psc.z - prc.=
z);
+ D3DXMatrixTranslation(&m7, prc.x + pt.x, prc.y + pt.y, prc.z + pt.z);
+ D3DXMatrixMultiply(&p1, &m1, &m2);
+ D3DXMatrixMultiply(&p2, &p1, &m3);
+ D3DXMatrixMultiply(&p3, &p2, &m4);
+ D3DXMatrixMultiply(&p4, &p3, &m5);
+ D3DXMatrixMultiply(&p5, &p4, &m6);
+ D3DXMatrixMultiply(pout, &p5, &m7);
+ return pout;
+}
+
D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pout, FLOAT x, FLOAT y=
, FLOAT z)
{
D3DXMatrixIdentity(pout);
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index b689fb7..6fb5736 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -164,8 +164,8 @@ static void D3DXMatrixTest(void)
D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
LPD3DXMATRIX funcpointer;
D3DXPLANE plane;
- D3DXQUATERNION q;
- D3DXVECTOR3 at, axis, eye;
+ D3DXQUATERNION q, r;
+ D3DXVECTOR3 at, axis, eye, last, scaling;
D3DXVECTOR4 light;
BOOL expected, got;
FLOAT angle, determinant, expectedfloat, gotfloat;
@@ -187,10 +187,13 @@ static void D3DXMatrixTest(void)
plane.a =3D -3.0f; plane.b =3D -1.0f; plane.c =3D 4.0f; plane.d =3D 7.0=
f;
=20
q.x =3D 1.0f; q.y =3D -4.0f; q.z =3D7.0f; q.w =3D -11.0f;
+ r.x =3D 0.87f; r.y =3D 0.65f; r.z =3D0.43f; r.w=3D 0.21f;
=20
at.x =3D -2.0f; at.y =3D 13.0f; at.z =3D -9.0f;
axis.x =3D 1.0f; axis.y =3D -3.0f; axis.z =3D 7.0f;
eye.x =3D 8.0f; eye.y =3D -5.0f; eye.z =3D 5.75f;
+ last.x =3D 9.7f; last.y =3D -8.6; last.z =3D 1.3f;
+ scaling.x =3D 0.03f; scaling.y =3D0.05f; scaling.z =3D 0.06f;
=20
light.x =3D 9.6f; light.y =3D 8.5f; light.z =3D 7.4; light.w =3D 6.3;
=20
@@ -364,6 +367,7 @@ static void D3DXMatrixTest(void)
U(expectedmat).m[3][0] =3D 1.615385f; U(expectedmat).m[3][1] =3D 0.5384=
62f; U(expectedmat).m[3][2] =3D -2.153846f; U(expectedmat).m[3][3] =3D 1.0f;
D3DXMatrixReflect(&gotmat,&plane);
expect_mat(expectedmat,gotmat);
+
/*____________D3DXMatrixRotationAxis_____*/
U(expectedmat).m[0][0] =3D 0.508475f; U(expectedmat).m[0][1] =3D 0.7638=
05f; U(expectedmat).m[0][2] =3D 0.397563f; U(expectedmat).m[0][3] =3D 0.0f;
U(expectedmat).m[1][0] =3D -0.814652f; U(expectedmat).m[1][1] =3D 0.576=
271f; U(expectedmat).m[1][2] =3D -0.065219f; U(expectedmat).m[1][3] =3D 0.0f=
;
@@ -428,6 +432,14 @@ static void D3DXMatrixTest(void)
D3DXMatrixShadow(&gotmat,&light,&plane);
expect_mat(expectedmat,gotmat);
=20
+/*____________D3DXMatrixTransformation______________*/
+ U(expectedmat).m[0][0] =3D -0.2148f; U(expectedmat).m[0][1] =3D 1.3116f=
; U(expectedmat).m[0][2] =3D 0.4752f; U(expectedmat).m[0][3] =3D 0.0f;
+ U(expectedmat).m[1][0] =3D 0.9504f; U(expectedmat).m[1][1] =3D -0.8836f=
; U(expectedmat).m[1][2] =3D 0.9244f; U(expectedmat).m[1][3] =3D 0.0f;
+ U(expectedmat).m[2][0] =3D 1.0212f; U(expectedmat).m[2][1] =3D 0.1936f;=
U(expectedmat).m[2][2] =3D -1.3588f; U(expectedmat).m[2][3] =3D 0.0f;
+ U(expectedmat).m[3][0] =3D 18.2985f; U(expectedmat).m[3][1] =3D -29.624=
001f; U(expectedmat).m[3][2] =3D 15.683499f; U(expectedmat).m[3][3] =3D 1.0f=
;
+ D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
+ expect_mat(expectedmat,gotmat);
+
/*____________D3DXMatrixTranslation______________*/
U(expectedmat).m[0][0] =3D 1.0f; U(expectedmat).m[0][1] =3D 0.0f; U(exp=
ectedmat).m[0][2] =3D 0.0f; U(expectedmat).m[0][3] =3D 0.0f;
U(expectedmat).m[1][0] =3D 0.0; U(expectedmat).m[1][1] =3D 1.0f; U(expe=
ctedmat).m[1][2] =3D 0.0f; U(expectedmat).m[1][3] =3D 0.0f;
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index a799dee..4ea4d7d 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -293,6 +293,7 @@ D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll(D3DXMA=
TRIX *pout, FLOAT yaw, F
D3DXMATRIX* WINAPI D3DXMatrixRotationZ(D3DXMATRIX *pout, FLOAT angle);
D3DXMATRIX* WINAPI D3DXMatrixScaling(D3DXMATRIX *pout, FLOAT sx, FLOAT sy, =
FLOAT sz);
D3DXMATRIX* WINAPI D3DXMatrixShadow(D3DXMATRIX *pout, CONST D3DXVECTOR4 *pl=
ight, CONST D3DXPLANE *pPlane);
+D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *p=
scalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *ps=
caling, CONST D3DXVECTOR3 *protationcenter, CONST D3DXQUATERNION *protation,=
CONST D3DXVECTOR3 *ptranslation);
D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pout, FLOAT x, FLOAT y=
, FLOAT z);
D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout, CONST D3DXMATRIX *=
pm);
=20
--=20
1.5.3.2
--=_6wbl3w7x8ygw--
More information about the wine-patches
mailing list