[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43608] trunk/blender/source/blender: use inline BLI_math functions for dot product and length calculation.

Campbell Barton ideasman42 at gmail.com
Sun Jan 22 18:20:47 CET 2012


Revision: 43608
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43608
Author:   campbellbarton
Date:     2012-01-22 17:20:37 +0000 (Sun, 22 Jan 2012)
Log Message:
-----------
use inline BLI_math functions for dot product and length calculation.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_armature.h
    trunk/blender/source/blender/blenkernel/intern/armature.c
    trunk/blender/source/blender/blenlib/intern/BLI_kdtree.c
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/blenlib/intern/noise.c
    trunk/blender/source/blender/editors/object/object_vgroup.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/render/intern/source/convertblender.c
    trunk/blender/source/blender/render/intern/source/occlusion.c
    trunk/blender/source/blender/render/intern/source/pixelshading.c
    trunk/blender/source/blender/render/intern/source/rayshade.c
    trunk/blender/source/blender/render/intern/source/shadbuf.c
    trunk/blender/source/blender/render/intern/source/shadeinput.c
    trunk/blender/source/blender/render/intern/source/volumetric.c

Modified: trunk/blender/source/blender/blenkernel/BKE_armature.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_armature.h	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/blenkernel/BKE_armature.h	2012-01-22 17:20:37 UTC (rev 43608)
@@ -86,7 +86,7 @@
 
 struct Bone *get_named_bone (struct bArmature *arm, const char *name);
 
-float distfactor_to_bone (float vec[3], float b1[3], float b2[3], float rad1, float rad2, float rdist);
+float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3], float rad1, float rad2, float rdist);
 
 void where_is_armature (struct bArmature *arm);
 void where_is_armature_bone(struct Bone *bone, struct Bone *prevbone);

Modified: trunk/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/armature.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/blenkernel/intern/armature.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -665,7 +665,7 @@
 }
 
 /* using vec with dist to bone b1 - b2 */
