David Adam : d3dx8: Implement D3DXMatrixAffine Transformation.

Alexandre Julliard julliard at winehq.org
Tue Nov 13 08:34:45 CST 2007


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

Author: David Adam <David.Adam at math.cnrs.fr>
Date:   Mon Nov 12 11:27:13 2007 +0100

d3dx8: Implement D3DXMatrixAffine Transformation.

---

 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);
 
 /*_________________D3DXMatrix____________________*/
 
+D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, float scaling, 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, -rotationcenter->z);
+     D3DXMatrixTranslation(&m4, rotationcenter->x, rotationcenter->y, rotationcenter->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 @@
 
 #include "wine/test.h"
 
-#define admitted_error 0.00001f
+#define admitted_error 0.0001f
 
 #define expect_color(expectedcolor,gotcolor) ok((fabs(expectedcolor.r-gotcolor.r)<admitted_error)&&(fabs(expectedcolor.g-gotcolor.g)<admitted_error)&&(fabs(expectedcolor.b-gotcolor.b)<admitted_error)&&(fabs(expectedcolor.a-gotcolor.a)<admitted_error),"Expected Color= (%f, %f, %f, %f)\n , Got Color= (%f, %f, %f, %f)\n", expectedcolor.r, expectedcolor.g, expectedcolor.b, expectedcolor.a, gotcolor.r, gotcolor.g, gotcolor.b, gotcolor.a);
 
@@ -177,6 +177,21 @@ static void D3DXMatrixTest(void)
 
     angle = D3DX_PI/3.0f;
 
+/*____________D3DXMatrixAffineTransformation______*/
+    expectedmat.m[0][0] = -459.239990f; expectedmat.m[0][1] = -576.719971f; expectedmat.m[0][2] = -263.440002f; expectedmat.m[0][3] = 0.0f;
+    expectedmat.m[1][0] = 519.760010f; expectedmat.m[1][1] = -352.440002f; expectedmat.m[1][2] = -277.679993f; expectedmat.m[1][3] = 0.0f;
+    expectedmat.m[2][0] = 363.119995f; expectedmat.m[2][1] = -121.040001f; expectedmat.m[2][2] = -117.479996f; expectedmat.m[2][3] = 0.0f;
+    expectedmat.m[3][0] = -1239.0f; expectedmat.m[3][1] = 667.0f; expectedmat.m[3][2] = 567.0f; expectedmat.m[3][3] = 1.0f;
+    D3DXMatrixAffineTransformation(&gotmat,3.56f,&at,&q,&axis);
+    expect_mat(expectedmat,gotmat);
+/* Test the NULL case */
+    expectedmat.m[0][0] = -459.239990f; expectedmat.m[0][1] = -576.719971f; expectedmat.m[0][2] = -263.440002f; expectedmat.m[0][3] = 0.0f;
+    expectedmat.m[1][0] = 519.760010f; expectedmat.m[1][1] = -352.440002f; expectedmat.m[1][2] = -277.679993f; expectedmat.m[1][3] = 0.0f;
+    expectedmat.m[2][0] = 363.119995f; expectedmat.m[2][1] = -121.040001f; expectedmat.m[2][2] = -117.479996f; expectedmat.m[2][3] = 0.0f;
+    expectedmat.m[3][0] = 1.0f; expectedmat.m[3][1] = -3.0f; expectedmat.m[3][2] = 7.0f; expectedmat.m[3][3] = 1.0f;
+    D3DXMatrixAffineTransformation(&gotmat,3.56f,NULL,&q,&axis);
+    expect_mat(expectedmat,gotmat);
+
 /*____________D3DXMatrixfDeterminant_____________*/
     expectedfloat = -147888.0f;
     gotfloat = D3DXMatrixfDeterminant(&mat);
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 9916490..da0c8f3 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -259,6 +259,7 @@ typedef struct D3DXCOLOR
     FLOAT r, g, b, a;
 } D3DXCOLOR, *LPD3DXCOLOR;
 
+D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, float scaling, 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);




More information about the wine-cvs mailing list