David Adam : d3dx8: Implement D3DXMatrixTransformation.

Alexandre Julliard julliard at winehq.org
Mon Nov 26 08:16:22 CST 2007


Module: wine
Branch: master
Commit: cf443380ba53cf6b32277d31a95c582654ca02db
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cf443380ba53cf6b32277d31a95c582654ca02db

Author: David Adam <David.Adam at math.cnrs.fr>
Date:   Wed Nov 21 17:23:13 2007 +0100

d3dx8: Implement D3DXMatrixTransformation.

---

 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, CONST D3DXVECTOR4 *plight,
     return pout;
 }
 
+D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *pscalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *pscaling, 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 = 0.0f;
+     psc.y = 0.0f;
+     psc.z = 0.0f;
+    }
+    else
+    {
+     psc.x = pscalingcenter->x;
+     psc.y = pscalingcenter->y;
+     psc.z = pscalingcenter->z;
+    }
+    if ( !protationcenter )
+    {
+     prc.x = 0.0f;
+     prc.y = 0.0f;
+     prc.z = 0.0f;
+    }
+    else
+    {
+     prc.x = protationcenter->x;
+     prc.y = protationcenter->y;
+     prc.z = protationcenter->z;
+    }
+    if ( !ptranslation )
+    {
+     pt.x = 0.0f;
+     pt.y = 0.0f;
+     pt.z = 0.0f;
+    }
+    else
+    {
+     pt.x = ptranslation->x;
+     pt.y = ptranslation->y;
+     pt.z = 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 = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
 
     q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
+    r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
 
     at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
     axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
     eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
+    last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
+    scaling.x = 0.03f; scaling.y =0.05f; scaling.z = 0.06f;
 
     light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
 
@@ -364,6 +367,7 @@ static void D3DXMatrixTest(void)
     U(expectedmat).m[3][0] = 1.615385f; U(expectedmat).m[3][1] = 0.538462f; U(expectedmat).m[3][2] = -2.153846f; U(expectedmat).m[3][3] = 1.0f;
     D3DXMatrixReflect(&gotmat,&plane);
     expect_mat(expectedmat,gotmat);
+
 /*____________D3DXMatrixRotationAxis_____*/
     U(expectedmat).m[0][0] = 0.508475f; U(expectedmat).m[0][1] = 0.763805f; U(expectedmat).m[0][2] = 0.397563f; U(expectedmat).m[0][3] = 0.0f;
     U(expectedmat).m[1][0] = -0.814652f; U(expectedmat).m[1][1] = 0.576271f; U(expectedmat).m[1][2] = -0.065219f; U(expectedmat).m[1][3] = 0.0f;
@@ -428,6 +432,14 @@ static void D3DXMatrixTest(void)
     D3DXMatrixShadow(&gotmat,&light,&plane);
     expect_mat(expectedmat,gotmat);
 
+/*____________D3DXMatrixTransformation______________*/
+    U(expectedmat).m[0][0] = -0.2148f; U(expectedmat).m[0][1] = 1.3116f; U(expectedmat).m[0][2] = 0.4752f; U(expectedmat).m[0][3] = 0.0f;
+    U(expectedmat).m[1][0] = 0.9504f; U(expectedmat).m[1][1] = -0.8836f; U(expectedmat).m[1][2] = 0.9244f; U(expectedmat).m[1][3] = 0.0f;
+    U(expectedmat).m[2][0] = 1.0212f; U(expectedmat).m[2][1] = 0.1936f; U(expectedmat).m[2][2] = -1.3588f; U(expectedmat).m[2][3] = 0.0f;
+    U(expectedmat).m[3][0] = 18.2985f; U(expectedmat).m[3][1] = -29.624001f; U(expectedmat).m[3][2] = 15.683499f; U(expectedmat).m[3][3] = 1.0f;
+    D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
+    expect_mat(expectedmat,gotmat);
+
 /*____________D3DXMatrixTranslation______________*/
     U(expectedmat).m[0][0] = 1.0f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
     U(expectedmat).m[1][0] = 0.0; U(expectedmat).m[1][1] = 1.0f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 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(D3DXMATRIX *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 *plight, CONST D3DXPLANE *pPlane);
+D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *pscalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *pscaling, 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);
 




More information about the wine-cvs mailing list