[PATCH] Implement D3DXQuaternionInverse with a test

David Adam David.Adam at math.cnrs.fr
Mon Nov 19 09:18:09 CST 2007


---
 dlls/d3dx8/d3dx8.spec   |    2 +-
 dlls/d3dx8/math.c       |   26 +++++++++++++++++++++++++-
 dlls/d3dx8/tests/math.c |    9 +++++++++
 include/d3dx8math.h     |    3 ++-
 4 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index ea9d87f..ffa82a8 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -55,7 +55,7 @@
 @ stub D3DXQuaternionRotationYawPitchRoll
 @ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
 @ stdcall D3DXQuaternionNormalize(ptr ptr)
-@ stub D3DXQuaternionInverse
+@ stdcall D3DXQuaternionInverse(ptr ptr)
 @ stub D3DXQuaternionLn
 @ stub D3DXQuaternionExp
 @ stub D3DXQuaternionSlerp
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 242c2b1..99c4a42 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -581,7 +581,31 @@ D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, C=
ONST D3DXPLANE *pplane, C
=20
 /*_________________D3DXQUATERNION________________*/
=20
-D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION * pout, CONST =
D3DXQUATERNION *pq1, CONST D3DXQUATERNION * pq2)
+D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3=
DXQUATERNION *pq)
+{
+    D3DXQUATERNION temp;
+    FLOAT norm;
+
+    norm =3D D3DXQuaternionLengthSq(pq);
+    if ( !norm )
+    {
+     pout->x =3D 0.0f;
+     pout->y =3D 0.0f;
+     pout->z =3D 0.0f;
+     pout->w =3D 0.0f;
+    }
+    else
+    {
+    D3DXQuaternionConjugate(&temp, pq);
+    pout->x =3D temp.x / norm;
+    pout->y =3D temp.y / norm;
+    pout->z =3D temp.z / norm;
+    pout->w =3D temp.w / norm;
+    }
+    return pout;
+}
+
+D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D=
3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2)
 {
     pout->x =3D pq2->w * pq1->x + pq2->x * pq1->w + pq2->y * pq1->z - pq2->=
z * pq1->y;
     pout->y =3D pq2->w * pq1->y - pq2->x * pq1->z + pq2->y * pq1->w + pq2->=
z * pq1->x;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index fe9893b..399bf46 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -591,6 +591,15 @@ static void D3X8QuaternionTest(void)
     funcpointer =3D D3DXQuaternionIdentity(NULL);
     ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
=20
+/*_______________D3DXQuaternionInverse________________________*/
+    expectedquat.x =3D -1.0f/121.0f; expectedquat.y =3D -2.0f/121.0f; expec=
tedquat.z =3D -4.0f/121.0f; expectedquat.w =3D 10.0f/121.0f;
+    D3DXQuaternionInverse(&gotquat,&q);
+    expect_vec4(expectedquat,gotquat);
+    /* test the null quaternion */
+    expectedquat.x =3D 0.0f; expectedquat.y =3D 0.0f; expectedquat.z =3D 0.=
0f; expectedquat.w =3D 0.0f;
+    D3DXQuaternionInverse(&gotquat,&nul);
+    expect_vec4(expectedquat,gotquat);
+
 /*_______________D3DXQuaternionIsIdentity________________*/
     s.x =3D 0.0f; s.y =3D 0.0f; s.z =3D 0.0f; s.w =3D 1.0f;
     expectedbool =3D TRUE;
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 08c7c63..37641ed 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -302,7 +302,8 @@ D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *=
pout, CONST D3DXPLANE *p
 D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp);
 D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CONST D3DXPLANE *ppla=
ne, CONST D3DXMATRIX *pm);
=20
-D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION * pout, CONST =
D3DXQUATERNION *pq1, CONST D3DXQUATERNION * pq2);
+D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3=
DXQUATERNION *pq);
+D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D=
3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2);
 D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq);
=20
 D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR=
2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g);
--=20
1.5.3.2


--=_1qyhfljkrsw--



More information about the wine-patches mailing list