[PATCH] Implement D3DXPlaneFromPoints with a test

David Adam David.Adam at math.cnrs.fr
Mon Nov 19 07:34:46 CST 2007


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

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 5b35df4..4dd230b 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -64,7 +64,7 @@
 @ stdcall D3DXPlaneNormalize(ptr ptr)
 @ stdcall D3DXPlaneIntersectLine(ptr ptr ptr ptr)
 @ stdcall D3DXPlaneFromPointNormal(ptr ptr ptr)
-@ stub D3DXPlaneFromPoints
+@ stdcall D3DXPlaneFromPoints(ptr ptr ptr ptr)
 @ stub D3DXPlaneTransform
 @ stub D3DXColorAdjustSaturation
 @ stub D3DXColorAdjustContrast
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 875ca49..0727492 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -491,6 +491,20 @@ D3DXPLANE* WINAPI D3DXPlaneFromPointNormal(D3DXPLANE *p=
out, CONST D3DXVECTOR3 *p
     return pout;
 }
=20
+D3DXPLANE* WINAPI D3DXPlaneFromPoints(D3DXPLANE *pout, CONST D3DXVECTOR3 *p=
v1, CONST D3DXVECTOR3 *pv2, CONST D3DXVECTOR3 *pv3)
+{
+    D3DXVECTOR3 edge1, edge2, normal, Nnormal;
+
+    edge1.x =3D 0.0f; edge1.y =3D 0.0f; edge1.z =3D 0.0f;
+    edge2.x =3D 0.0f; edge2.y =3D 0.0f; edge2.z =3D 0.0f;
+    D3DXVec3Subtract(&edge1, pv2, pv1);
+    D3DXVec3Subtract(&edge2, pv3, pv1);
+    D3DXVec3Cross(&normal, &edge1, &edge2);
+    D3DXVec3Normalize(&Nnormal, &normal);
+    D3DXPlaneFromPointNormal(pout, pv1, &Nnormal);
+    return pout;
+}
+
 D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *pout, CONST D3DXPLA=
NE *pp, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2)
 {
     D3DXVECTOR3 direction, normal;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 2811fea..05b84fb 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -437,12 +437,13 @@ static void D3DXMatrixTest(void)
 static void D3DXPlaneTest(void)
 {
     D3DXPLANE expectedplane, gotplane, nulplane, plane;
-    D3DXVECTOR3 expectedvec, gotvec, vec1, vec2;
+    D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
     LPD3DXVECTOR3 funcpointer;
     D3DXVECTOR4 vec;
     FLOAT expected, got;
=20
     plane.a =3D -3.0f; plane.b =3D -1.0f; plane.c =3D 4.0f; plane.d =3D 7.0=
f;
+
     vec.x =3D 2.0f; vec.y =3D 5.0f; vec.z =3D -6.0f; vec.w =3D 11.0f;
=20
 /*_______________D3DXPlaneDot________________*/
@@ -485,6 +486,19 @@ static void D3DXPlaneTest(void)
     D3DXPlaneFromPointNormal(&gotplane,&vec1,&vec2);
     expect_plane(expectedplane, gotplane);
=20
+/*_______________D3DXPlaneFromPoints_______*/
+    vec1.x =3D 1.0f; vec1.y =3D 2.0f; vec1.z =3D 3.0f;
+    vec2.x =3D 1.0f; vec2.y =3D -6.0f; vec2.z =3D -5.0f;
+    vec3.x =3D 83.0f; vec3.y =3D 74.0f; vec3.z =3D 65.0f;
+    expectedplane.a =3D 0.085914f; expectedplane.b =3D -0.704492f; expected=
plane.c =3D 0.704492f; expectedplane.d =3D -0.790406f;
+    D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
+    expect_plane(expectedplane, gotplane);
+    /* Test if 2 vectors are parallels */
+    vec3.x =3D 1.0f; vec3.y =3D 1.0f; vec3.z =3D 2.0f;
+    expectedplane.a =3D 0.0f; expectedplane.b =3D 0.0f; expectedplane.c =3D=
 0.0f; expectedplane.d =3D 0.0f;
+    D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
+    expect_plane(expectedplane, gotplane);
+
 /*_______________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;
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 8c2cdc3..8082876 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -294,6 +294,7 @@ D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pou=
t, FLOAT x, FLOAT y, FLO
 D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout, CONST D3DXMATRIX *=
pm);
=20
 D3DXPLANE* WINAPI D3DXPlaneFromPointNormal(D3DXPLANE *pout, CONST D3DXVECTO=
R3 *pvpoint, CONST D3DXVECTOR3 *pvnormal);
+D3DXPLANE* WINAPI D3DXPlaneFromPoints(D3DXPLANE *pout, CONST D3DXVECTOR3 *p=
v1, CONST D3DXVECTOR3 *pv2, CONST D3DXVECTOR3 *pv3);
 D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *pout, CONST D3DXPLA=
NE *pp, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2);
 D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp);
=20
--=20
1.5.3.2


--=_4o519q88ej28--



More information about the wine-patches mailing list