diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-11-30 10:10:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-11-30 10:10:01 +0400 |
commit | 6bb45495d11e6547c847aee59dc86ca28adf472b (patch) | |
tree | 81ee3e9a5d77d8fb2cbef5ce85757be566d03eed /source/blender | |
parent | 7a1dfa298a384b262aa879de8aad648275d6a1ff (diff) |
fix for r51636 - making the lens work in ortho mode made view-all and local-view operators give bad zoom levels.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 1 | ||||
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 17 |
4 files changed, 17 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 9118baeae6f..57c88919021 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -267,6 +267,7 @@ void BKE_camera_params_from_view3d(CameraParams *params, View3D *v3d, RegionView 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; } diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 01a9b4cf74a..269a932dcf5 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -219,7 +219,9 @@ 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(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]); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 1c34ff39339..434d8ee338b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2238,7 +2238,7 @@ static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar, 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); @@ -2250,7 +2250,7 @@ static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar, } else { /* adjust zoom so it looks nicer */ - size *= 0.7f; + size = ED_view3d_radius_to_ortho_dist(v3d->lens, size / 2.0f); } } } diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index eb065de98da..15928204920 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1029,7 +1029,7 @@ static int view3d_localview_init(Main *bmain, Scene *scene, ScrArea *sa, ReportL 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; @@ -1074,7 +1074,8 @@ static int view3d_localview_init(Main *bmain, Scene *scene, ScrArea *sa, ReportL 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) { @@ -1103,7 +1104,7 @@ static int view3d_localview_init(Main *bmain, Scene *scene, ScrArea *sa, ReportL rv3d->dist = size_persp; } else { - rv3d->dist = size * 0.7f; + rv3d->dist = size_ortho; } /* correction for window aspect ratio */ @@ -1526,10 +1527,14 @@ float ED_view3d_pixel_size(RegionView3D *rv3d, const float co[3]) ) * 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 */ |