David Adam : d3dx8: Implement D3DXQuaternionSlerp.

Alexandre Julliard julliard at winehq.org
Tue Nov 20 10:55:00 CST 2007


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

Author: David Adam <David.Adam at math.cnrs.fr>
Date:   Mon Nov 19 17:21:11 2007 +0100

d3dx8: Implement D3DXQuaternionSlerp.

---

 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(D3DXQUATERNION *pout, CONST D3DXQ
     }
     return pout;
 }
+
+D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t)
+{
+    FLOAT dot, epsilon;
+
+    epsilon = 1.0f;
+    dot = D3DXQuaternionDot(pq1, pq2);
+    if ( dot < 0.0f) epsilon = -1.0f;
+    pout->x = (1.0f - t) * pq1->x + epsilon * t * pq2->x;
+    pout->y = (1.0f - t) * pq1->y + epsilon * t * pq2->y;
+    pout->z = (1.0f - t) * pq1->z + epsilon * t * pq2->z;
+    pout->w = (1.0f - t) * pq1->w + epsilon * t * pq2->w;
+    return pout;
+}
+
 /*_________________D3DXVec2_____________________*/
 
 D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *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)
 
 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;
 
     nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
     q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
     r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
+    t.x = -1111.0f, t.y= 111.0f; t.z = -11.0f; t.w = 1.0f;
+
+    scale = 0.3f;
 
 /*_______________D3DXQuaternionConjugate________________*/
     expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
@@ -644,6 +647,14 @@ static void D3X8QuaternionTest(void)
     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
     D3DXQuaternionNormalize(&gotquat,&nul);
     expect_vec4(expectedquat,gotquat);
+
+/*_______________D3DXQuaternionSlerp________________________*/
+    expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
+    D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
+    expect_vec4(expectedquat,gotquat);
+    expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
+    D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
+    expect_vec4(expectedquat,gotquat);
 }
 
 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, CONST D3DXPLANE *pplane, C
 D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
 D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2);
 D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
+D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t);
 
 D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *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 *pv3, FLOAT s);




More information about the wine-cvs mailing list