make api functions for converting rv3d->camzoom, so the odd logic for this isn't...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 20 May 2011 04:14:29 +0000 (04:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 20 May 2011 04:14:29 +0000 (04:14 +0000)
source/blender/blenkernel/BKE_screen.h
source/blender/blenkernel/intern/screen.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/makesdna/DNA_view3d_types.h
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp

index 56b0cd63e0109a07cf691bcc16df91e60c8505b3..bc443b4a3a63c33d7ee4ad8a5bbb3c975d244196 100644 (file)
@@ -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); 
index 63e35408381eefe2ddf652c996cac34b80682941..3207975c6f9d97408628af9dddac15947ddfbffa 100644 (file)
@@ -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);
+}
index 4ef02243cd5d27de3fa6dd292d1b5251e240ade7..804cea57195fe7dcc5e9daf2d43f34c81aa57dcf 100644 (file)
@@ -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;
        
index f0f7735343586477d9a3b219060384ae21e63417..897114b5a3f427a9e00c525d6a9d419bf149b100 100644 (file)
@@ -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))
index dc8979e0bf3431a205eb23aa28250018bc4cb623..41b26e4a715dcb3e018cdd7b49061bd19d094f5c 100644 (file)
@@ -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) {
index f4b4ef37ad997b336717a467dde5b9cabda2facc..7379493003d2fd90f8dab84c082775a75c108865 100644 (file)
@@ -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) */
index 4789155dcedf915ba1a5dc96931bb3b2c5a66d45..59c5888ff35bc903d8ab028019b088c126e302b5 100644 (file)
@@ -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 {