-float distfactor_to_bone (float vec[3], float b1[3], float b2[3], float rad1, float rad2, float rdist)
+float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3], float rad1, float rad2, float rdist)
 {
 	float dist=0.0f; 
 	float bdelta[3];
@@ -677,18 +677,18 @@
 	
 	sub_v3_v3v3(pdelta, vec, b1);
 	
-	a = bdelta[0]*pdelta[0] + bdelta[1]*pdelta[1] + bdelta[2]*pdelta[2];
-	hsqr = ((pdelta[0]*pdelta[0]) + (pdelta[1]*pdelta[1]) + (pdelta[2]*pdelta[2]));
+	a = dot_v3v3(bdelta, pdelta);
+	hsqr = dot_v3v3(pdelta, pdelta);
 	
-	if (a < 0.0F){
+	if (a < 0.0f) {
 		/* If we're past the end of the bone, do a spherical field attenuation thing */
-		dist= ((b1[0]-vec[0])*(b1[0]-vec[0]) +(b1[1]-vec[1])*(b1[1]-vec[1]) +(b1[2]-vec[2])*(b1[2]-vec[2])) ;
+		dist = len_squared_v3v3(b1, vec);
 		rad= rad1;
 	}
-	else if (a > l){
+	else if (a > l) {
 		/* If we're past the end of the bone, do a spherical field attenuation thing */
-		dist= ((b2[0]-vec[0])*(b2[0]-vec[0]) +(b2[1]-vec[1])*(b2[1]-vec[1]) +(b2[2]-vec[2])*(b2[2]-vec[2])) ;
-		rad= rad2;
+		dist = len_squared_v3v3(b2, vec);
+		rad = rad2;
 	}
 	else {
 		dist= (hsqr - (a*a));
@@ -709,7 +709,7 @@
 		if(rdist==0.0f || dist >= l) 
 			return 0.0f;
 		else {
-			a= (float)sqrt(dist)-rad;
+			a = sqrtf(dist)-rad;
 			return 1.0f-( a*a )/( rdist*rdist );
 		}
 	}

Modified: trunk/blender/source/blender/blenlib/intern/BLI_kdtree.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_kdtree.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/blenlib/intern/BLI_kdtree.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -132,19 +132,18 @@
 	tree->root= kdtree_balance(tree->nodes, tree->totnode, 0);
 }
 
-static float squared_distance(float *v2, float *v1, float *n1, float *n2)
+static float squared_distance(float *v2, float *v1, float *UNUSED(n1), float *n2)
 {
 	float d[3], dist;
-	(void)n1; /* unused */
 
 	d[0]= v2[0]-v1[0];
 	d[1]= v2[1]-v1[1];
 	d[2]= v2[2]-v1[2];
 
-	dist= d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
+	dist = dot_v3v3(d, d);
 
-	//if(n1 && n2 && n1[0]*n2[0] + n1[1]*n2[1] + n1[2]*n2[2] < 0.0f)
-	if(n2 && d[0]*n2[0] + d[1]*n2[1] + d[2]*n2[2] < 0.0f)
+	//if(n1 && n2 && (dot_v3v3(n1, n2) < 0.0f))
+	if(n2 && (dot_v3v3(d, n2) < 0.0f))
 		dist *= 10.0f;
 
 	return dist;

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -2485,8 +2485,9 @@
 		cross_v3_v3v3(ct, tang, tangv);
 	
 		/* check flip */
-		if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f)
+		if (dot_v3v3(ct, n) < 0.0f) {
 			negate_v3(tang);
+		}
 	}
 	else {
 		tang[0]= tang[1]= tang[2]=  0.0;

Modified: trunk/blender/source/blender/blenlib/intern/noise.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/noise.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/blenlib/intern/noise.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -919,10 +919,6 @@
 	{-0.944031, -0.326599, -0.045624},
 };
 
-
-
-#define DOT(a,b) (a[0] * b[0] + a[1] * b[1] + a[2] * b[2])
-
 #define setup(i,b0,b1,r0,r1) \
 		t = vec[i] + 10000.0f; \
 		b0 = ((int)t) & 255; \

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -870,7 +870,7 @@
 	closest_to_plane_v3(projB, coord, norm, end);
 	// (vertical and horizontal refer to the plane's y and xz respectively)
 	// vertical distance
-	dists[index] = norm[0]*end[0] + norm[1]*end[1] + norm[2]*end[2] + d;
+	dists[index] = dot_v3v3(norm, end) + d;
 	// vertical change
 	changes[index][0] = dists[index] - distToStart;
 	//printf("vc %f %f\n", distance(end, projB, 3)-distance(start, projA, 3), changes[index][0]);
@@ -1111,7 +1111,7 @@
 					mag= normalize_v3(norm);
 					if(mag) { /* zeros fix */
 						d = -dot_v3v3(norm, coord);
-						/* dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); */ /* UNUSED */
+						/* dist = (dot_v3v3(norm, m.co) + d); */ /* UNUSED */
 						moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp);
 					}
 				}

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -634,7 +634,7 @@
 
 		sub_v3_v3v3(dvec, newvec, vod->trackvec);
 
-		si= sqrt(dvec[0]*dvec[0]+ dvec[1]*dvec[1]+ dvec[2]*dvec[2]);
+		si = len_v3(dvec);
 		si /= (float)(2.0 * TRACKBALLSIZE);
 
 		cross_v3_v3v3(q1+1, vod->trackvec, newvec);

