make previous commit work when the camera is locked to the view (in that case use the camera lens, not the viewport lens value).

This commit is contained in:
Campbell Barton
2012-11-30 04:40:32 +00:00
parent c3406db4f5
commit 8c3df03c5f
3 changed files with 18 additions and 5 deletions

View File

@@ -219,7 +219,7 @@ void ED_view3d_clipping_enable(void);
void ED_view3d_clipping_disable(void);
float ED_view3d_pixel_size(struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_dist_from_radius(struct View3D *v3d, const float radius);
float ED_view3d_dist_from_radius(const float angle, const float radius);
void drawcircball(int mode, const float cent[3], float rad, float tmat[][4]);

View File

@@ -2224,8 +2224,22 @@ static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar,
/* fix up zoom distance if needed */
if (rv3d->is_persp) {
float lens, sensor_size;
/* offset the view based on the lens */
size = ED_view3d_dist_from_radius(v3d, size / 2.0f);
if (rv3d->persp == RV3D_CAMOB && ED_view3d_camera_lock_check(v3d, rv3d)) {
CameraParams params;
BKE_camera_params_init(&params);
BKE_camera_params_from_object(&params, v3d->camera);
lens = params.lens;
sensor_size = BKE_camera_sensor_size(params.sensor_fit, params.sensor_x, params.sensor_y);
}
else {
lens = v3d->lens;
sensor_size = DEFAULT_SENSOR_WIDTH;
}
size = ED_view3d_dist_from_radius(focallength_to_fov(lens, sensor_size), size / 2.0f);
if (size <= v3d->near * 1.5f) {
/* do not zoom closer than the near clipping plane */
size = v3d->near * 1.5f;

View File

@@ -1521,10 +1521,9 @@ float ED_view3d_pixel_size(RegionView3D *rv3d, const float co[3])
}
/* use for perspective view only */
float ED_view3d_dist_from_radius(View3D *v3d, const float radius)
float ED_view3d_dist_from_radius(const float angle, const float radius)
{
const float angle = (((float)M_PI) - focallength_to_fov(v3d->lens, DEFAULT_SENSOR_WIDTH));
return radius * fabsf(1.0f / cosf(angle / 2.0f));
return radius * fabsf(1.0f / cosf((((float)M_PI) - angle) / 2.0f));
}
/* view matrix properties utilities */