[PATCH] Partial implementation of D3DXQuaternionLn with a test

David Adam David.Adam at math.cnrs.fr
Wed Nov 21 07:34:32 CST 2007


---
 dlls/d3dx8/d3dx8.spec   |    2 +-
 dlls/d3dx8/math.c       |   28 ++++++++++++++++++++++++++++
 dlls/d3dx8/tests/math.c |   20 ++++++++++++++++++--
 include/d3dx8math.h     |    1 +
 4 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index d398791..d65dce0 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -56,7 +56,7 @@
 @ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
 @ stdcall D3DXQuaternionNormalize(ptr ptr)
 @ stdcall D3DXQuaternionInverse(ptr ptr)
-@ stub D3DXQuaternionLn
+@ stdcall D3DXQuaternionLn(ptr ptr)
 @ stub D3DXQuaternionExp
 @ stdcall D3DXQuaternionSlerp(ptr ptr ptr long)
 @ stdcall D3DXQuaternionSquad(ptr ptr ptr ptr ptr long)
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index aa8664f..19d6a9f 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -612,6 +612,34 @@ D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATER=
NION *pout, CONST D3DXQUA
     return pout;
 }
=20
+D3DXQUATERNION* WINAPI D3DXQuaternionLn(D3DXQUATERNION *pout, CONST D3DXQUA=
TERNION *pq)
+{
+    FLOAT norm, normvec, theta;
+
+    norm =3D D3DXQuaternionLengthSq(pq);
+    if ( norm > 1.0001f )
+    {
+     pout->x =3D pq->x;
+     pout->y =3D pq->y;
+     pout->z =3D pq->z;
+     pout->w =3D 0.0f;
+    }
+    else if( norm > 0.99999f)
+    {
+     normvec =3D sqrt( pq->x * pq->x + pq->y * pq->y + pq->z * pq->z );
+     theta =3D atan2(normvec, pq->w) / normvec;
+     pout->x =3D theta * pq->x;
+     pout->y =3D theta * pq->y;
+     pout->z =3D theta * pq->z;
+     pout->w =3D 0.0f;
+    }
+    else
+    {
+     FIXME("The quaternion (%f, %f, %f, %f) has a norm <1. This should not =
happen. Windows returns a result anyway. This case is not implemented yet.\n=
", pq->x, pq->y, pq->z, pq->w);
+    }
+    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;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 950bc5e..6dfe49c 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -553,7 +553,7 @@ static void D3DXPlaneTest(void)
 static void D3X8QuaternionTest(void)
 {
     D3DXMATRIX mat;
-    D3DXQUATERNION expectedquat, gotquat, Nq, nul, q, r, s, t, u;
+    D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, q, r, s, t, u;
     LPD3DXQUATERNION funcpointer;
     D3DXVECTOR3 axis, expectedvec;
     FLOAT angle, expected, got, scale, scale2;
@@ -643,6 +643,23 @@ static void D3X8QuaternionTest(void)
     got =3D D3DXQuaternionLengthSq(NULL);
     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
=20
+/*_______________D3DXQuaternionLn______________________________*/
+    expectedquat.x =3D 1.0f; expectedquat.y =3D 2.0f; expectedquat.z =3D 4.=
0f; expectedquat.w =3D 0.0f;
+    D3DXQuaternionLn(&gotquat,&q);
+    expect_vec4(expectedquat,gotquat);
+    expectedquat.x =3D -3.0f; expectedquat.y =3D 4.0f; expectedquat.z =3D -=
5.0f; expectedquat.w =3D 0.0f;
+    D3DXQuaternionLn(&gotquat,&r);
+    expect_vec4(expectedquat,gotquat);
+    Nq.x =3D 1.0f/11.0f; Nq.y =3D 2.0f/11.0f; Nq.z =3D 4.0f/11.0f; Nq.w=3D1=
0.0f/11.0f;
+    expectedquat.x =3D 0.093768f; expectedquat.y =3D 0.187536f; expectedqua=
t.z =3D 0.375073f; expectedquat.w =3D 0.0f;
+    D3DXQuaternionLn(&gotquat,&Nq);
+    expect_vec4(expectedquat,gotquat);
+    /* Test the cas where the norm of the quaternion is <1 */
+    Nq1.x =3D 0.2f; Nq1.y =3D 0.1f; Nq1.z =3D 0.3; Nq1.w=3D 0.9f;
+    expectedquat.x =3D 0.206945f; expectedquat.y =3D 0.103473f; expectedqua=
t.z =3D 0.310418f; expectedquat.w =3D 0.0f;
+    D3DXQuaternionLn(&gotquat,&Nq1);
+    todo_wine{ expect_vec4(expectedquat,gotquat) };
+
 /*_______________D3DXQuaternionMultiply________________________*/
     expectedquat.x =3D 3.0f; expectedquat.y =3D 61.0f; expectedquat.z =3D -=
32.0f; expectedquat.w =3D 85.0f;
     D3DXQuaternionMultiply(&gotquat,&q,&r);
@@ -706,7 +723,6 @@ static void D3X8QuaternionTest(void)
     D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,=
D3DX_PI/3.0f);
     expect_vec4(expectedquat,gotquat);
=20
-
 /*_______________D3DXQuaternionSlerp________________________*/
     expectedquat.x =3D -0.2f; expectedquat.y =3D 2.6f; expectedquat.z =3D 1=
.3f; expectedquat.w =3D 9.1f;
     D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 5ef85b4..6c5f18f 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -304,6 +304,7 @@ D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CO=
NST D3DXPLANE *pplane, C
=20
 D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric(D3DXQUATERNION *pout, CONS=
T D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, CONST D3DXQUATERNION *pq3,=
 FLOAT f, FLOAT g);
 D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3=
DXQUATERNION *pq);
+D3DXQUATERNION* WINAPI D3DXQuaternionLn(D3DXQUATERNION *pout, CONST D3DXQUA=
TERNION *pq);
 D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D=
3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2);
 D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq);
 D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis(D3DXQUATERNION *pout, CON=
ST D3DXVECTOR3 *pv, FLOAT angle);
--=20
1.5.3.2


--=_6f0o8v8fi5wc--



More information about the wine-patches mailing list