[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27142] trunk/blender/source/blender/ editors/space_view3d: use math functions in view code, no functional changes.

Campbell Barton ideasman42 at gmail.com
Thu Feb 25 21:26:38 CET 2010


Revision: 27142
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27142
Author:   campbellbarton
Date:     2010-02-25 21:26:38 +0100 (Thu, 25 Feb 2010)

Log Message:
-----------
use math functions in view code, no functional changes.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2010-02-25 20:21:09 UTC (rev 27141)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2010-02-25 20:26:38 UTC (rev 27142)
@@ -110,9 +110,7 @@
 
 					if(ar->winx>ar->winy) y1= ar->winy*rv3d->dist/ar->winx;
 					else y1= rv3d->dist;
-
-					ofs[0]= rv3d->ofs[0];
-					ofs[1]= rv3d->ofs[1];
+					copy_v2_v2(ofs, rv3d->ofs);
 				}
 				else if(ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
 					ofs[2]= rv3d->ofs[2];
@@ -372,8 +370,7 @@
 				closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin);
 				vod->dist0 = rv3d->dist = len_v3v3(my_pivot, dvec);
 
-				negate_v3(dvec);
-				VECCOPY(rv3d->ofs, dvec);
+				negate_v3_v3(rv3d->ofs, dvec);
 			}
 			negate_v3(vod->dyn_ofs);
 			VECCOPY(vod->ofs, rv3d->ofs);
@@ -548,11 +545,8 @@
 			* dragged. */
 		phi = si * M_PI / 2.0;
 
-		si= sin(phi);
 		q1[0]= cos(phi);
-		q1[1]*= si;
-		q1[2]*= si;
-		q1[3]*= si;
+		mul_v3_fl(q1+1, sin(phi));
 		mul_qt_qtqt(rv3d->viewquat, q1, vod->oldquat);
 
 		if (vod->use_dyn_ofs) {
@@ -570,7 +564,7 @@
 	}
 	else {
 		/* New turntable view code by John Aughey */
-		float si, phi, q1[4];
+		float phi, q1[4];
 		float m[3][3];
 		float m_inv[3][3];
 		float xvec[3] = {1,0,0};
@@ -590,11 +584,8 @@
 
 		/* Perform the up/down rotation */
 		phi = sensitivity * -(y - vod->oldy);
-		si = sin(phi);
 		q1[0] = cos(phi);
-		q1[1] = si * xvec[0];
-		q1[2] = si * xvec[1];
-		q1[3] = si * xvec[2];
+		mul_v3_v3fl(q1+1, xvec, sin(phi));
 		mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1);
 
 		if (vod->use_dyn_ofs) {
@@ -635,12 +626,10 @@
 
 			if ((dot_v3v3(snapmat[0], viewmat[0]) > thres) &&
 				(dot_v3v3(snapmat[1], viewmat[1]) > thres) &&
-				(dot_v3v3(snapmat[2], viewmat[2]) > thres)){
-
-				QUATCOPY(rv3d->viewquat, snapquats[i]);
-
-				rv3d->view = view;
-
+				(dot_v3v3(snapmat[2], viewmat[2]) > thres)
+			) {
+				copy_qt_qt(rv3d->viewquat, snapquats[i]);
+				rv3d->view= view;
 				break;
 			}
 		}
@@ -969,18 +958,15 @@
 		vb[0] = ar->winx;
 		vb[1] = ar->winy;
 
-		tpos[0] = -rv3d->ofs[0];
-		tpos[1] = -rv3d->ofs[1];
-		tpos[2] = -rv3d->ofs[2];
+		negate_v3_v3(tpos, rv3d->ofs);
 
 		/* Project cursor position into 3D space */
 		initgrabz(rv3d, tpos[0], tpos[1], tpos[2]);
 		window_to_3d_delta(ar, dvec, mouseloc[0]-vb[0]/2, mouseloc[1]-vb[1]/2);
 
 		/* Calculate view target position for dolly */
-		tvec[0] = -(tpos[0] + dvec[0]);
-		tvec[1] = -(tpos[1] + dvec[1]);
-		tvec[2] = -(tpos[2] + dvec[2]);
+		add_v3_v3v3(tvec, tpos, dvec);
+		negate_v3(tvec);
 
 		/* Offset to target position and dolly */
 		new_dist = rv3d->dist * dfac;
@@ -989,11 +975,7 @@
 		rv3d->dist = new_dist;
 
 		/* Calculate final offset */
-		dvec[0] = tvec[0] + dvec[0] * dfac;
-		dvec[1] = tvec[1] + dvec[1] * dfac;
-		dvec[2] = tvec[2] + dvec[2] * dfac;
-
-		VECCOPY(rv3d->ofs, dvec);
+		madd_v3_v3v3fl(rv3d->ofs, tvec, dvec, dfac);
 	} else {
 		rv3d->dist *= dfac;
 	}
@@ -1407,9 +1389,7 @@
 
 	if(ok==0) return OPERATOR_FINISHED;
 
-	afm[0]= (max[0]-min[0]);
-	afm[1]= (max[1]-min[1]);
-	afm[2]= (max[2]-min[2]);
+	sub_v3_v3v3(afm, max, min);
 	size= MAX3(afm[0], afm[1], afm[2]);
 
 	if(rv3d->persp==RV3D_ORTHO) {
@@ -1427,10 +1407,7 @@
 		}
 	}
 
