[PATCH] Implement-D3DX___Length-function-with-a-test.patch
David Adam
David.Adam at math.cnrs.fr
Thu Oct 18 07:03:03 CDT 2007
---
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..3449dfa 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -26,6 +26,23 @@
=20
#define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<adm=
itted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector=
=3D (%f, %f)\n , Got Vector=3D (%f, %f)\n", expectedvec.x, expectedvec.y, go=
tvec.x, gotvec.y);
=20
+static void D3X8QuaternionTest(void)
+{
+ D3DXQUATERNION q;
+ FLOAT expected, got;
+
+ q.x =3D 1.0f, q.y =3D 2.0f; q.z =3D 4.0f; q.w =3D 10.0f;=20
+
+/*_______________D3DXQuaternionLength__________________________*/
+ expected =3D 11.0f;
+ got =3D D3DXQuaternionLength(&q);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", e=
xpected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D 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)
=20
}
=20
+static void D3X8Vector3Test(void)
+{
+ D3DXVECTOR3 u;
+ FLOAT expected, got;
+
+ u.x =3D 9.0f; u.y =3D 6.0f; u.z =3D 2.0f;
+
+/*_______________D3DXVec3Length__________________________*/
+ expected =3D 11.0f;
+ got =3D D3DXVec3Length(&u);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", e=
xpected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D 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 =3D 1.0f; u.y =3D 2.0f; u.z =3D 4.0f; u.w =3D 10.0;
+
+/*_______________D3DXVec4Length__________________________*/
+ expected =3D 11.0f;
+ got =3D D3DXVec4Length(&u);
+ ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", e=
xpected, got);
+ /* Tests the case NULL */
+ expected=3D0.0f;
+ got =3D 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__
=20
+/*_______________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;
}
=20
+/*__________________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
--=20
1.5.3.2
--=_6a5oyajbf14w--
More information about the wine-patches
mailing list