diff options
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 16 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 8 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view3d_types.h | 2 | ||||
-rw-r--r-- | source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp | 6 |
7 files changed, 40 insertions, 29 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 56b0cd63e01..bc443b4a3a6 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -246,6 +246,9 @@ void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene); void BKE_screen_view3d_scene_sync(struct bScreen *sc); void BKE_screen_view3d_main_sync(ListBase *screen_lb, struct Scene *scene); +/* zoom factor conversion */ +float BKE_screen_view3d_zoom_to_fac(float camzoom); +float BKE_screen_view3d_zoom_from_fac(float zoomfac); /* screen */ void free_screen(struct bScreen *sc); diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 63e35408381..3207975c6f9 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -416,3 +416,20 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene) } } +/* magic zoom calculation, no idea what + * it signifies, if you find out, tell me! -zr + */ + +/* simple, its magic dude! + * well, to be honest, this gives a natural feeling zooming + * with multiple keypad presses (ton) + */ +float BKE_screen_view3d_zoom_to_fac(float camzoom) +{ + return powf(((float)M_SQRT2 + camzoom/50.0f), 2.0f) / 4.0f; +} + +float BKE_screen_view3d_zoom_from_fac(float zoomfac) +{ + return ((sqrtf(4.0f * zoomfac) - (float)M_SQRT2) * 50.0f); +} diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 4ef02243cd5..804cea57195 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -61,6 +61,7 @@ #include "BKE_global.h" #include "BKE_paint.h" #include "BKE_scene.h" +#include "BKE_screen.h" #include "BKE_unit.h" #include "RE_pipeline.h" // make_stars @@ -870,25 +871,15 @@ void view3d_viewborder_size_get(Scene *scene, ARegion *ar, float size_r[2]) void view3d_calc_camera_border(Scene *scene, ARegion *ar, RegionView3D *rv3d, View3D *v3d, rctf *viewborder_r, short do_shift) { - float zoomfac, size[2]; + const float zoomfac= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); + float size[2]; float dx= 0.0f, dy= 0.0f; view3d_viewborder_size_get(scene, ar, size); if (rv3d == NULL) rv3d = ar->regiondata; - - /* magic zoom calculation, no idea what - * it signifies, if you find out, tell me! -zr - */ - /* simple, its magic dude! - * well, to be honest, this gives a natural feeling zooming - * with multiple keypad presses (ton) - */ - - zoomfac= ((float)M_SQRT2 + rv3d->camzoom/50.0f); - zoomfac= (zoomfac*zoomfac) * 0.25f; - + size[0]= size[0]*zoomfac; size[1]= size[1]*zoomfac; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index f0f77353435..897114b5a3f 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -56,6 +56,7 @@ #include "BKE_paint.h" #include "BKE_report.h" #include "BKE_scene.h" +#include "BKE_screen.h" #include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */ @@ -919,14 +920,11 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf) static void viewmove_apply(ViewOpsData *vod, int x, int y) { if((vod->rv3d->persp==RV3D_CAMOB) && !(vod->v3d->flag2 & V3D_LOCK_CAMERA)) { - float zoomfac= ((float)M_SQRT2 + (float)vod->rv3d->camzoom / 50.0f); - zoomfac= (zoomfac * zoomfac) * 0.5f; - + const float zoomfac= BKE_screen_view3d_zoom_to_fac((float)vod->rv3d->camzoom) * 2.0f; vod->rv3d->camdx += (vod->oldx - x)/(vod->ar->winx * zoomfac); vod->rv3d->camdy += (vod->oldy - y)/(vod->ar->winy * zoomfac); CLAMP(vod->rv3d->camdx, -1.0f, 1.0f); CLAMP(vod->rv3d->camdy, -1.0f, 1.0f); -// XXX preview3d_event= 0; } else { float dvec[3]; @@ -1888,8 +1886,8 @@ static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was xfac= (float)ar->winx / (float)(size[0] + 4); yfac= (float)ar->winy / (float)(size[1] + 4); - rv3d->camzoom= (sqrtf(4.0f * MIN2(xfac, yfac)) - (float)M_SQRT2) * 50.0f; - rv3d->camzoom= CLAMPIS(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); + rv3d->camzoom= BKE_screen_view3d_zoom_from_fac(MIN2(xfac, yfac)); + CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C)); @@ -2145,9 +2143,9 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar) int im_width= (scene->r.size*scene->r.xsch)/100; view3d_viewborder_size_get(scene, ar, size); - - rv3d->camzoom= (sqrtf(4.0f * (float)im_width/size[0]) - (float)M_SQRT2) * 50.0f; - rv3d->camzoom= CLAMPIS(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); + + rv3d->camzoom= BKE_screen_view3d_zoom_from_fac((float)im_width/size[0]); + CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); } static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index dc8979e0bf3..41b26e4a715 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -52,6 +52,7 @@ #include "BKE_main.h" #include "BKE_report.h" #include "BKE_scene.h" +#include "BKE_screen.h" #include "BIF_gl.h" #include "BIF_glutil.h" @@ -995,10 +996,11 @@ int get_view3d_viewplane(View3D *v3d, RegionView3D *rv3d, int winxi, int winyi, else { /* fac for zoom, also used for camdx */ if(rv3d->persp==RV3D_CAMOB) { - fac= (1.41421f + ( (float)rv3d->camzoom )/50.0f); - fac*= fac; + fac= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom) * 4.0f; + } + else { + fac= 2.0; } - else fac= 2.0; /* viewplane size depends... */ if(cam && cam->type==CAM_ORTHO) { diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index f4b4ef37ad9..7379493003d 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -98,7 +98,7 @@ typedef struct RegionView3D { float pixsize; /* runtime only */ float ofs[3]; /* view center & orbit pivot, negative of worldspace location, * also matches -viewinv[3][0:3] in ortho mode.*/ - short camzoom; + short camzoom; /* viewport zoom on the camera frame, see BKE_screen_view3d_zoom_to_fac */ short twdrawflag; char is_persp; /* check if persp/ortho view, since 'persp' cant be used for this since * it can have cameras assigned as well. (only set in setwinmatrixview3d) */ diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 4789155dced..59c5888ff35 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -81,6 +81,8 @@ extern "C" { #include "DNA_windowmanager_types.h" #include "BKE_global.h" #include "BKE_report.h" +/* #include "BKE_screen.h" */ /* cant include this because of 'new' function name */ +extern float BKE_screen_view3d_zoom_to_fac(float camzoom); //XXX #include "BIF_screen.h" @@ -254,9 +256,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c camzoom = 1.0f; } else { - camzoom = (1.41421 + (rv3d->camzoom / 50.0)); - camzoom *= camzoom; - camzoom = 4.0 / camzoom; + camzoom = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); } } else { |