[PATCH] Implement D3DXPlaneIntersectLine with a test

David Adam David.Adam at math.cnrs.fr
Thu Nov 15 05:15:58 CST 2007


---
 dlls/d3dx8/d3dx8.spec   |    2 +-
 dlls/d3dx8/math.c       |   20 ++++++++++++++++++++
 dlls/d3dx8/tests/math.c |   17 ++++++++++++++++-
 include/d3dx8math.h     |    1 +
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 3759513..71c55ac 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -62,7 +62,7 @@
 @ stub D3DXQuaternionSquad
 @ stub D3DXQuaternionBaryCentric
 @ stdcall D3DXPlaneNormalize(ptr ptr)
-@ stub D3DXPlaneIntersectLine
+@ stdcall D3DXPlaneIntersectLine(ptr ptr ptr ptr)
 @ stub D3DXPlaneFromPointNormal
 @ stub D3DXPlaneFromPoints
 @ stub D3DXPlaneTransform
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 9a9def9..032d2db 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -435,6 +435,26 @@ D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout=
, CONST D3DXMATRIX *pm)
=20
 /*_________________D3DXPLANE________________*/
=20
+D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *pout, CONST D3DXPLA=
NE *pp, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
+{
+    D3DXVECTOR3 direction, normal;
+    FLOAT dot, temp;
+
+    normal.x =3D pp->a;
+    normal.y =3D pp->b;
+    normal.z =3D pp->c;
+    direction.x =3D pv2->x - pv1->x;
+    direction.y =3D pv2->y - pv1->y;
+    direction.z =3D pv2->z - pv1->z;
+    dot =3D D3DXVec3Dot(&normal, &direction);
+    if ( !dot ) return NULL;
+    temp =3D ( pp->d + D3DXVec3Dot(&normal, pv1) ) / dot;
+    pout->x =3D pv1->x - temp * direction.x;
+    pout->y =3D pv1->y - temp * direction.y;
+    pout->z =3D pv1->z - temp * direction.z;
+    return pout;
+}
+
 D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp)
 {
     FLOAT norm;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index e3dc060..526fc00 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -416,6 +416,8 @@ static void D3DXMatrixTest(void)
 static void D3DXPlaneTest(void)
 {
     D3DXPLANE expectedplane, gotplane, nulplane, plane;
+    D3DXVECTOR3 expectedvec, gotvec, vec1, vec2;
+    LPD3DXVECTOR3 funcpointer;
     D3DXVECTOR4 vec;
     FLOAT expected, got;
=20
@@ -455,7 +457,20 @@ static void D3DXPlaneTest(void)
     got =3D D3DXPlaneDotNormal(NULL,NULL),
     ok( expected =3D=3D got, "Expected : %f, Got : %f\n",expected, got);
=20
-/*_______________D3DXPlaneDotNormalize______________*/
+/*_______________D3DXPlaneIntersectLine___________*/
+    vec1.x =3D 9.0f; vec1.y =3D 6.0f; vec1.z =3D 3.0f;
+    vec2.x =3D 2.0f; vec2.y =3D 5.0f; vec2.z =3D 8.0f;
+    expectedvec.x =3D 20.0f/3.0f; expectedvec.y =3D 17.0f/3.0f; expectedvec=
.z =3D 14.0f/3.0f;
+    D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
+    expect_vec3(expectedvec, gotvec);
+    /* Test a parallele line */
+    vec1.x =3D 11.0f; vec1.y =3D 13.0f; vec1.z =3D 15.0f;
+    vec2.x =3D 17.0f; vec2.y =3D 31.0f; vec2.z =3D 24.0f;
+    expectedvec.x =3D 20.0f/3.0f; expectedvec.y =3D 17.0f/3.0f; expectedvec=
.z =3D 14.0f/3.0f;
+    funcpointer =3D D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
+    ok(funcpointer =3D=3D NULL, "Expected: %p, Got: %p\n", NULL, funcpointe=
r);
+
+/*_______________D3DXPlaneNormalize______________*/
     expectedplane.a =3D -3.0f/sqrt(26.0f); expectedplane.b =3D -1.0f/sqrt(2=
6.0f); expectedplane.c =3D 4.0f/sqrt(26.0f); expectedplane.d =3D 7.0/sqrt(26=
.0f);
     D3DXPlaneNormalize(&gotplane, &plane);
     expect_plane(expectedplane, gotplane);
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index c92535e..7660b21 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -291,6 +291,7 @@ D3DXMATRIX* WINAPI D3DXMatrixScaling(D3DXMATRIX *pout, F=
LOAT sx, FLOAT sy, FLOAT
 D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pout, FLOAT x, FLOAT y=
, FLOAT z);
 D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout, CONST D3DXMATRIX *=
pm);
=20
+D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *pout, CONST D3DXPLA=
NE *pp, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2);
 D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp);
=20
 D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq);
--=20
1.5.3.2


--=_5bp33j7d4nk8--



More information about the wine-patches mailing list