Commits

Anonymous committed 7ab4889

fix for r51636 - making the lens work in ortho mode made view-all and local-view operators give bad zoom levels.

git-svn-id: https://svn.blender.org/svnroot/bf-blender/trunk@52673954f8c5b-7b00-dc11-b283-0030488c597c

Comments (0)

Files changed (4)

blender/source/blender/blenkernel/intern/camera.c

 		params->clipsta = -params->clipend;
 
 		params->is_ortho = TRUE;
+		/* make sure any changes to this match ED_view3d_radius_to_ortho_dist() */
 		params->ortho_scale = rv3d->dist * sensor_size / v3d->lens;
 		params->zoom = 2.0f;
 	}

blender/source/blender/editors/include/ED_view3d.h

 void ED_view3d_clipping_disable(void);
 
 float ED_view3d_pixel_size(struct RegionView3D *rv3d, const float co[3]);
-float ED_view3d_dist_from_radius(const float angle, const float radius);
+
+float ED_view3d_radius_to_persp_dist(const float angle, const float radius);
+float ED_view3d_radius_to_ortho_dist(const float lens, const float radius);
 
 void drawcircball(int mode, const float cent[3], float rad, float tmat[][4]);
 

blender/source/blender/editors/space_view3d/view3d_edit.c

 				lens = v3d->lens;
 				sensor_size = DEFAULT_SENSOR_WIDTH;
 			}
-			size = ED_view3d_dist_from_radius(focallength_to_fov(lens, sensor_size), size / 2.0f);
+			size = ED_view3d_radius_to_persp_dist(focallength_to_fov(lens, sensor_size), size / 2.0f);
 
 			/* do not zoom closer than the near clipping plane */
 			size = max_ff(size, v3d->near * 1.5f);
 			}
 			else {
 				/* adjust zoom so it looks nicer */
-				size *= 0.7f;
+				size = ED_view3d_radius_to_ortho_dist(v3d->lens, size / 2.0f);
 			}
 		}
 	}

blender/source/blender/editors/space_view3d/view3d_view.c

 	View3D *v3d = sa->spacedata.first;
 	Base *base;
 	float min[3], max[3], box[3];
-	float size = 0.0, size_persp;
+	float size = 0.0f, size_persp = 0.0f, size_ortho = 0.0f;
 	unsigned int locallay;
 	int ok = FALSE;
 
 		size = max_ff(size, v3d->near * 1.5f);
 
 		/* perspective size (we always switch out of camera view so no need to use its lens size) */
-		size_persp = ED_view3d_dist_from_radius(focallength_to_fov(v3d->lens, DEFAULT_SENSOR_WIDTH), size / 2.0f);
+		size_persp = ED_view3d_radius_to_persp_dist(focallength_to_fov(v3d->lens, DEFAULT_SENSOR_WIDTH), size / 2.0f);
+		size_ortho = ED_view3d_radius_to_ortho_dist(v3d->lens, size / 2.0f);
 	}
 	
 	if (ok == TRUE) {
 					rv3d->dist = size_persp;
 				}
 				else {
-					rv3d->dist = size * 0.7f;
+					rv3d->dist = size_ortho;
 				}
 
 				/* correction for window aspect ratio */
 	        ) * rv3d->pixsize;
 }
 
-/* use for perspective view only */
-float ED_view3d_dist_from_radius(const float angle, const float radius)
+float ED_view3d_radius_to_persp_dist(const float angle, const float radius)
 {
-	return radius * fabsf(1.0f / cosf((((float)M_PI) - angle) / 2.0f));
+	return (radius / 2.0f) * fabsf(1.0f / cosf((((float)M_PI) - angle) / 2.0f));
+}
+
+float ED_view3d_radius_to_ortho_dist(const float lens, const float radius)
+{
+	return radius / (DEFAULT_SENSOR_WIDTH / lens);
 }
 
 /* view matrix properties utilities */