[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51250] trunk/blender/source/blender/ editors/space_view3d: minor refactor, move view selected rv3d specific logic into its own static function.

Campbell Barton ideasman42 at gmail.com
Wed Oct 10 12:05:56 CEST 2012


Revision: 51250
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51250
Author:   campbellbarton
Date:     2012-10-10 10:05:56 +0000 (Wed, 10 Oct 2012)
Log Message:
-----------
minor refactor, move view selected rv3d specific logic into its own static function.

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	2012-10-10 08:50:56 UTC (rev 51249)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2012-10-10 10:05:56 UTC (rev 51250)
@@ -2282,23 +2282,78 @@
 	RNA_def_boolean(ot->srna, "center", 0, "Center", "");
 }
 
+static void viewselected_rv3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar,
+                                          const float min[3], const float max[3],
+                                          int ok_dist)
+{
+	RegionView3D *rv3d = ar->regiondata;
+	float afm[3];
+	float size;
+
+	/* SMOOTHVIEW */
+	float new_ofs[3];
+	float new_dist;
+
+	sub_v3_v3v3(afm, max, min);
+	size = MAX3(afm[0], afm[1], afm[2]);
+
+	if (ok_dist) {
+		/* fix up zoom distance if needed */
+
+		if (rv3d->is_persp) {
+			if (size <= v3d->near * 1.5f) {
+				/* do not zoom closer than the near clipping plane */
+				size = v3d->near * 1.5f;
+			}
+		}
+		else { /* ortho */
+			if (size < 0.0001f) {
+				/* bounding box was a single point so do not zoom */
+				ok_dist = 0;
+			}
+			else {
+				/* adjust zoom so it looks nicer */
+				size *= 0.7f;
+			}
+		}
+	}
+
+	add_v3_v3v3(new_ofs, min, max);
+	mul_v3_fl(new_ofs, -0.5f);
+
+	new_dist = size;
+
+	/* correction for window aspect ratio */
+	if (ar->winy > 2 && ar->winx > 2) {
+		size = (float)ar->winx / (float)ar->winy;
+		if (size < 1.0f) size = 1.0f / size;
+		new_dist *= size;
+	}
+
+	if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
+		rv3d->persp = RV3D_PERSP;
+		view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
+	}
+	else {
+		view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
+	}
+
+	/* smooth view does viewlock RV3D_BOXVIEW copy */
+}
+
 /* like a localview without local!, was centerview() in 2.4x */
 static int viewselected_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	ARegion *ar = CTX_wm_region(C);
 	View3D *v3d = CTX_wm_view3d(C);
-	RegionView3D *rv3d = CTX_wm_region_view3d(C);
+	RegionView3D *rv3d = ar->regiondata;
 	Scene *scene = CTX_data_scene(C);
 	Object *ob = OBACT;
 	Object *obedit = CTX_data_edit_object(C);
-	float size, min[3], max[3], afm[3];
+	float min[3], max[3];
 	int ok = 0, ok_dist = 1;
 	const short skip_camera = ED_view3d_camera_lock_check(v3d, rv3d);
 
-	/* SMOOTHVIEW */
-	float new_ofs[3];
-	float new_dist;
-
 	INIT_MINMAX(min, max);
 
 	if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) {
@@ -2368,53 +2423,11 @@
 		}
 	}
 
-	if (ok == 0) return OPERATOR_FINISHED;
-
-	sub_v3_v3v3(afm, max, min);
-	size = MAX3(afm[0], afm[1], afm[2]);
-
-	if (ok_dist) {
-		/* fix up zoom distance if needed */
-
-		if (rv3d->is_persp) {
-			if (size <= v3d->near * 1.5f) {
-				/* do not zoom closer than the near clipping plane */
-				size = v3d->near * 1.5f;
-			}
-		}
-		else { /* ortho */
-			if (size < 0.0001f) {
-				/* bounding box was a single point so do not zoom */
-				ok_dist = 0;
-			}
-			else {
-				/* adjust zoom so it looks nicer */
-				size *= 0.7f;
-			}
-		}
+	if (ok == 0) {
+		return OPERATOR_FINISHED;
 	}
 
-	add_v3_v3v3(new_ofs, min, max);
-	mul_v3_fl(new_ofs, -0.5f);
-
-	new_dist = size;
-
-	/* correction for window aspect ratio */
-	if (ar->winy > 2 && ar->winx > 2) {
-		size = (float)ar->winx / (float)ar->winy;
-		if (size < 1.0f) size = 1.0f / size;
-		new_dist *= size;
-	}
-
-	if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
-		rv3d->persp = RV3D_PERSP;
-		view3d_smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
-	}
-	else {
-		view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
-	}
-
-	/* smooth view does viewlock RV3D_BOXVIEW copy */
+	viewselected_rv3d_from_minmax(C, v3d, ar, min, max, ok_dist);
 	
 // XXX	BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
 

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2012-10-10 08:50:56 UTC (rev 51249)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2012-10-10 10:05:56 UTC (rev 51250)
@@ -125,7 +125,7 @@
 /* will start timer if appropriate */
 /* the arguments are the desired situation */
 void view3d_smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera,
-						float *ofs, float *quat, float *dist, float *lens)
+                        float *ofs, float *quat, float *dist, float *lens)
 {
 	wmWindowManager *wm = CTX_wm_manager(C);
 	wmWindow *win = CTX_wm_window(C);
@@ -140,7 +140,7 @@
 	copy_qt_qt(sms.new_quat, rv3d->viewquat);
 	sms.new_dist = rv3d->dist;
 	sms.new_lens = v3d->lens;
-	sms.to_camera = 0;
+	sms.to_camera = FALSE;
 
 	/* note on camera locking, this is a little confusing but works ok.
 	 * we may be changing the view 'as if' there is no active camera, but in fact
@@ -162,22 +162,22 @@
 
 	if (camera) {
 		ED_view3d_from_object(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens);
-		sms.to_camera = 1; /* restore view3d values in end */
+		sms.to_camera = TRUE; /* restore view3d values in end */
 	}
 	
 	if (C && U.smooth_viewtx) {
-		int changed = 0; /* zero means no difference */
+		int changed = FALSE; /* zero means no difference */
 		
 		if (oldcamera != camera)
-			changed = 1;
+			changed = TRUE;
 		else if (sms.new_dist != rv3d->dist)
-			changed = 1;
+			changed = TRUE;
 		else if (sms.new_lens != v3d->lens)
-			changed = 1;
+			changed = TRUE;
 		else if (!equals_v3v3(sms.new_ofs, rv3d->ofs))
-			changed = 1;
+			changed = TRUE;
 		else if (!equals_v4v4(sms.new_quat, rv3d->viewquat))
-			changed = 1;
+			changed = TRUE;
 		
 		/* The new view is different from the old one
 		 * so animate the view */
@@ -241,7 +241,7 @@
 	
 	/* if we get here nothing happens */
 	if (ok == FALSE) {
-		if (sms.to_camera == 0) {
+		if (sms.to_camera == FALSE) {
 			copy_v3_v3(rv3d->ofs, sms.new_ofs);
 			copy_qt_qt(rv3d->viewquat, sms.new_quat);
 			rv3d->dist = sms.new_dist;




More information about the Bf-blender-cvs mailing list