diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec index a2dab96f826..2e68ba2e813 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 deb52d2dd66..adee217beeb 100644 --- a/dlls/d3dx9_36/math.c +++ b/dlls/d3dx9_36/math.c @@ -26,6 +26,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 */ diff --git a/include/d3dx9math.h b/include/d3dx9math.h index 9801504a34c..54e7762fbe2 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);