[PATCH] Implement D3DXPlaneNormalize with a test
David Adam
David.Adam at math.cnrs.fr
Thu Nov 15 04:27:19 CST 2007
---
dlls/d3dx8/d3dx8.spec | 2 +-
dlls/d3dx8/math.c | 24 ++++++++++++++++++++++++
dlls/d3dx8/tests/math.c | 17 ++++++++++++++++-
include/d3dx8math.h | 2 ++
4 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 7578597..3759513 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -61,7 +61,7 @@
@ stub D3DXQuaternionSlerp
@ stub D3DXQuaternionSquad
@ stub D3DXQuaternionBaryCentric
-@ stub D3DXPlaneNormalize
+@ stdcall D3DXPlaneNormalize(ptr ptr)
@ stub D3DXPlaneIntersectLine
@ stub D3DXPlaneFromPointNormal
@ stub D3DXPlaneFromPoints
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 15276fa..9a9def9 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -433,6 +433,30 @@ D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout=
, CONST D3DXMATRIX *pm)
return pout;
}
=20
+/*_________________D3DXPLANE________________*/
+
+D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp)
+{
+ FLOAT norm;
+
+ norm =3D sqrt(pp->a * pp->a + pp->b * pp->b + pp->c * pp->c);
+ if ( norm )
+ {
+ pout->a =3D pp->a / norm;
+ pout->b =3D pp->b / norm;
+ pout->c =3D pp->c / norm;
+ pout->d =3D pp->d / norm;
+ }
+ else
+ {
+ pout->a =3D 0.0f;
+ pout->b =3D 0.0f;
+ pout->c =3D 0.0f;
+ pout->d =3D 0.0f;
+ }
+ return pout;
+}
+
/*_________________D3DXQUATERNION________________*/
=20
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq)
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 9e862ab..e3dc060 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -50,6 +50,8 @@
U(gotmat).m[3][0],U(gotmat).m[3][1],U(gotmat).m[3][2],U(gotmat).m[3]=
[3]); \
}
=20
+#define expect_plane(expectedplane,gotplane) ok((fabs(expectedplane.a-gotpl=
ane.a)<admitted_error)&&(fabs(expectedplane.b-gotplane.b)<admitted_error)&&(=
fabs(expectedplane.c-gotplane.c)<admitted_error)&&(fabs(expectedplane.d-gotp=
lane.d)<admitted_error),"Expected Plane=3D (%f, %f, %f, %f)\n , Got Plane=3D=
(%f, %f, %f, %f)\n", expectedplane.a, expectedplane.b, expectedplane.c, exp=
ectedplane.d, gotplane.a, gotplane.b, gotplane.c, gotplane.d);
+
#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 Vec=
tor=3D (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.=
x, gotvec.y, gotvec.z);
@@ -413,7 +415,7 @@ static void D3DXMatrixTest(void)
=20
static void D3DXPlaneTest(void)
{
- D3DXPLANE plane;
+ D3DXPLANE expectedplane, gotplane, nulplane, plane;
D3DXVECTOR4 vec;
FLOAT expected, got;
=20
@@ -452,6 +454,19 @@ static void D3DXPlaneTest(void)
expected =3D 0.0f;
got =3D D3DXPlaneDotNormal(NULL,NULL),
ok( expected =3D=3D got, "Expected : %f, Got : %f\n",expected, got);
+
+/*_______________D3DXPlaneDotNormalize______________*/
+ 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);
+ nulplane.a =3D 0.0; nulplane.b =3D 0.0f, nulplane.c =3D 0.0f; nulplane.=
d =3D 0.0f;
+ expectedplane.a =3D 0.0f; expectedplane.b =3D 0.0f; expectedplane.c =3D=
0.0f; expectedplane.d =3D 0.0f;
+ D3DXPlaneNormalize(&gotplane, &nulplane);
+ expect_plane(expectedplane, gotplane);
+ nulplane.a =3D 0.0; nulplane.b =3D 0.0f, nulplane.c =3D 0.0f; nulplane.=
d =3D 4.3f;
+ expectedplane.a =3D 0.0f; expectedplane.b =3D 0.0f; expectedplane.c =3D=
0.0f; expectedplane.d =3D 0.0f;
+ D3DXPlaneNormalize(&gotplane, &nulplane);
+ expect_plane(expectedplane, gotplane);
}
=20
static void D3X8QuaternionTest(void)
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index cfe4845..c92535e 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -291,6 +291,8 @@ 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
+D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp);
+
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST =
D3DXQUATERNION *pq);
=20
D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR=
2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g);
--=20
1.5.3.2
--=_p8dbb2nuv9c--
More information about the wine-patches
mailing list