patch [8/15]: Implements D3DRMVectorNormalize [try 2]

David.Adam at math.cnrs.fr David.Adam at math.cnrs.fr
Thu Apr 19 14:10:46 CDT 2007


-------------- next part --------------
>From 35ed20106c51188027b636fe12f4d57f2d5b654b Mon Sep 17 00:00:00 2001
From: Adam <David.Adam at math.cnrs.fr>
Date: Fri, 20 Apr 2007 02:05:05 +0200
Subject: [PATCH] Implements D3DVectorNormalize with test.

---
 dlls/d3drm/d3drm.spec     |    2 +-
 dlls/d3drm/math.c         |   16 ++++++++++++++++
 dlls/d3drm/tests/vector.c |   14 +++++++++++++-
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec
index d534719..d5ccb2a 100644
--- a/dlls/d3drm/d3drm.spec
+++ b/dlls/d3drm/d3drm.spec
@@ -12,7 +12,7 @@
 @ stdcall D3DRMVectorCrossProduct(ptr ptr ptr)
 @ stdcall D3DRMVectorDotProduct(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 4c68665..5f9d85d 100644
--- a/dlls/d3drm/math.c
+++ b/dlls/d3drm/math.c
@@ -74,6 +74,22 @@ D3DVALUE WINAPI D3DRMVectorModulus(LPD3D
     return result;
 }
 
+/* Normalize a vector.  Returns (1,0,0) if INPUT is the NULL vector. */
+LPD3DVECTOR WINAPI D3DRMVectorNormalize(LPD3DVECTOR u)
+{
+    D3DVALUE modulus;
+    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 439ba6b..ad8cd39 100644
--- a/dlls/d3drm/tests/vector.c
+++ b/dlls/d3drm/tests/vector.c
@@ -33,7 +33,7 @@ #define expect_vec(expectedvec,gotvec) \
 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);
-- 
1.4.2



More information about the wine-patches mailing list