Module: wine Branch: master Commit: 8abfaa04cc31763c5b048fdeace3934df0bfbfb3 URL: http://source.winehq.org/git/wine.git/?a=commit;h=8abfaa04cc31763c5b048fdeac...
Author: David Adam David.Adam@math.cnrs.fr Date: Thu Nov 15 11:27:19 2007 +0100
d3dx8: Implement D3DXPlaneNormalize.
---
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; }
+/*_________________D3DXPLANE________________*/ + +D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp) +{ + FLOAT norm; + + norm = sqrt(pp->a * pp->a + pp->b * pp->b + pp->c * pp->c); + if ( norm ) + { + pout->a = pp->a / norm; + pout->b = pp->b / norm; + pout->c = pp->c / norm; + pout->d = pp->d / norm; + } + else + { + pout->a = 0.0f; + pout->b = 0.0f; + pout->c = 0.0f; + pout->d = 0.0f; + } + return pout; +} + /*_________________D3DXQUATERNION________________*/
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]); \ }
+#define expect_plane(expectedplane,gotplane) ok((fabs(expectedplane.a-gotplane.a)<admitted_error)&&(fabs(expectedplane.b-gotplane.b)<admitted_error)&&(fabs(expectedplane.c-gotplane.c)<admitted_error)&&(fabs(expectedplane.d-gotplane.d)<admitted_error),"Expected Plane= (%f, %f, %f, %f)\n , Got Plane= (%f, %f, %f, %f)\n", expectedplane.a, expectedplane.b, expectedplane.c, expectedplane.d, gotplane.a, gotplane.b, gotplane.c, gotplane.d); + #define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
#define expect_vec3(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expectedvec.z-gotvec.z)<admitted_error),"Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.x, gotvec.y, gotvec.z); @@ -413,7 +415,7 @@ static void D3DXMatrixTest(void)
static void D3DXPlaneTest(void) { - D3DXPLANE plane; + D3DXPLANE expectedplane, gotplane, nulplane, plane; D3DXVECTOR4 vec; FLOAT expected, got;
@@ -452,6 +454,19 @@ static void D3DXPlaneTest(void) expected = 0.0f; got = D3DXPlaneDotNormal(NULL,NULL), ok( expected == got, "Expected : %f, Got : %f\n",expected, got); + +/*_______________D3DXPlaneDotNormalize______________*/ + expectedplane.a = -3.0f/sqrt(26.0f); expectedplane.b = -1.0f/sqrt(26.0f); expectedplane.c = 4.0f/sqrt(26.0f); expectedplane.d = 7.0/sqrt(26.0f); + D3DXPlaneNormalize(&gotplane, &plane); + expect_plane(expectedplane, gotplane); + nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f; + expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f; + D3DXPlaneNormalize(&gotplane, &nulplane); + expect_plane(expectedplane, gotplane); + nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 4.3f; + expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f; + D3DXPlaneNormalize(&gotplane, &nulplane); + expect_plane(expectedplane, gotplane); }
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, FLOAT sx, FLOAT sy, FLOAT D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pout, FLOAT x, FLOAT y, FLOAT z); D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout, CONST D3DXMATRIX *pm);
+D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp); + D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g);