-	new_ofs[0]= -(min[0]+max[0])/2.0f;
-	new_ofs[1]= -(min[1]+max[1])/2.0f;
-	new_ofs[2]= -(min[2]+max[2])/2.0f;
-
+	madd_v3_v3v3fl(new_ofs, min, max, -0.5f);
 	new_dist = size;
 
 	/* correction for window aspect ratio */
@@ -1703,9 +1680,7 @@
 			new_ofs[2] = -p[2];
 		} else {
 			/* We cant use the depth, fallback to the old way that dosnt set the center depth */
-			new_ofs[0] = rv3d->ofs[0];
-			new_ofs[1] = rv3d->ofs[1];
-			new_ofs[2] = rv3d->ofs[2];
+			copy_v3_v3(new_ofs, rv3d->ofs);
 
 			initgrabz(rv3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]);
 
@@ -1979,7 +1954,7 @@
 static int vieworbit_exec(bContext *C, wmOperator *op)
 {
 	RegionView3D *rv3d= CTX_wm_region_view3d(C);
-	float phi, si, q1[4], new_quat[4];
+	float phi, q1[4], new_quat[4];
 	int orbitdir;
 
 	orbitdir = RNA_enum_get(op->ptr, "type");
@@ -1988,6 +1963,7 @@
 
 		if(rv3d->persp != RV3D_CAMOB) {
 			if(orbitdir == V3D_VIEW_STEPLEFT || orbitdir == V3D_VIEW_STEPRIGHT) {
+				float si;
 				/* z-axis */
 				phi= (float)(M_PI/360.0)*U.pad_rot_angle;
 				if(orbitdir == V3D_VIEW_STEPRIGHT) phi= -phi;
@@ -2005,11 +1981,8 @@
 				normalize_v3(q1+1);
 				phi= (float)(M_PI/360.0)*U.pad_rot_angle;
 				if(orbitdir == V3D_VIEW_STEPDOWN) phi= -phi;
-				si= (float)sin(phi);
 				q1[0]= (float)cos(phi);
-				q1[1]*= si;
-				q1[2]*= si;
-				q1[3]*= si;
+				mul_v3_fl(q1+1, sin(phi));
 				mul_qt_qtqt(new_quat, rv3d->viewquat, q1);
 				rv3d->view= 0;
 			}
@@ -2812,7 +2785,7 @@
 	float xvec[3] = {1,0,0};
 	float yvec[3] = {0,-1,0};
 	float zvec[3] = {0,0,1};
-	float phi, si;
+	float phi;
 	float q1[4];
 	float obofs[3];
 	float reverse;
@@ -2961,11 +2934,8 @@
 
     /* Perform the up/down rotation */
     phi = sbadjust * rsens * /*0.5f * */ fval[3]; /* spin vertically half as fast as horizontally */
-    si = sin(phi);
     q1[0] = cos(phi);
-    q1[1] = si * xvec[0];
-    q1[2] = si * xvec[1];
-    q1[3] = si * xvec[2];
+    mul_v3_v3fl(q1+1, xvec, sin(phi));
     mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1);
 
     if (use_sel) {

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2010-02-25 20:21:09 UTC (rev 27141)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2010-02-25 20:26:38 UTC (rev 27142)
@@ -404,13 +404,9 @@
 {
 	float dvec[3];
 	float mat3[3][3];
-	
-	dvec[0]= rv3d->dist*rv3d->viewinv[2][0];
-	dvec[1]= rv3d->dist*rv3d->viewinv[2][1];
-	dvec[2]= rv3d->dist*rv3d->viewinv[2][2];
-	
-	VECCOPY(ob->loc, dvec);
-	sub_v3_v3v3(ob->loc, ob->loc, rv3d->ofs);
+
+	mul_v3_v3fl(dvec, rv3d->viewinv[2], rv3d->dist);
+	sub_v3_v3v3(ob->loc, dvec, rv3d->ofs);
 	rv3d->viewquat[0]= -rv3d->viewquat[0];
 
 	// quat_to_eul( ob->rot,rv3d->viewquat); // in 2.4x for xyz eulers only
@@ -602,9 +598,7 @@
 		p2[3] = 1.0f;
 		mul_m4_v4(rv3d->viewmat, p2);
 
-		p2[0] = 2.0f * p2[0];
-		p2[1] = 2.0f * p2[1];
-		p2[2] = 2.0f * p2[2];
+		mul_v3_fl(p2, 2.0f);
 
 		mul_m4_v4(rv3d->viewinv, p2);
 
@@ -2612,10 +2606,9 @@
 	
 	if(axisidx > 0) alignaxis[axisidx-1]= 1.0;
 	else alignaxis[-axisidx-1]= -1.0;
-	
-	VECCOPY(norm, vec);
-	normalize_v3(norm);
-	
+
+	normalize_v3_v3(norm, vec);
+
 	angle= (float)acos(dot_v3v3(alignaxis, norm));
 	cross_v3_v3v3(axis, alignaxis, norm);
 	axis_angle_to_quat( new_quat,axis, -angle);





More information about the Bf-blender-cvs mailing list