David Adam : d3dx8: Implement D3DX*Dot with a test.

Alexandre Julliard julliard at winehq.org
Mon Oct 22 09:55:45 CDT 2007


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

Author: David Adam <David.Adam at math.cnrs.fr>
Date:   Thu Oct 18 18:06:37 2007 +0200

d3dx8: Implement D3DX*Dot with a test.

---

 dlls/d3dx8/tests/math.c |   45 ++++++++++++++++++++++++++++++++++++++++++---
 include/d3dx8math.inl   |   22 ++++++++++++++++++++--
 2 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index a598020..a222362 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -28,10 +28,23 @@
 
 static void D3X8QuaternionTest(void)
 {
-    D3DXQUATERNION q;
+    D3DXQUATERNION q, r;
     FLOAT expected, got;
 
     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;
+
+/*_______________D3DXQuaternionDot______________________*/
+    expected = 55.0f;
+    got = D3DXQuaternionDot(&q,&r);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+    /* Tests the case NULL */
+    expected=0.0f;
+    got = D3DXQuaternionDot(NULL,&r);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+    expected=0.0f;
+    got = D3DXQuaternionDot(NULL,NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
 
 /*_______________D3DXQuaternionLength__________________________*/
    expected = 11.0f;
@@ -168,10 +181,23 @@ static void D3X8Vector2Test(void)
 
 static void D3X8Vector3Test(void)
 {
-    D3DXVECTOR3 u;
+    D3DXVECTOR3 u, v;
     FLOAT expected, got;
 
     u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
+    v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
+
+/*_______________D3DXVec3Dot__________________________*/
+    expected = -8.0f;
+    got = D3DXVec3Dot(&u,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+    /* Tests the case NULL */
+    expected=0.0f;
+    got = D3DXVec3Dot(NULL,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+    expected=0.0f;
+    got = D3DXVec3Dot(NULL,NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
 
 /*_______________D3DXVec3Length__________________________*/
    expected = 11.0f;
@@ -194,10 +220,23 @@ static void D3X8Vector3Test(void)
 
 static void D3X8Vector4Test(void)
 {
-    D3DXVECTOR4 u;
+    D3DXVECTOR4 u, v;
     FLOAT expected, got;
 
     u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
+    v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
+
+/*_______________D3DXVec4Dot__________________________*/
+    expected = 55.0f;
+    got = D3DXVec4Dot(&u,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+    /* Tests the case NULL */
+    expected=0.0f;
+    got = D3DXVec4Dot(NULL,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+    expected=0.0f;
+    got = D3DXVec4Dot(NULL,NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
 
 /*_______________D3DXVec4Length__________________________*/
    expected = 11.0f;
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index c8de09b..cbe01ec 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -95,6 +95,12 @@ static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *pout, CONST D3DXVECTOR2
 
 /*__________________D3DXVECTOR3_______________________*/
 
+static inline FLOAT D3DXVec3Dot(CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
+{
+    if ( !pv1 || !pv2 ) return 0.0f;
+    return (pv1->x) * (pv2->x) + (pv1->y) * (pv2->y) + (pv1->z) * (pv2->z);
+}
+
 static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *pv)
 {
     if (!pv) return 0.0f;
@@ -109,6 +115,12 @@ static inline FLOAT D3DXVec3LengthSq(CONST D3DXVECTOR3 *pv)
 
 /*__________________D3DXVECTOR4_______________________*/
 
+static inline FLOAT D3DXVec4Dot(CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
+{
+    if (!pv1 || !pv2 ) return 0.0f;
+    return (pv1->x) * (pv2->x) + (pv1->y) * (pv2->y) + (pv1->z) * (pv2->z) + (pv1->w) * (pv2->w);
+}
+
 static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv)
 {
     if (!pv) return 0.0f;
@@ -123,13 +135,19 @@ static inline FLOAT D3DXVec4LengthSq(CONST D3DXVECTOR4 *pv)
 
 /*__________________D3DXQUATERNION____________________*/
 
-static inline FLOAT D3DXQuaternionLength( CONST D3DXQUATERNION *pq)
+static inline FLOAT D3DXQuaternionDot(CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2)
+{
+    if ( !pq1 || !pq2 ) return 0.0f;
+    return (pq1->x) * (pq2->x) + (pq1->y) * (pq2->y) + (pq1->z) * (pq2->z) + (pq1->w) * (pq2->w);
+}
+
+static inline FLOAT D3DXQuaternionLength(CONST D3DXQUATERNION *pq)
 {
     if (!pq) return 0.0f;
     return sqrt( (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w) );
 }
 
-static inline FLOAT D3DXQuaternionLengthSq( CONST D3DXQUATERNION *pq)
+static inline FLOAT D3DXQuaternionLengthSq(CONST D3DXQUATERNION *pq)
 {
     if (!pq) return 0.0f;
     return (pq->x) * (pq->x) + (pq->y) * (pq->y) + (pq->z) * (pq->z) + (pq->w) * (pq->w);




More information about the wine-cvs mailing list