Luis C. Busquets Pérez : d3dx9: Implement D3DXMatrixDecompose.

Alexandre Julliard julliard at winehq.org
Fri Sep 12 07:01:50 CDT 2008


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

Author: Luis C. Busquets Pérez <luiscar2001 at yahoo.es>
Date:   Thu Sep 11 20:14:38 2008 +0200

d3dx9: Implement D3DXMatrixDecompose.

---

 dlls/d3dx9_36/d3dx9_36.spec |    2 +-
 dlls/d3dx9_36/math.c        |   54 +++++++++++++++++++++++++++++++++++++++++++
 include/d3dx9math.h         |    1 +
 3 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec
index a2dab96..2e68ba2 100644
--- a/dlls/d3dx9_36/d3dx9_36.spec
+++ b/dlls/d3dx9_36/d3dx9_36.spec
@@ -198,7 +198,7 @@
 @ stub D3DXLoadVolumeFromVolume
 @ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr) d3dx8.D3DXMatrixAffineTransformation
 @ stub D3DXMatrixAffineTransformation2D
-@ stub D3DXMatrixDecompose
+@ stdcall D3DXMatrixDecompose(ptr ptr ptr ptr)
 @ stdcall D3DXMatrixDeterminant(ptr) d3dx8.D3DXMatrixfDeterminant
 @ stdcall D3DXMatrixInverse(ptr ptr ptr) d3dx8.D3DXMatrixInverse
 @ stdcall D3DXMatrixLookAtLH(ptr ptr ptr ptr) d3dx8.D3DXMatrixLookAtLH
diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c
index deb52d2..adee217 100644
--- a/dlls/d3dx9_36/math.c
+++ b/dlls/d3dx9_36/math.c
@@ -27,6 +27,60 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
 
 /*************************************************************************
+ * D3DXMatrixDecompose
+ */
+HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, D3DXMATRIX *pm)
+{
+    D3DXMATRIX normalized;
+    D3DXVECTOR3 vec;
+
+    if (!pm)
+    {
+     return D3DERR_INVALIDCALL;
+    }
+
+    /*Compute the scaling part.*/
+    vec.x=pm->m[0][0];
+    vec.y=pm->m[0][1];
+    vec.z=pm->m[0][2];
+    poutscale->x=D3DXVec3Length(&vec);
+
+    vec.x=pm->m[1][0];
+    vec.y=pm->m[1][1];
+    vec.z=pm->m[1][2];
+    poutscale->y=D3DXVec3Length(&vec);
+
+    vec.x=pm->m[2][0];
+    vec.y=pm->m[2][1];
+    vec.z=pm->m[2][2];
+    poutscale->z=D3DXVec3Length(&vec);
+
+    /*Compute the translation part.*/
+    pouttranslation->x=pm->m[3][0];
+    pouttranslation->y=pm->m[3][1];
+    pouttranslation->z=pm->m[3][2];
+
+    /*Let's calculate the rotation now*/
+    if ( (poutscale->x == 0.0f) || (poutscale->y == 0.0f) || (poutscale->z == 0.0f) )
+    {
+     return D3DERR_INVALIDCALL;
+    }
+
+    normalized.m[0][0]=pm->m[0][0]/poutscale->x;
+    normalized.m[0][1]=pm->m[0][1]/poutscale->x;
+    normalized.m[0][2]=pm->m[0][2]/poutscale->x;
+    normalized.m[1][0]=pm->m[1][0]/poutscale->y;
+    normalized.m[1][1]=pm->m[1][1]/poutscale->y;
+    normalized.m[1][2]=pm->m[1][2]/poutscale->y;
+    normalized.m[2][0]=pm->m[2][0]/poutscale->z;
+    normalized.m[2][1]=pm->m[2][1]/poutscale->z;
+    normalized.m[2][2]=pm->m[2][2]/poutscale->z;
+
+    D3DXQuaternionRotationMatrix(poutrotation,&normalized);
+    return S_OK;
+}
+
+/*************************************************************************
  * D3DXPlaneTransformArray
  */
 D3DXPLANE* WINAPI D3DXPlaneTransformArray(
diff --git a/include/d3dx9math.h b/include/d3dx9math.h
index 9801504..54e7762 100644
--- a/include/d3dx9math.h
+++ b/include/d3dx9math.h
@@ -267,6 +267,7 @@ D3DXCOLOR* WINAPI D3DXColorAdjustContrast(D3DXCOLOR *pout, CONST D3DXCOLOR *pc,
 D3DXCOLOR* WINAPI D3DXColorAdjustSaturation(D3DXCOLOR *pout, CONST D3DXCOLOR *pc, FLOAT s);
 
 D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, float scaling, D3DXVECTOR3 *rotationcenter, D3DXQUATERNION *rotation, D3DXVECTOR3 *translation);
+HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, D3DXMATRIX *pm);
 FLOAT WINAPI D3DXMatrixDeterminant(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