Modified: trunk/blender/source/blender/render/intern/source/convertblender.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/convertblender.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/render/intern/source/convertblender.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -671,7 +671,7 @@
 			float *tav= RE_vertren_get_tangent(obr, ver, 0);
 			if (tav) {
 				/* orthonorm. */
-				float tdn = tav[0]*ver->n[0] + tav[1]*ver->n[1] + tav[2]*ver->n[2];
+				const float tdn = dot_v3v3(tav, ver->n);
 				tav[0] -= ver->n[0]*tdn;
 				tav[1] -= ver->n[1]*tdn;
 				tav[2] -= ver->n[2]*tdn;
@@ -767,7 +767,7 @@
 	while(asf) {
 		for(a=0; a<4; a++) {
 			if(asf->vlr[a] && asf->vlr[a]!=vlr) {
-				inp= fabs( vlr->n[0]*asf->vlr[a]->n[0] + vlr->n[1]*asf->vlr[a]->n[1] + vlr->n[2]*asf->vlr[a]->n[2] );
+				inp = fabsf(dot_v3v3(vlr->n, asf->vlr[a]->n));
 				if(inp < thresh) return 1;
 			}
 		}
@@ -790,7 +790,7 @@
 			if(asf->vlr[a] && asf->vlr[a]!=vlr) {
 				/* this face already made a copy for this vertex! */
 				if(asf->nver[a]) {
-					inp= fabs( vlr->n[0]*asf->vlr[a]->n[0] + vlr->n[1]*asf->vlr[a]->n[1] + vlr->n[2]*asf->vlr[a]->n[2] );
+					inp = fabsf(dot_v3v3(vlr->n, asf->vlr[a]->n));
 					if(inp >= thresh) {
 						return asf->nver[a];
 					}
@@ -2158,7 +2158,7 @@
 				copy_v3_v3(view, vec);
 				normalize_v3(view);
 
-				zn= nor[0]*view[0]+nor[1]*view[1]+nor[2]*view[2];
+				zn = dot_v3v3(nor, view);
 				if(zn>=0.0f) hasize= 0.0f;
 				else hasize*= zn*zn*zn*zn;
 			}
@@ -2240,9 +2240,9 @@
 		mul_m4_v3(mat, shi->co);
 
 	if(imat) {
-		shi->vn[0]= imat[0][0]*vr->n[0]+imat[0][1]*vr->n[1]+imat[0][2]*vr->n[2];
-		shi->vn[1]= imat[1][0]*vr->n[0]+imat[1][1]*vr->n[1]+imat[1][2]*vr->n[2];
-		shi->vn[2]= imat[2][0]*vr->n[0]+imat[2][1]*vr->n[1]+imat[2][2]*vr->n[2];
+		shi->vn[0] = dot_v3v3(imat[0], vr->n);
+		shi->vn[1] = dot_v3v3(imat[1], vr->n);
+		shi->vn[2] = dot_v3v3(imat[2], vr->n);
 	}
 
 	if (texco & TEXCO_UV) {
@@ -4241,7 +4241,7 @@
 				flen= normal_tri_v3( nor,vlr->v4->co, vlr->v3->co, vlr->v1->co);
 				if(flen==0.0f) normal_tri_v3( nor,vlr->v4->co, vlr->v2->co, vlr->v1->co);
 				
-				xn= nor[0]*vlr->n[0] + nor[1]*vlr->n[1] + nor[2]*vlr->n[2];
+				xn = dot_v3v3(nor, vlr->n);
 
 				if(ABS(xn) < 0.999995f ) {	// checked on noisy fractal grid
 					
@@ -4252,11 +4252,11 @@
 					
 					/* split direction based on vnorms */
 					normal_tri_v3( nor,vlr->v1->co, vlr->v2->co, vlr->v3->co);
-					d1= nor[0]*vlr->v1->n[0] + nor[1]*vlr->v1->n[1] + nor[2]*vlr->v1->n[2];
+					d1 = dot_v3v3(nor, vlr->v1->n);
 
 					normal_tri_v3( nor,vlr->v2->co, vlr->v3->co, vlr->v4->co);
-					d2= nor[0]*vlr->v2->n[0] + nor[1]*vlr->v2->n[1] + nor[2]*vlr->v2->n[2];
-				
+					d2 = dot_v3v3(nor, vlr->v2->n);
+
 					if( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24;
 					else vlr->flag &= ~R_DIVIDE_24;
 
@@ -5267,7 +5267,7 @@
 		if(vec[0]<0.0f) ang= -ang;
 		zco[0]= ang/pixelphix + zmulx;
 		
-		ang= 0.5f*(float)M_PI - saacos(vec[1]/sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]));
+		ang= 0.5f*(float)M_PI - saacos(vec[1] / len_v3(vec));
 		zco[1]= ang/pixelphiy + zmuly;
 		
 	}
@@ -5487,9 +5487,9 @@
 		}
 		
 		// transform (=rotate) to cam space
-		camco[0]= imat[0][0]*fsvec[0] + imat[0][1]*fsvec[1] + imat[0][2]*fsvec[2];
-		camco[1]= imat[1][0]*fsvec[0] + imat[1][1]*fsvec[1] + imat[1][2]*fsvec[2];
-		camco[2]= imat[2][0]*fsvec[0] + imat[2][1]*fsvec[1] + imat[2][2]*fsvec[2];
+		camco[0] = dot_v3v3(imat[0], fsvec);
+		camco[1] = dot_v3v3(imat[1], fsvec);
+		camco[2] = dot_v3v3(imat[2], fsvec);
 
 		// get homogenous coordinates
 		projectvert(camco, winmat, hoco);

Modified: trunk/blender/source/blender/render/intern/source/occlusion.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/occlusion.c	2012-01-22 16:29:10 UTC (rev 43607)
+++ trunk/blender/source/blender/render/intern/source/occlusion.c	2012-01-22 17:20:37 UTC (rev 43608)
@@ -1413,7 +1413,7 @@
 	if(env) {
 		/* sky shading using bent normal */

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list