[Bf-blender-cvs] [f2e3af68be4] wintab_fallback_walknav: Cleanup: Swap defines for static const in walk and fly mode.

Nicholas Rishel noreply at git.blender.org
Fri Jul 9 09:04:44 CEST 2021


Commit: f2e3af68be439cab143e8b53d38f9b6293aeaddb
Author: Nicholas Rishel
Date:   Thu Jul 8 14:50:50 2021 -0700
Branches: wintab_fallback_walknav
https://developer.blender.org/rBf2e3af68be439cab143e8b53d38f9b6293aeaddb

Cleanup: Swap defines for static const in walk and fly mode.

===================================================================

M	source/blender/editors/space_view3d/view3d_navigate_fly.c
M	source/blender/editors/space_view3d/view3d_navigate_walk.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_navigate_fly.c b/source/blender/editors/space_view3d/view3d_navigate_fly.c
index e2fa0fdc6a5..2d819ced3b7 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_fly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_fly.c
@@ -752,10 +752,14 @@ static void flyMoveCamera(bContext *C,
 
 static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
 {
-#define FLY_ROTATE_FAC 10.0f        /* more is faster */
-#define FLY_ZUP_CORRECT_FAC 0.1f    /* amount to correct per step */
-#define FLY_ZUP_CORRECT_ACCEL 0.05f /* increase upright momentum each step */
-#define FLY_SMOOTH_FAC 20.0f        /* higher value less lag */
+  /* Higher is faster. */
+  static const float fly_rotate_factor = 10.0f;
+  /* Amount to correct per step. */
+  static const float fly_z_up_correct_factor = 0.1f;
+  /* Increase upright momentum each step. */
+  static const float fly_z_up_correct_accel = 0.05f;
+  /* Higher is less lag. */
+  static const float fly_smooth_factor = 20.0f;
 
   RegionView3D *rv3d = fly->rv3d;
 
@@ -875,7 +879,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
           copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
           mul_m3_v3(mat, upvec);
           /* Rotate about the relative up vec */
-          axis_angle_to_quat(tmp_quat, upvec, moffset[1] * time_redraw * -FLY_ROTATE_FAC);
+          axis_angle_to_quat(tmp_quat, upvec, moffset[1] * time_redraw * -fly_rotate_factor);
           mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
 
           if (fly->xlock != FLY_AXISLOCK_STATE_OFF) {
@@ -908,7 +912,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
           }
 
           /* Rotate about the relative up vec */
-          axis_angle_to_quat(tmp_quat, upvec, moffset[0] * time_redraw * FLY_ROTATE_FAC);
+          axis_angle_to_quat(tmp_quat, upvec, moffset[0] * time_redraw * fly_rotate_factor);
           mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
 
           if (fly->xlock != FLY_AXISLOCK_STATE_OFF) {
@@ -934,10 +938,10 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
             axis_angle_to_quat(tmp_quat,
                                upvec,
                                roll * time_redraw_clamped * fly->zlock_momentum *
-                                   FLY_ZUP_CORRECT_FAC);
+                                   fly_z_up_correct_factor);
             mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
 
-            fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL;
+            fly->zlock_momentum += fly_z_up_correct_accel;
           }
           else {
             /* don't check until the view rotates again */
@@ -996,7 +1000,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
 
       /* impose a directional lag */
       interp_v3_v3v3(
-          dvec, dvec_tmp, fly->dvec_prev, (1.0f / (1.0f + (time_redraw * FLY_SMOOTH_FAC))));
+          dvec, dvec_tmp, fly->dvec_prev, (1.0f / (1.0f + (time_redraw * fly_smooth_factor))));
 
       add_v3_v3(rv3d->ofs, dvec);
 
diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.c b/source/blender/editors/space_view3d/view3d_navigate_walk.c
index 120a7016f73..3164c1e8403 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_walk.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_walk.c
@@ -987,12 +987,12 @@ static float getVelocityZeroTime(const float gravity, const float velocity)
 
 static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
 {
-#define WALK_ROTATE_TABLET_FAC 8.8f             /* Higher is faster, relative to region size. */
-#define WALK_ROTATE_CONSTANT_FAC DEG2RAD(0.15f) /* Higher is faster, radians per-pixel. */
-#define WALK_TOP_LIMIT DEG2RADF(85.0f)
-#define WALK_BOTTOM_LIMIT DEG2RADF(-80.0f)
-#define WALK_MOVE_SPEED base_speed
-#define WALK_BOOST_FACTOR ((void)0, walk->speed_factor)
+  /* Higher is faster, relative to region size. */
+  static const float walk_rotate_tablet_factor = 8.8f;
+  /* Higher is faster, radians per-pixel. */
+  static const float walk_rotate_constant_factor = DEG2RAD(0.15f);
+  static const float walk_top_limit = DEG2RADF(85.0f);
+  static const float walk_bottom_limit = DEG2RADF(-80.0f);
 
   RegionView3D *rv3d = walk->rv3d;
   ARegion *region = walk->region;
@@ -1044,13 +1044,13 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
       walk->time_lastdraw = time_current;
 
       /* base speed in m/s */
-      walk->speed = WALK_MOVE_SPEED;
+      walk->speed = base_speed;
 
       if (walk->is_fast) {
-        walk->speed *= WALK_BOOST_FACTOR;
+        walk->speed *= walk->speed_factor;
       }
       else if (walk->is_slow) {
-        walk->speed *= 1.0f / WALK_BOOST_FACTOR;
+        walk->speed *= 1.0f / walk->speed_factor;
       }
 
       copy_m3_m4(mat, rv3d->viewinv);
@@ -1069,12 +1069,12 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
 #ifdef USE_TABLET_SUPPORT
           if (walk->is_cursor_absolute) {
             y /= region->winy;
-            y *= WALK_ROTATE_TABLET_FAC;
+            y *= walk_rotate_tablet_factor;
           }
           else
 #endif
           {
-            y *= WALK_ROTATE_CONSTANT_FAC;
+            y *= walk_rotate_constant_factor;
           }
 
           /* user adjustment factor */
@@ -1084,10 +1084,10 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
           /* it ranges from 90.0f to -90.0f */
           angle = -asinf(rv3d->viewmat[2][2]);
 
-          if (angle > WALK_TOP_LIMIT && y > 0.0f) {
+          if (angle > walk_top_limit && y > 0.0f) {
             y = 0.0f;
           }
-          else if (angle < WALK_BOTTOM_LIMIT && y < 0.0f) {
+          else if (angle < walk_bottom_limit && y < 0.0f) {
             y = 0.0f;
           }
 
@@ -1118,12 +1118,12 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
 #ifdef USE_TABLET_SUPPORT
           if (walk->is_cursor_absolute) {
             x /= region->winx;
-            x *= WALK_ROTATE_TABLET_FAC;
+            x *= walk_rotate_tablet_factor;
           }
           else
 #endif
           {
-            x *= WALK_ROTATE_CONSTANT_FAC;
+            x *= walk_rotate_constant_factor;
           }
 
           /* user adjustment factor */
@@ -1226,7 +1226,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
 
         /* the distance we would fall naturally smoothly enough that we
          * can manually drop the object without activating gravity */
-        fall_distance = time_redraw * walk->speed * WALK_BOOST_FACTOR;
+        fall_distance = time_redraw * walk->speed * walk->speed_factor;
 
         if (fabsf(difference) < fall_distance) {
           /* slope/stairs */
@@ -1338,11 +1338,6 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
   }
 
   return OPERATOR_FINISHED;
-#undef WALK_ROTATE_TABLET_FAC
-#undef WALK_TOP_LIMIT
-#undef WALK_BOTTOM_LIMIT
-#undef WALK_MOVE_SPEED
-#undef WALK_BOOST_FACTOR
 }
 
 #ifdef WITH_INPUT_NDOF



More information about the Bf-blender-cvs mailing list