[PATCH] Implement D3DX__Dot with a test

David Adam David.Adam at math.cnrs.fr
Thu Oct 18 11:06:37 CDT 2007


---
 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 d6afdf4..1e37068 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -28,10 +28,23 @@
=20
 static void D3X8QuaternionTest(void)
 {
-    D3DXQUATERNION q;
+    D3DXQUATERNION q, r;
     FLOAT expected, got;
=20
     q.x =3D 1.0f, q.y =3D 2.0f; q.z =3D 4.0f; q.w =3D 10.0f;=20
+    r.x =3D -3.0f; r.y =3D 4.0f; r.z =3D -5.0f; r.w =3D 7.0;
+
+/*_______________D3DXQuaternionDot______________________*/
+    expected =3D 55.0f;
+    got =3D D3DXQuaternionDot(&q,&r);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+    /* Tests the case NULL */
+    expected=3D0.0f;
+    got =3D D3DXQuaternionDot(NULL,&r);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+    expected=3D0.0f;
+    got =3D D3DXQuaternionDot(NULL,NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
=20
 /*_______________D3DXQuaternionLength__________________________*/
    expected =3D 11.0f;
@@ -168,10 +181,23 @@ static void D3X8Vector2Test(void)
=20
 static void D3X8Vector3Test(void)
 {
-    D3DXVECTOR3 u;
+    D3DXVECTOR3 u, v;
     FLOAT expected, got;
=20
     u.x =3D 9.0f; u.y =3D 6.0f; u.z =3D 2.0f;
+    v.x =3D 2.0f; v.y =3D -3.0f; v.z =3D -4.0;
+
+/*_______________D3DXVec3Dot__________________________*/
+    expected =3D -8.0f;
+    got =3D D3DXVec3Dot(&u,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+    /* Tests the case NULL */
+    expected=3D0.0f;
+    got =3D D3DXVec3Dot(NULL,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+    expected=3D0.0f;
+    got =3D D3DXVec3Dot(NULL,NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
=20
 /*_______________D3DXVec3Length__________________________*/
    expected =3D 11.0f;
@@ -194,10 +220,23 @@ static void D3X8Vector3Test(void)
=20
 static void D3X8Vector4Test(void)
 {
-    D3DXVECTOR4 u;
+    D3DXVECTOR4 u, v;
     FLOAT expected, got;
=20
     u.x =3D 1.0f; u.y =3D 2.0f; u.z =3D 4.0f; u.w =3D 10.0;
+    v.x =3D -3.0f; v.y =3D 4.0f; v.z =3D -5.0f; v.w =3D 7.0;
+
+/*_______________D3DXVec4Dot__________________________*/
+    expected =3D 55.0f;
+    got =3D D3DXVec4Dot(&u,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+    /* Tests the case NULL */
+    expected=3D0.0f;
+    got =3D D3DXVec4Dot(NULL,&v);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
+    expected=3D0.0f;
+    got =3D D3DXVec4Dot(NULL,NULL);
+    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
=20
 /*_______________D3DXVec4Length__________________________*/
    expected =3D 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
=20
 /*__________________D3DXVECTOR3_______________________*/
=20
+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)
=20
 /*__________________D3DXVECTOR4_______________________*/
=20
+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)
=20
 /*__________________D3DXQUATERNION____________________*/
=20
-static inline FLOAT D3DXQuaternionLength( CONST D3DXQUATERNION *pq)
+static inline FLOAT D3DXQuaternionDot(CONST D3DXQUATERNION *pq1, CONST D3DX=
QUATERNION *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) );
 }
=20
-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);
--=20
1.5.3.2


--=_5vz2gytr4ikg--



More information about the wine-patches mailing list