David Adam : d3dx8: Implement D3DXMatrixTransformation2D.

Alexandre Julliard julliard at winehq.org
Thu Nov 13 08:51:46 CST 2008


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

Author: David Adam <david.adam.cnrs at gmail.com>
Date:   Wed Nov 12 19:16:30 2008 +0100

d3dx8: Implement D3DXMatrixTransformation2D.

---

 dlls/d3dx9_36/d3dx9_36.spec |    2 +-
 dlls/d3dx9_36/math.c        |   80 +++++++++++++++++++++++++++++++++++++++++++
 dlls/d3dx9_36/tests/math.c  |   79 ++++++++++++++++++++++++++++++++++++++++++
 include/d3dx9math.h         |    1 +
 4 files changed, 161 insertions(+), 1 deletions(-)

diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec
index 9058dd7..d7fba36 100644
--- a/dlls/d3dx9_36/d3dx9_36.spec
+++ b/dlls/d3dx9_36/d3dx9_36.spec
@@ -225,7 +225,7 @@
 @ stdcall D3DXMatrixScaling(ptr long long long) d3dx8.D3DXMatrixScaling
 @ stdcall D3DXMatrixShadow(ptr ptr ptr) d3dx8.D3DXMatrixShadow
 @ stdcall D3DXMatrixTransformation(ptr ptr ptr ptr ptr ptr ptr) d3dx8.D3DXMatrixTransformation
-@ stub D3DXMatrixTransformation2D
+@ stdcall D3DXMatrixTransformation2D(ptr ptr long ptr ptr long ptr)
 @ stdcall D3DXMatrixTranslation(ptr long long long) d3dx8.D3DXMatrixTranslation
 @ stdcall D3DXMatrixTranspose(ptr ptr) d3dx8.D3DXMatrixTranspose
 @ stub D3DXOptimizeFaces
diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c
index b5cdde2..a00ffc5 100644
--- a/dlls/d3dx9_36/math.c
+++ b/dlls/d3dx9_36/math.c
@@ -1,6 +1,7 @@
 /*
  * Mathematical operations specific to D3DX9.
  *
+ * Copyright (C) 2008 David Adam
  * Copyright (C) 2008 Philip Nilsson
  *
  * This library is free software; you can redistribute it and/or
@@ -130,6 +131,85 @@ HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutr
 }
 
 /*************************************************************************
+ * D3DXMatrixTransformation2D
+ */
+D3DXMATRIX* WINAPI D3DXMatrixTransformation2D(
+    D3DXMATRIX *pout, CONST D3DXVECTOR2 *pscalingcenter,
+    FLOAT scalingrotation, CONST D3DXVECTOR2 *pscaling,
+    CONST D3DXVECTOR2 *protationcenter, FLOAT rotation,
+    CONST D3DXVECTOR2 *ptranslation)
+{
+    D3DXQUATERNION rot, sca_rot;
+    D3DXVECTOR3 rot_center, sca, sca_center, trans;
+
+    if ( pscalingcenter )
+    {
+        sca_center.x=pscalingcenter->x;
+        sca_center.y=pscalingcenter->y;
+        sca_center.z=0.0f;
+    }
+    else
+    {
+        sca_center.x=0.0f;
+        sca_center.y=0.0f;
+        sca_center.z=0.0f;
+    }
+
+    if ( pscaling )
+    {
+        sca.x=pscaling->x;
+        sca.y=pscaling->y;
+        sca.z=0.0f;
+    }
+    else
+    {
+        sca.x=0.0f;
+        sca.y=0.0f;
+        sca.z=0.0f;
+    }
+
+    if ( protationcenter )
+    {
+        rot_center.x=protationcenter->x;
+        rot_center.y=protationcenter->y;
+        rot_center.z=0.0f;
+    }
+    else
+    {
+        rot_center.x=0.0f;
+        rot_center.y=0.0f;
+        rot_center.z=0.0f;
+    }
+
+    if ( ptranslation )
+    {
+        trans.x=ptranslation->x;
+        trans.y=ptranslation->y;
+        trans.z=0.0f;
+    }
+    else
+    {
+        trans.x=0.0f;
+        trans.y=0.0f;
+        trans.z=0.0f;
+    }
+
+    rot.w=cos(rotation/2.0f);
+    rot.x=0.0f;
+    rot.y=0.0f;
+    rot.z=sin(rotation/2.0f);
+
+    sca_rot.w=cos(scalingrotation/2.0f);
+    sca_rot.x=0.0f;
+    sca_rot.y=0.0f;
+    sca_rot.z=sin(scalingrotation/2.0f);
+
+    D3DXMatrixTransformation(pout, &sca_center, &sca_rot, &sca, &rot_center, &rot, &trans);
+
+    return pout;
+}
+
+/*************************************************************************
  * D3DXPlaneTransformArray
  */
 D3DXPLANE* WINAPI D3DXPlaneTransformArray(
diff --git a/dlls/d3dx9_36/tests/math.c b/dlls/d3dx9_36/tests/math.c
index 2930d34..cc71b33 100644
--- a/dlls/d3dx9_36/tests/math.c
+++ b/dlls/d3dx9_36/tests/math.c
@@ -1,4 +1,5 @@
 /*
+ * Copyright 2008 David Adam
  * Copyright 2008 Philip Nilsson
  *
  * This library is free software; you can redistribute it and/or
@@ -584,6 +585,83 @@ static void test_Matrix_Decompose(void)
     ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %x\n", hr);
 }
 
+static void test_Matrix_Transformation2D(void)
+{
+    D3DXMATRIX exp_mat, got_mat;
+    D3DXVECTOR2 rot_center, sca, sca_center, trans;
+    FLOAT rot, sca_rot;
+
+    rot_center.x = 3.0f;
+    rot_center.y = 4.0f;
+
+    sca.x = 12.0f;
+    sca.y = -3.0f;
+
+    sca_center.x = 9.0f;
+    sca_center.y = -5.0f;
+
+    trans.x = -6.0f;
+    trans.y = 7.0f;
+
+    rot = D3DX_PI/3.0f;
+
+    sca_rot = 5.0f*D3DX_PI/4.0f;
+
+    exp_mat.m[0][0] = -4.245192f;
+    exp_mat.m[1][0] = -0.147116f;
+    exp_mat.m[2][0] = 0.0f;
+    exp_mat.m[3][0] = 45.265373f;
+    exp_mat.m[0][1] = 7.647113f;
+    exp_mat.m[1][1] = 8.745192f;
+    exp_mat.m[2][1] = 0.0f;
+    exp_mat.m[3][1] = -13.401899f;
+    exp_mat.m[0][2] = 0.0f;
+    exp_mat.m[1][2] = 0.0f;
+    exp_mat.m[2][2] = 0.0f;
+    exp_mat.m[3][2] = 0.0f;
+    exp_mat.m[0][3] = 0.0f;
+    exp_mat.m[1][3] = 0.0f;
+    exp_mat.m[2][3] = 0.0f;
+    exp_mat.m[3][3] = 1.0f;
+
+    D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, &sca, &rot_center, rot, &trans);
+
+    expect_mat(&exp_mat, &got_mat);
+
+/*_________*/
+
+    sca_center.x = 9.0f;
+    sca_center.y = -5.0f;
+
+    trans.x = -6.0f;
+    trans.y = 7.0f;
+
+    rot = D3DX_PI/3.0f;
+
+    sca_rot = 5.0f*D3DX_PI/4.0f;
+
+    exp_mat.m[0][0] = 0.0f;
+    exp_mat.m[1][0] = 0.0f;
+    exp_mat.m[2][0] = 0.0f;
+    exp_mat.m[3][0] = 2.830127f;
+    exp_mat.m[0][1] = 0.0f;
+    exp_mat.m[1][1] = 0.0f;
+    exp_mat.m[2][1] = 0.0f;
+    exp_mat.m[3][1] = 12.294229f;
+    exp_mat.m[0][2] = 0.0f;
+    exp_mat.m[1][2] = 0.0f;
+    exp_mat.m[2][2] = 0.0f;
+    exp_mat.m[3][2] = 0.0f;
+    exp_mat.m[0][3] = 0.0f;
+    exp_mat.m[1][3] = 0.0f;
+    exp_mat.m[2][3] = 0.0f;
+    exp_mat.m[3][3] = 1.0f;
+
+    D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, NULL, NULL, rot, &trans);
+
+    expect_mat(&exp_mat, &got_mat);
+}
+
 static void test_D3DXVec_Array(void)
 {
     unsigned int i;
@@ -725,5 +803,6 @@ START_TEST(math)
 {
     test_Matrix_AffineTransformation2D();
     test_Matrix_Decompose();
+    test_Matrix_Transformation2D();
     test_D3DXVec_Array();
 }
diff --git a/include/d3dx9math.h b/include/d3dx9math.h
index 9992919..83b8749 100644
--- a/include/d3dx9math.h
+++ b/include/d3dx9math.h
@@ -296,6 +296,7 @@ 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* WINAPI D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *pscalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *pscaling, CONST D3DXVECTOR3 *protationcenter, CONST D3DXQUATERNION *protation, CONST D3DXVECTOR3 *ptranslation);
+D3DXMATRIX* WINAPI D3DXMatrixTransformation2D(D3DXMATRIX *pout, CONST D3DXVECTOR2 *pscalingcenter, FLOAT scalingrotation, CONST D3DXVECTOR2 *pscaling, CONST D3DXVECTOR2 *protationcenter, FLOAT rotation, CONST D3DXVECTOR2 *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