Module: wine Branch: master Commit: 819362d0f73cce3c24c3db0f4f60167e66b91a40 URL: http://source.winehq.org/git/wine.git/?a=commit;h=819362d0f73cce3c24c3db0f4f...
Author: David Adam David.Adam@math.cnrs.fr Date: Thu Apr 19 21:10:46 2007 +0200
d3drm: Implement D3DRMVectorNormalize.
---
dlls/d3drm/d3drm.spec | 2 +- dlls/d3drm/math.c | 17 +++++++++++++++++ dlls/d3drm/tests/vector.c | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec index 1efbfd4..172f07e 100644 --- a/dlls/d3drm/d3drm.spec +++ b/dlls/d3drm/d3drm.spec @@ -12,7 +12,7 @@ @ stdcall D3DRMVectorCrossProduct(ptr ptr ptr) @ stdcall D3DRMVectorDotProduct(ptr ptr) @ stdcall D3DRMVectorModulus(ptr) -@ stub D3DRMVectorNormalize +@ stdcall D3DRMVectorNormalize(ptr) @ stub D3DRMVectorRandom @ stub D3DRMVectorReflect @ stub D3DRMVectorRotate diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c index 77f176e..8ab947a 100644 --- a/dlls/d3drm/math.c +++ b/dlls/d3drm/math.c @@ -75,6 +75,23 @@ D3DVALUE WINAPI D3DRMVectorModulus(LPD3DVECTOR v) return result; }
+/* Normalize a vector. Returns (1,0,0) if INPUT is the NULL vector. */ +LPD3DVECTOR WINAPI D3DRMVectorNormalize(LPD3DVECTOR u) +{ + D3DVALUE modulus = D3DRMVectorModulus(u); + if(modulus) + { + D3DRMVectorScale(u,u,1.0/modulus); + } + else + { + u->x=1.0; + u->y=0.0; + u->z=0.0; + } + return u; +} + /* Scale a vector */ LPD3DVECTOR WINAPI D3DRMVectorScale(LPD3DVECTOR d, LPD3DVECTOR s, D3DVALUE factor) { diff --git a/dlls/d3drm/tests/vector.c b/dlls/d3drm/tests/vector.c index 6f45801..45d6323 100644 --- a/dlls/d3drm/tests/vector.c +++ b/dlls/d3drm/tests/vector.c @@ -33,7 +33,7 @@ void VectorTest(void) { D3DVALUE mod,par; - D3DVECTOR e,r,u,v; + D3DVECTOR e,r,u,v,casnul;
u.x=2.0;u.y=2.0;u.z=1.0; v.x=4.0;v.y=4.0;v.z=0.0; @@ -61,6 +61,18 @@ void VectorTest(void) mod=D3DRMVectorModulus(&u); ok((mod == 3.0), "Expected 3.0, Got %f",mod);
+/*_______________________VectorNormalize___________________________*/ + D3DRMVectorNormalize(&u); + e.x=2.0/3.0;e.y=2.0/3.0;e.z=1.0/3.0; + expect_vec(e,u); + +/* If u is the NULL vector, MSDN says that the return vector is NULL. In fact, the returned vector is (1,0,0). The following test case prove it. */ + + casnul.x=0.0; casnul.y=0.0; casnul.z=0.0; + D3DRMVectorNormalize(&casnul); + e.x=1.0; e.y=0.0; e.z=0.0; + expect_vec(e,casnul); + /*_______________________VectorScale__________________________*/ par=2.5; D3DRMVectorScale(&r,&v,par);