[PATCH] Implement D3DXQuaternionSlerp with a test

David Adam David.Adam at math.cnrs.fr
Mon Nov 19 10:21:11 CST 2007


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

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index ffa82a8..005ac87 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -58,7 +58,7 @@
 @ stdcall D3DXQuaternionInverse(ptr ptr)
 @ stub D3DXQuaternionLn
 @ stub D3DXQuaternionExp
-@ stub D3DXQuaternionSlerp
+@ stdcall D3DXQuaternionSlerp(ptr ptr ptr long)
 @ stub D3DXQuaternionSquad
 @ stub D3DXQuaternionBaryCentric
 @ stdcall D3DXPlaneNormalize(ptr ptr)
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 99c4a42..900566c 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -635,6 +635,21 @@ D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUAT=
ERNION *pout, CONST D3DXQ
     }
     return pout;
 }
+
+D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DX=
QUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t)
+{
+    FLOAT dot, epsilon;
+
+    epsilon =3D 1.0f;
+    dot =3D D3DXQuaternionDot(pq1, pq2);
+    if ( dot < 0.0f) epsilon =3D -1.0f;
+    pout->x =3D (1.0f - t) * pq1->x + epsilon * t * pq2->x;
+    pout->y =3D (1.0f - t) * pq1->y + epsilon * t * pq2->y;
+    pout->z =3D (1.0f - t) * pq1->z + epsilon * t * pq2->z;
+    pout->w =3D (1.0f - t) * pq1->w + epsilon * t * pq2->w;
+    return pout;
+}
+
 /*_________________D3DXVec2_____________________*/
=20
 D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR=
2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g)
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 399bf46..3f96e76 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -552,14 +552,17 @@ static void D3DXPlaneTest(void)
=20
 static void D3X8QuaternionTest(void)
 {
-    D3DXQUATERNION expectedquat, gotquat, nul, q, r, s;
+    D3DXQUATERNION expectedquat, gotquat, nul, q, r, s, t;
     LPD3DXQUATERNION funcpointer;
-    FLOAT expected, got;
+    FLOAT expected, got, scale;
     BOOL expectedbool, gotbool;
=20
     nul.x =3D 0.0f; nul.y =3D 0.0f; nul.z =3D 0.0f; nul.w =3D 0.0f;
     q.x =3D 1.0f, q.y =3D 2.0f; q.z =3D 4.0f; q.w =3D 10.0f;
     r.x =3D -3.0f; r.y =3D 4.0f; r.z =3D -5.0f; r.w =3D 7.0;
+    t.x =3D -1111.0f, t.y=3D 111.0f; t.z =3D -11.0f; t.w =3D 1.0f;
+
+    scale =3D 0.3f;
=20
 /*_______________D3DXQuaternionConjugate________________*/
     expectedquat.x =3D -1.0f; expectedquat.y =3D -2.0f; expectedquat.z =3D =
-4.0f; expectedquat.w =3D 10.0f;
@@ -644,6 +647,14 @@ static void D3X8QuaternionTest(void)
     expectedquat.x =3D 0.0f; expectedquat.y =3D 0.0f; expectedquat.z =3D 0.=
0f; expectedquat.w =3D 0.0f;
     D3DXQuaternionNormalize(&gotquat,&nul);
     expect_vec4(expectedquat,gotquat);
+
+/*_______________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);
+    expect_vec4(expectedquat,gotquat);
+    expectedquat.x =3D 334.0f; expectedquat.y =3D -31.9f; expectedquat.z =
=3D 6.1f; expectedquat.w =3D 6.7f;
+    D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
+    expect_vec4(expectedquat,gotquat);
 }
=20
 static void D3X8Vector2Test(void)
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 37641ed..455089c 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -305,6 +305,7 @@ D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CO=
NST D3DXPLANE *pplane, C
 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);
+D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DX=
QUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t);
=20
 D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR=
2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g);
 D3DXVECTOR2* WINAPI D3DXVec2CatmullRom(D3DXVECTOR2 *pout, CONST D3DXVECTOR2=
 *pv0, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv=
3, FLOAT s);
--=20
1.5.3.2


--=_70wpxj9arbk8--



More information about the wine-patches mailing list