minor speedup to VectorNormalize #define's
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 16 Oct 2000 20:46:19 +0000 (20:46 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 16 Oct 2000 20:46:19 +0000 (20:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@52 d7cf8633-e32d-0410-b094-e92efae38249

mathlib.h

index 881b243..42c76ea 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -45,8 +45,8 @@ extern        int nanmask;
 #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
 #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
 #define CrossProduct(v1,v2,cross) {cross[0] = v1[1]*v2[2] - v1[2]*v2[1];cross[1] = v1[2]*v2[0] - v1[0]*v2[2];cross[2] = v1[0]*v2[1] - v1[1]*v2[0];}
-#define VectorNormalize(v) {float ilength;if ((ilength = sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]))) {ilength = 1/ilength;v[0] *= ilength;v[1] *= ilength;v[2] *= ilength;}}
-#define VectorNormalize2(v,dest) {float ilength;if ((ilength = sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]))) {ilength = 1/ilength;dest[0] = v[0] * ilength;dest[1] = v[1] * ilength;dest[2] = v[2] * ilength;}}
+#define VectorNormalize(v) {float ilength = 1.0f / (float) sqrt(DotProduct(v,v));v[0] *= ilength;v[1] *= ilength;v[2] *= ilength;}
+#define VectorNormalize2(v,dest) {float ilength = 1.0f / (float) sqrt(DotProduct(v,v));dest[0] = v[0] * ilength;dest[1] = v[1] * ilength;dest[2] = v[2] * ilength;}
 #define VectorDistance2(a, b) ((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]))
 #define VectorDistance(a, b) sqrt(VectorDistance(a,b))
 #define VectorLength(a) sqrt(DotProduct(a, a))