[PATCH] Implement D3DX__Add with a test
David Adam
David.Adam at math.cnrs.fr
Thu Oct 18 11:32:17 CDT 2007
---
dlls/d3dx8/tests/math.c | 30 ++++++++++++++++++++++++++++--
include/d3dx8math.inl | 19 +++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 1e37068..06c20d6 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -26,6 +26,10 @@
=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
+#define expect_vec3(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<ad=
mitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expected=
vec.z-gotvec.z)<admitted_error),"Expected Vector=3D (%f, %f,%f)\n , Got Vect=
or=3D (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.x=
, gotvec.y, gotvec.z);
+
+#define expect_vec4(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<ad=
mitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expected=
vec.z-gotvec.z)<admitted_error)&&(fabs(expectedvec.w-gotvec.w)<admitted_erro=
r),"Expected Vector=3D (%f, %f, %f, %f)\n , Got Vector=3D (%f, %f, %f, %f)\n=
", expectedvec.x, expectedvec.y, expectedvec.z, expectedvec.w, gotvec.x, got=
vec.y, gotvec.z, gotvec.w);
+
static void D3X8QuaternionTest(void)
{
D3DXQUATERNION q, r;
@@ -181,12 +185,23 @@ static void D3X8Vector2Test(void)
=20
static void D3X8Vector3Test(void)
{
- D3DXVECTOR3 u, v;
+ D3DXVECTOR3 expectedvec, gotvec, u, v;
+ LPD3DXVECTOR3 funcpointer;
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;
=20
+/*_______________D3DXVec3Add__________________________*/
+ expectedvec.x =3D 11.0f; expectedvec.y =3D 3.0f; expectedvec.z =3D -2.0=
f;=20
+ D3DXVec3Add(&gotvec,&u,&v);
+ expect_vec3(expectedvec,gotvec);
+ /* Tests the case NULL */
+ funcpointer =3D D3DXVec3Add(&gotvec,NULL,&v);
+ ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+ funcpointer =3D D3DXVec3Add(NULL,NULL,NULL);
+ ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+
/*_______________D3DXVec3Dot__________________________*/
expected =3D -8.0f;
got =3D D3DXVec3Dot(&u,&v);
@@ -220,12 +235,23 @@ static void D3X8Vector3Test(void)
=20
static void D3X8Vector4Test(void)
{
- D3DXVECTOR4 u, v;
+ D3DXVECTOR4 expectedvec, gotvec, u, v;
+ LPD3DXVECTOR4 funcpointer;
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;
=20
+/*_______________D3DXVec3Add__________________________*/
+ expectedvec.x =3D -2.0f; expectedvec.y =3D 6.0f; expectedvec.z =3D -1.0=
f; expectedvec.w =3D 17.0;
+ D3DXVec4Add(&gotvec,&u,&v);
+ expect_vec4(expectedvec,gotvec);
+ /* Tests the case NULL */
+ funcpointer =3D D3DXVec4Add(&gotvec,NULL,&v);
+ ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+ funcpointer =3D D3DXVec4Add(NULL,NULL,NULL);
+ ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+
/*_______________D3DXVec4Dot__________________________*/
expected =3D 55.0f;
got =3D D3DXVec4Dot(&u,&v);
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index cbe01ec..d80ab65 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -95,6 +95,15 @@ static inline D3DXVECTOR2* D3DXVec2Subtract(D3DXVECTOR2 *=
pout, CONST D3DXVECTOR2
=20
/*__________________D3DXVECTOR3_______________________*/
=20
+static inline D3DXVECTOR3* D3DXVec3Add(D3DXVECTOR3 *pout, CONST D3DXVECTOR3=
*pv1, CONST D3DXVECTOR3 *pv2)
+{
+ if ( !pout || !pv1 || !pv2) return NULL;
+ pout->x =3D pv1->x + pv2->x;
+ pout->y =3D pv1->y + pv2->y;
+ pout->z =3D pv1->z + pv2->z;=20
+ return pout;
+}
+
static inline FLOAT D3DXVec3Dot(CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *=
pv2)
{
if ( !pv1 || !pv2 ) return 0.0f;
@@ -115,6 +124,16 @@ static inline FLOAT D3DXVec3LengthSq(CONST D3DXVECTOR3 =
*pv)
=20
/*__________________D3DXVECTOR4_______________________*/
=20
+static inline D3DXVECTOR4* D3DXVec4Add(D3DXVECTOR4 *pout, CONST D3DXVECTOR4=
*pv1, CONST D3DXVECTOR4 *pv2)
+{
+ if ( !pout || !pv1 || !pv2) return NULL;
+ pout->x =3D pv1->x + pv2->x;
+ pout->y =3D pv1->y + pv2->y;
+ pout->z =3D pv1->z + pv2->z;=20
+ pout->w =3D pv1->w + pv2->w;
+ return pout;
+}
+
static inline FLOAT D3DXVec4Dot(CONST D3DXVECTOR4 *pv1, CONST D3DXVECTOR4 *=
pv2)
{
if (!pv1 || !pv2 ) return 0.0f;
--=20
1.5.3.2
--=_44ezcfd99w00--
More information about the wine-patches
mailing list