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

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


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

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

d3dx8: Implement D3DX*Length with a test.

---

 dlls/d3dx8/tests/math.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++
 include/d3dx8math.inl   |   30 ++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 9ae9018..d0d0b03 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -26,6 +26,23 @@
 
 #define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
 
+static void D3X8QuaternionTest(void)
+{
+    D3DXQUATERNION q;
+    FLOAT expected, got;
+
+    q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
+
+/*_______________D3DXQuaternionLength__________________________*/
+   expected = 11.0f;
+   got = D3DXQuaternionLength(&q);
+   ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+   /* Tests the case NULL */
+    expected=0.0f;
+    got = D3DXQuaternionLength(NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+}
+
 static void D3X8Vector2Test(void)
 {
     D3DXVECTOR2 expectedvec, gotvec, u, v;
@@ -140,7 +157,44 @@ static void D3X8Vector2Test(void)
 
 }
 
+static void D3X8Vector3Test(void)
+{
+    D3DXVECTOR3 u;
+    FLOAT expected, got;
+
+    u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
+
+/*_______________D3DXVec3Length__________________________*/
+   expected = 11.0f;
+   got = D3DXVec3Length(&u);
+   ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+   /* Tests the case NULL */
+    expected=0.0f;
+    got = D3DXVec3Length(NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+}
+
+static void D3X8Vector4Test(void)
+{
+    D3DXVECTOR4 u;
+    FLOAT expected, got;
+
+    u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
+
+/*_______________D3DXVec4Length__________________________*/
+   expected = 11.0f;
+   got = D3DXVec4Length(&u);
+   ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+   /* Tests the case NULL */
+    expected=0.0f;
+    got = D3DXVec4Length(NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
+}
+
 START_TEST(math)
 {
+    D3X8QuaternionTest();
     D3X8Vector2Test();
+    D3X8Vector3Test();
+    D3X8Vector4Test();
 }
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index 24ff812..94e0019 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -19,6 +19,8 @@
 #ifndef __D3DX8MATH_INL__
 #define __D3DX8MATH_INL__
 
+/*_______________D3DXVECTOR2________________________*/
+
 static inline D3DXVECTOR2* D3DXVec2Add(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2)
 {
     if ( !pout || !pv1 || !pv2) return NULL;
@@ -91,4 +93,32 @@ static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *pout, CONST D3DXVECTOR2
     return pout;
 }
 
+/*__________________D3DXVECTOR3_______________________*/
+
+static inline FLOAT D3DXVec3Length(CONST D3DXVECTOR3 *pv)
+{
+    if (!pv) return 0.0f;
+    return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) );
+}
+
+/*__________________D3DXVECTOR4_______________________*/
+
+static inline FLOAT D3DXVec4Length(CONST D3DXVECTOR4 *pv)
+{
+    if (!pv) return 0.0f;
+    return sqrt( (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv->w) * (pv->w) );
+}
+
+
+/*__________________D3DXQUATERNION____________________*/
+
+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) );
+}
+
+
+
+
 #endif




More information about the wine-cvs mailing list