[PATCH] Implement D3DX__Lerp with a test

David Adam David.Adam at math.cnrs.fr
Thu Oct 18 12:01:57 CDT 2007


---
 dlls/d3dx8/tests/math.c |   30 ++++++++++++++++++++++++++----
 include/d3dx8math.inl   |   20 ++++++++++++++++++++
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 78e47d2..95d04e9 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -187,10 +187,11 @@ static void D3X8Vector3Test(void)
 {
     D3DXVECTOR3 expectedvec, gotvec, u, v;
     LPD3DXVECTOR3 funcpointer;
-    FLOAT expected, got;
+    FLOAT expected, got, scale;
=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;
+    scale =3D -6.5f;
=20
 /*_______________D3DXVec3Add__________________________*/
     expectedvec.x =3D 11.0f; expectedvec.y =3D 3.0f; expectedvec.z =3D -2.0=
f;=20
@@ -232,6 +233,16 @@ static void D3X8Vector3Test(void)
     got =3D D3DXVec3LengthSq(NULL);
     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
=20
+/*_______________D3DXVec3Lerp__________________________*/
+    expectedvec.x =3D 54.5f; expectedvec.y =3D 64.5f, expectedvec.z =3D 41.=
0f ;
+    D3DXVec3Lerp(&gotvec,&u,&v,scale);
+    expect_vec3(expectedvec,gotvec);
+    /* Tests the case NULL */
+    funcpointer =3D D3DXVec3Lerp(&gotvec,NULL,&v,scale);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+    funcpointer =3D D3DXVec3Lerp(NULL,NULL,NULL,scale);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+
 /*_______________D3DXVec3Subtract_______________________*/
     expectedvec.x =3D 7.0f; expectedvec.y =3D 9.0f; expectedvec.z =3D 6.0f;=
=20
     D3DXVec3Subtract(&gotvec,&u,&v);
@@ -248,12 +259,13 @@ static void D3X8Vector4Test(void)
 {
     D3DXVECTOR4 expectedvec, gotvec, u, v;
     LPD3DXVECTOR4 funcpointer;
-    FLOAT expected, got;
+    FLOAT expected, got, scale;
+    scale =3D -6.5f;
=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__________________________*/
+/*_______________D3DXVec4Add__________________________*/
     expectedvec.x =3D -2.0f; expectedvec.y =3D 6.0f; expectedvec.z =3D -1.0=
f; expectedvec.w =3D 17.0f;
     D3DXVec4Add(&gotvec,&u,&v);
     expect_vec4(expectedvec,gotvec);
@@ -293,7 +305,17 @@ static void D3X8Vector4Test(void)
     got =3D D3DXVec4LengthSq(NULL);
     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", =
expected, got);
=20
-/*_______________D3DXVec3Add__________________________*/
+/*_______________D3DXVec4Lerp__________________________*/
+    expectedvec.x =3D 27.0f; expectedvec.y =3D -11.0f; expectedvec.z =3D 62=
.5;  expectedvec.w =3D 29.5;
+    D3DXVec4Lerp(&gotvec,&u,&v,scale);
+    expect_vec4(expectedvec,gotvec);
+    /* Tests the case NULL */
+    funcpointer =3D D3DXVec4Lerp(&gotvec,NULL,&v,scale);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+    funcpointer =3D D3DXVec4Lerp(NULL,NULL,NULL,scale);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+
+/*_______________D3DXVec4Subtract__________________________*/
     expectedvec.x =3D 4.0f; expectedvec.y =3D -2.0f; expectedvec.z =3D 9.0f=
; expectedvec.w =3D 3.0f;
     D3DXVec4Subtract(&gotvec,&u,&v);
     expect_vec4(expectedvec,gotvec);
diff --git a/include/d3dx8math.inl b/include/d3dx8math.inl
index 266d923..7aeb94c 100644
--- a/include/d3dx8math.inl
+++ b/include/d3dx8math.inl
@@ -122,6 +122,15 @@ static inline FLOAT D3DXVec3LengthSq(CONST D3DXVECTOR3 =
*pv)
     return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z);
 }
=20
+static inline D3DXVECTOR3* D3DXVec3Lerp(D3DXVECTOR3 *pout, CONST D3DXVECTOR=
3 *pv1, CONST D3DXVECTOR3 *pv2, FLOAT s)
+{
+    if ( !pout || !pv1 || !pv2) return NULL;
+    pout->x =3D (1-s) * (pv1->x) + s * (pv2->x);
+    pout->y =3D (1-s) * (pv1->y) + s * (pv2->y);
+    pout->z =3D (1-s) * (pv1->z) + s * (pv2->z);
+    return pout;
+}
+
 static inline D3DXVECTOR3* D3DXVec3Subtract(D3DXVECTOR3 *pout, CONST D3DXVE=
CTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
 {
     if ( !pout || !pv1 || !pv2) return NULL;
@@ -160,6 +169,16 @@ static inline FLOAT D3DXVec4LengthSq(CONST D3DXVECTOR4 =
*pv)
     return (pv->x) * (pv->x) + (pv->y) * (pv->y) + (pv->z) * (pv->z) + (pv-=
>w) * (pv->w);
 }
=20
+static inline D3DXVECTOR4* D3DXVec4Lerp(D3DXVECTOR4 *pout, CONST D3DXVECTOR=
4 *pv1, CONST D3DXVECTOR4 *pv2, FLOAT s)
+{
+    if ( !pout || !pv1 || !pv2) return NULL;
+    pout->x =3D (1-s) * (pv1->x) + s * (pv2->x);
+    pout->y =3D (1-s) * (pv1->y) + s * (pv2->y);
+    pout->z =3D (1-s) * (pv1->z) + s * (pv2->z);
+    pout->w =3D (1-s) * (pv1->w) + s * (pv2->w);
+    return pout;
+}
+
 static inline D3DXVECTOR4* D3DXVec4Subtract(D3DXVECTOR4 *pout, CONST D3DXVE=
CTOR4 *pv1, CONST D3DXVECTOR4 *pv2)
 {
     if ( !pout || !pv1 || !pv2) return NULL;
@@ -169,6 +188,7 @@ static inline D3DXVECTOR4* D3DXVec4Subtract(D3DXVECTOR4 =
*pout, CONST D3DXVECTOR4
     pout->w =3D pv1->w - pv2->w;
     return pout;
 }
+
 /*__________________D3DXQUATERNION____________________*/
=20
 static inline FLOAT D3DXQuaternionDot(CONST D3DXQUATERNION *pq1, CONST D3DX=
QUATERNION *pq2)
--=20
1.5.3.2


--=_2x6002erfeg4--



More information about the wine-patches mailing list