diff --git a/source/blender/editors/space_view3d/view3d_navigate_fly.cc b/source/blender/editors/space_view3d/view3d_navigate_fly.cc index 2591b07b310..560190b263f 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_fly.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_fly.cc @@ -14,7 +14,7 @@ #ifdef WITH_INPUT_NDOF //# define NDOF_FLY_DEBUG -/* is this needed for ndof? - commented so redraw doesn't thrash - campbell */ +/* NOTE(@ideasman42): is this needed for NDOF? commented so redraw doesn't thrash. */ //# define NDOF_FLY_DRAW_TOOMUCH #endif /* WITH_INPUT_NDOF */ @@ -22,9 +22,9 @@ #include "MEM_guardedalloc.h" -#include "BLI_blenlib.h" #include "BLI_math_matrix.h" #include "BLI_math_rotation.h" +#include "BLI_rect.h" #include "BKE_context.h" #include "BKE_lib_id.h" @@ -78,17 +78,19 @@ enum { FLY_MODAL_SPEED, /* mouse-pan typically. */ }; -/* relative view axis locking - xlock, zlock */ +/** Relative view axis locking - xlock, zlock. */ enum eFlyPanState { - /* disabled */ + /** Disabled. */ FLY_AXISLOCK_STATE_OFF = 0, - - /* enabled but not checking because mouse hasn't moved outside the margin since locking was - * checked an not needed when the mouse moves, locking is set to 2 so checks are done. */ + /** + * Enabled but not checking because mouse hasn't moved outside the margin since locking was + * checked an not needed when the mouse moves, locking is set to 2 so checks are done. + */ FLY_AXISLOCK_STATE_IDLE = 1, - - /* mouse moved and checking needed, - * if no view altering is done its changed back to #FLY_AXISLOCK_STATE_IDLE */ + /** + * Mouse moved and checking needed, + * if no view altering is done its changed back to #FLY_AXISLOCK_STATE_IDLE. + */ FLY_AXISLOCK_STATE_ACTIVE = 2, }; @@ -132,7 +134,7 @@ void fly_modal_keymap(wmKeyConfig *keyconf) keymap = WM_modalkeymap_ensure(keyconf, "View3D Fly Modal", modal_items); - /* assign map to operators */ + /* Assign map to operators. */ WM_modalkeymap_assign(keymap, "VIEW3D_OT_fly"); } @@ -193,7 +195,7 @@ struct FlyInfo { /** World scale 1.0 default. */ float grid; - /* compare between last state */ + /* Compare between last state. */ /** Used to accelerate when using the mouse-wheel a lot. */ double time_lastwheel; /** Time between draws. */ @@ -201,7 +203,6 @@ struct FlyInfo { void *draw_handle_pixel; - /* use for some lag */ /** Keep the previous value to smooth transitions (use lag). */ float dvec_prev[3]; @@ -214,7 +215,7 @@ struct FlyInfo { /** \name Internal Fly Drawing * \{ */ -/* prototypes */ +/* Prototypes. */ #ifdef WITH_INPUT_NDOF static void flyApply_ndof(bContext *C, FlyInfo *fly, bool is_confirm); #endif /* WITH_INPUT_NDOF */ @@ -238,8 +239,8 @@ static void drawFlyPixel(const bContext * /*C*/, ARegion * /*region*/, void *arg yoff = 0; } - /* draws 4 edge brackets that frame the safe area where the - * mouse can move during fly mode without spinning the view */ + /* Draws 4 edge brackets that frame the safe area where the + * mouse can move during fly mode without spinning the view. */ x1 = xoff + 0.45f * fly->width; y1 = yoff + 0.45f * fly->height; @@ -255,28 +256,28 @@ static void drawFlyPixel(const bContext * /*C*/, ARegion * /*region*/, void *arg immBegin(GPU_PRIM_LINES, 16); - /* bottom left */ + /* Bottom left. */ immVertex2f(pos, x1, y1); immVertex2f(pos, x1, y1 + 5); immVertex2f(pos, x1, y1); immVertex2f(pos, x1 + 5, y1); - /* top right */ + /* Top right. */ immVertex2f(pos, x2, y2); immVertex2f(pos, x2, y2 - 5); immVertex2f(pos, x2, y2); immVertex2f(pos, x2 - 5, y2); - /* top left */ + /* Top left. */ immVertex2f(pos, x1, y2); immVertex2f(pos, x1, y2 - 5); immVertex2f(pos, x1, y2); immVertex2f(pos, x1 + 5, y2); - /* bottom right */ + /* Bottom right. */ immVertex2f(pos, x2, y1); immVertex2f(pos, x2, y1 + 5); @@ -293,7 +294,7 @@ static void drawFlyPixel(const bContext * /*C*/, ARegion * /*region*/, void *arg /** \name Internal Fly Logic * \{ */ -/* FlyInfo->state */ +/** FlyInfo::state */ enum { FLY_RUNNING = 0, FLY_CANCEL = 1, @@ -306,7 +307,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent wmWindow *win = CTX_wm_window(C); rctf viewborder; - float upvec[3]; /* tmp */ + float upvec[3]; float mat[3][3]; fly->rv3d = CTX_wm_region_view3d(C); @@ -319,7 +320,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent puts("\n-- fly begin --"); #endif - /* sanity check: for rare but possible case (if lib-linking the camera fails) */ + /* Sanity check: for rare but possible case (if lib-linking the camera fails). */ if ((fly->rv3d->persp == RV3D_CAMOB) && (fly->v3d->camera == nullptr)) { fly->rv3d->persp = RV3D_PERSP; } @@ -376,7 +377,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent fly->rv3d->rflag |= RV3D_NAVIGATING; - /* detect whether to start with Z locking */ + /* Detect whether to start with Z locking. */ copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f); copy_m3_m4(mat, fly->rv3d->viewinv); mul_m3_v3(mat, upvec); @@ -387,7 +388,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent fly->v3d_camera_control = ED_view3d_cameracontrol_acquire( fly->depsgraph, fly->scene, fly->v3d, fly->rv3d); - /* calculate center */ + /* Calculate center. */ if (ED_view3d_cameracontrol_object_get(fly->v3d_camera_control)) { ED_view3d_calc_camera_border( fly->scene, fly->depsgraph, fly->region, fly->v3d, fly->rv3d, &viewborder, false); @@ -406,7 +407,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent fly->center_mval[1] = fly->height / 2; } - /* center the mouse, probably the UI mafia are against this but without its quite annoying */ + /* Center the mouse, probably the UI mafia are against this but without its quite annoying. */ WM_cursor_warp(win, fly->region->winrct.xmin + fly->center_mval[0], fly->region->winrct.ymin + fly->center_mval[1]); @@ -423,7 +424,7 @@ static int flyEnd(bContext *C, FlyInfo *fly) return OPERATOR_RUNNING_MODAL; } if (fly->state == FLY_CONFIRM) { - /* Needed for auto_keyframe. */ + /* Needed for auto-keyframe. */ #ifdef WITH_INPUT_NDOF if (fly->ndof) { flyApply_ndof(C, fly, true); @@ -475,21 +476,22 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) } #ifdef WITH_INPUT_NDOF else if (event->type == NDOF_MOTION) { - /* do these automagically get delivered? yes. */ + /* Do these auto-magically get delivered? yes. */ // puts("ndof motion detected in fly mode!"); // static const char *tag_name = "3D mouse position"; const wmNDOFMotionData *incoming_ndof = static_cast( event->customdata); switch (incoming_ndof->progress) { - case P_STARTING: - /* start keeping track of 3D mouse position */ + case P_STARTING: { + /* Start keeping track of 3D mouse position. */ # ifdef NDOF_FLY_DEBUG puts("start keeping track of 3D mouse position"); # endif - /* fall-through */ - case P_IN_PROGRESS: - /* update 3D mouse position */ + /* Fall-through. */ + } + case P_IN_PROGRESS: { + /* Update 3D mouse position. */ # ifdef NDOF_FLY_DEBUG putchar('.'); fflush(stdout); @@ -503,8 +505,9 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) memcpy(fly->ndof, incoming_ndof, sizeof(wmNDOFMotionData)); } break; - case P_FINISHING: - /* stop keeping track of 3D mouse position */ + } + case P_FINISHING: { + /* Stop keeping track of 3D mouse position. */ # ifdef NDOF_FLY_DEBUG puts("stop keeping track of 3D mouse position"); # endif @@ -513,29 +516,33 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) // free(fly->ndof); fly->ndof = nullptr; } - /* update the time else the view will jump when 2D mouse/timer resume */ + /* Update the time else the view will jump when 2D mouse/timer resume. */ fly->time_lastdraw = PIL_check_seconds_timer(); break; - default: - break; /* should always be one of the above 3 */ + } + default: { + /* Should always be one of the above 3. */ + break; + } } } #endif /* WITH_INPUT_NDOF */ - /* handle modal keymap first */ + /* Handle modal key-map first. */ else if (event->type == EVT_MODAL_MAP) { switch (event->val) { - case FLY_MODAL_CANCEL: + case FLY_MODAL_CANCEL: { fly->state = FLY_CANCEL; break; - case FLY_MODAL_CONFIRM: + } + case FLY_MODAL_CONFIRM: { fly->state = FLY_CONFIRM; break; - + } /* Speed adjusting with mouse-pan (track-pad). */ case FLY_MODAL_SPEED: { float fac = 0.02f * (event->prev_xy[1] - event->xy[1]); - /* allowing to brake immediate */ + /* Allowing to brake immediate. */ if (fac > 0.0f && fly->speed < 0.0f) { fly->speed = 0.0f; } @@ -552,7 +559,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) double time_currwheel; float time_wheel; - /* not quite correct but avoids confusion WASD/arrow keys 'locking up' */ + /* Not quite correct but avoids confusion WASD/arrow keys 'locking up'. */ if (fly->axis == -1) { fly->axis = 2; fly->speed = fabsf(fly->speed); @@ -561,7 +568,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) time_currwheel = PIL_check_seconds_timer(); time_wheel = float(time_currwheel - fly->time_lastwheel); fly->time_lastwheel = time_currwheel; - /* Mouse wheel delays range from (0.5 == slow) to (0.01 == fast) */ + /* Mouse wheel delays range from (0.5 == slow) to (0.01 == fast). */ /* 0-0.5 -> 0-5.0 */ time_wheel = 1.0f + (10.0f - (20.0f * min_ff(time_wheel, 0.5f))); @@ -577,7 +584,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) double time_currwheel; float time_wheel; - /* not quite correct but avoids confusion WASD/arrow keys 'locking up' */ + /* Not quite correct but avoids confusion WASD/arrow keys 'locking up'. */ if (fly->axis == -1) { fly->axis = 2; fly->speed = -fabsf(fly->speed); @@ -597,17 +604,18 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) } break; } - case FLY_MODAL_PAN_ENABLE: + case FLY_MODAL_PAN_ENABLE: { fly->pan_view = true; break; - case FLY_MODAL_PAN_DISABLE: + } + case FLY_MODAL_PAN_DISABLE: { fly->pan_view = false; break; - - /* Implement WASD keys, comments only for 'forward'. */ - case FLY_MODAL_DIR_FORWARD: + } + /* Implement WASD keys, comments only for 'forward'. */ + case FLY_MODAL_DIR_FORWARD: { if (fly->axis == 2 && fly->speed < 0.0f) { - /* reverse direction stops, tap again to continue */ + /* Reverse direction stops, tap again to continue. */ fly->axis = -1; } else { @@ -622,7 +630,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = 2; } break; - case FLY_MODAL_DIR_BACKWARD: + } + case FLY_MODAL_DIR_BACKWARD: { if (fly->axis == 2 && fly->speed > 0.0f) { fly->axis = -1; } @@ -637,7 +646,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = 2; } break; - case FLY_MODAL_DIR_LEFT: + } + case FLY_MODAL_DIR_LEFT: { if (fly->axis == 0 && fly->speed < 0.0f) { fly->axis = -1; } @@ -652,7 +662,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = 0; } break; - case FLY_MODAL_DIR_RIGHT: + } + case FLY_MODAL_DIR_RIGHT: { if (fly->axis == 0 && fly->speed > 0.0f) { fly->axis = -1; } @@ -667,7 +678,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = 0; } break; - case FLY_MODAL_DIR_DOWN: + } + case FLY_MODAL_DIR_DOWN: { if (fly->axis == 1 && fly->speed < 0.0f) { fly->axis = -1; } @@ -681,7 +693,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = 1; } break; - case FLY_MODAL_DIR_UP: + } + case FLY_MODAL_DIR_UP: { if (fly->axis == 1 && fly->speed > 0.0f) { fly->axis = -1; } @@ -695,8 +708,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = 1; } break; - - case FLY_MODAL_AXIS_LOCK_X: + } + case FLY_MODAL_AXIS_LOCK_X: { if (fly->xlock != FLY_AXISLOCK_STATE_OFF) { fly->xlock = FLY_AXISLOCK_STATE_OFF; } @@ -705,7 +718,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->xlock_momentum = 0.0; } break; - case FLY_MODAL_AXIS_LOCK_Z: + } + case FLY_MODAL_AXIS_LOCK_Z: { if (fly->zlock != FLY_AXISLOCK_STATE_OFF) { fly->zlock = FLY_AXISLOCK_STATE_OFF; } @@ -714,20 +728,23 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->zlock_momentum = 0.0; } break; - - case FLY_MODAL_PRECISION_ENABLE: + } + case FLY_MODAL_PRECISION_ENABLE: { fly->use_precision = true; break; - case FLY_MODAL_PRECISION_DISABLE: + } + case FLY_MODAL_PRECISION_DISABLE: { fly->use_precision = false; break; - - case FLY_MODAL_FREELOOK_ENABLE: + } + case FLY_MODAL_FREELOOK_ENABLE: { fly->use_freelook = true; break; - case FLY_MODAL_FREELOOK_DISABLE: + } + case FLY_MODAL_FREELOOK_DISABLE: { fly->use_freelook = false; break; + } } } } @@ -738,7 +755,7 @@ static void flyMoveCamera(bContext *C, const bool do_translate, const bool is_confirm) { - /* we only consider autokeying on playback or if user confirmed fly on the same frame + /* We only consider auto-keying on playback or if user confirmed fly on the same frame * otherwise we get a keyframe even if the user cancels. */ const bool use_autokey = is_confirm || fly->anim_playing; ED_view3d_cameracontrol_update(fly->v3d_camera_control, use_autokey, C, do_rotate, do_translate); @@ -746,23 +763,23 @@ 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 */ +#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. */ RegionView3D *rv3d = fly->rv3d; - /* 3x3 copy of the view matrix so we can move along the view axis */ + /* 3x3 copy of the view matrix so we can move along the view axis. */ float mat[3][3]; - /* this is the direction that's added to the view offset per redraw */ + /* This is the direction that's added to the view offset per redraw. */ float dvec[3] = {0, 0, 0}; /* Camera Up-righting variables. */ - float moffset[2]; /* mouse offset from the views center */ - float tmp_quat[4]; /* used for rotating the view */ + float moffset[2]; /* Mouse offset from the views center. */ + float tmp_quat[4]; /* Used for rotating the view. */ - /* x and y margin defining the safe area where the mouse's movement won't rotate the view */ + /* X and Y margin defining the safe area where the mouse's movement won't rotate the view. */ int xmargin, ymargin; #ifdef NDOF_FLY_DEBUG @@ -777,11 +794,11 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) { - /* mouse offset from the center */ + /* Mouse offset from the center. */ moffset[0] = fly->mval[0] - fly->center_mval[0]; moffset[1] = fly->mval[1] - fly->center_mval[1]; - /* enforce a view margin */ + /* Enforce a view margin. */ if (moffset[0] > xmargin) { moffset[0] -= xmargin; } @@ -803,7 +820,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) } /* Scale the mouse movement by this value - scales mouse movement to the view size - * `moffset[0] / (region->winx-xmargin * 2)` - window size minus margin (same for y) + * `moffset[0] / (region->winx-xmargin * 2)` - window size minus margin (same for Y). * * the mouse moves isn't linear. */ @@ -824,8 +841,8 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) { float dvec_tmp[3]; - /* time how fast it takes for us to redraw, - * this is so simple scenes don't fly too fast */ + /* Time how fast it takes for us to redraw, + * this is so simple scenes don't fly too fast. */ double time_current; float time_redraw; float time_redraw_clamped; @@ -835,13 +852,13 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) time_current = PIL_check_seconds_timer(); time_redraw = float(time_current - fly->time_lastdraw); - /* clamp redraw time to avoid jitter in roll correction */ + /* Clamp redraw time to avoid jitter in roll correction. */ time_redraw_clamped = min_ff(0.05f, time_redraw); fly->time_lastdraw = time_current; - /* Scale the time to use shift to scale the speed down- just like - * shift slows many other areas of blender down */ + /* Scale the time to use shift to scale the speed down - just like + * shift slows many other areas of blender down. */ if (fly->use_precision) { fly->speed = fly->speed * (1.0f - time_redraw_clamped); } @@ -849,7 +866,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) copy_m3_m4(mat, rv3d->viewinv); if (fly->pan_view == true) { - /* pan only */ + /* Pan only. */ copy_v3_fl3(dvec_tmp, -moffset[0], -moffset[1], 0.0f); if (fly->use_precision) { @@ -861,20 +878,21 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) mul_v3_fl(dvec_tmp, time_redraw * 200.0f * fly->grid); } else { - float roll; /* similar to the angle between the camera's up and the Z-up, - * but its very rough so just roll */ + /* Similar to the angle between the camera's up and the Z-up, + * but its very rough so just roll. */ + float roll; - /* rotate about the X axis- look up/down */ + /* Rotate about the X axis- look up/down. */ if (moffset[1]) { float upvec[3]; copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f); mul_m3_v3(mat, upvec); - /* Rotate about the relative up vec */ + /* Rotate about the relative up vector. */ axis_angle_to_quat(tmp_quat, upvec, moffset[1] * time_redraw * -FLY_ROTATE_FAC); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock != FLY_AXISLOCK_STATE_OFF) { - fly->xlock = FLY_AXISLOCK_STATE_ACTIVE; /* check for rotation */ + fly->xlock = FLY_AXISLOCK_STATE_ACTIVE; /* Check for rotation. */ } if (fly->zlock != FLY_AXISLOCK_STATE_OFF) { fly->zlock = FLY_AXISLOCK_STATE_ACTIVE; @@ -882,10 +900,10 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) fly->xlock_momentum = 0.0f; } - /* rotate about the Y axis- look left/right */ + /* Rotate about the Y axis- look left/right. */ if (moffset[0]) { float upvec[3]; - /* if we're upside down invert the moffset */ + /* If we're upside down invert the `moffset`. */ copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f); mul_m3_v3(mat, upvec); @@ -893,7 +911,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) moffset[0] = -moffset[0]; } - /* make the lock vectors */ + /* Make the lock vectors. */ if (fly->zlock) { copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f); } @@ -902,12 +920,12 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) mul_m3_v3(mat, upvec); } - /* Rotate about the relative up vec */ + /* Rotate about the relative up vector. */ axis_angle_to_quat(tmp_quat, upvec, moffset[0] * time_redraw * FLY_ROTATE_FAC); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock != FLY_AXISLOCK_STATE_OFF) { - fly->xlock = FLY_AXISLOCK_STATE_ACTIVE; /* check for rotation */ + fly->xlock = FLY_AXISLOCK_STATE_ACTIVE; /* Check for rotation. */ } if (fly->zlock != FLY_AXISLOCK_STATE_OFF) { fly->zlock = FLY_AXISLOCK_STATE_ACTIVE; @@ -919,13 +937,13 @@ 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); - /* make sure we have some z rolling */ + /* Make sure we have some Z rolling. */ if (fabsf(upvec[2]) > 0.00001f) { roll = upvec[2] * 5.0f; - /* rotate the view about this axis */ + /* Rotate the view about this axis. */ copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f); mul_m3_v3(mat, upvec); - /* Rotate about the relative up vec */ + /* Rotate about the relative up vector. */ axis_angle_to_quat(tmp_quat, upvec, roll * time_redraw_clamped * fly->zlock_momentum * @@ -935,25 +953,25 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL; } else { - /* don't check until the view rotates again */ + /* Don't check until the view rotates again. */ fly->zlock = FLY_AXISLOCK_STATE_IDLE; fly->zlock_momentum = 0.0f; } } - /* Only apply X-axis correction when mouse isn't applying x rotation. */ + /* Only apply X-axis correction when mouse isn't applying X rotation. */ if (fly->xlock == FLY_AXISLOCK_STATE_ACTIVE && moffset[1] == 0) { float upvec[3]; copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f); mul_m3_v3(mat, upvec); - /* make sure we have some z rolling */ + /* Make sure we have some Z rolling. */ if (fabsf(upvec[2]) > 0.00001f) { roll = upvec[2] * -5.0f; - /* rotate the view about this axis */ + /* Rotate the view about this axis. */ copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f); mul_m3_v3(mat, upvec); - /* Rotate about the relative up vec */ + /* Rotate about the relative up vector. */ axis_angle_to_quat( tmp_quat, upvec, roll * time_redraw_clamped * fly->xlock_momentum * 0.1f); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); @@ -961,20 +979,20 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) fly->xlock_momentum += 0.05f; } else { - fly->xlock = FLY_AXISLOCK_STATE_IDLE; /* see above */ + fly->xlock = FLY_AXISLOCK_STATE_IDLE; /* See above. */ fly->xlock_momentum = 0.0f; } } if (fly->axis == -1) { - /* pause */ + /* Pause. */ zero_v3(dvec_tmp); } else if (!fly->use_freelook) { - /* Normal operation */ - /* define dvec, view direction vector */ + /* Normal operation. */ + /* Define `dvec`, view direction vector. */ zero_v3(dvec_tmp); - /* move along the current axis */ + /* Move along the current axis. */ dvec_tmp[fly->axis] = 1.0f; mul_m3_v3(mat, dvec_tmp); @@ -989,7 +1007,7 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) mul_v3_fl(dvec_tmp, fly->speed * time_redraw * 0.25f); } - /* impose a directional lag */ + /* Impose a directional lag. */ interp_v3_v3v3( dvec, dvec_tmp, fly->dvec_prev, (1.0f / (1.0f + (time_redraw * FLY_SMOOTH_FAC)))); @@ -1004,10 +1022,10 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) } } else { - /* we're not redrawing but we need to update the time else the view will jump */ + /* We're not redrawing but we need to update the time else the view will jump. */ fly->time_lastdraw = PIL_check_seconds_timer(); } - /* end drawing */ + /* End drawing. */ copy_v3_v3(fly->dvec_prev, dvec); } @@ -1092,7 +1110,7 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event) flyEvent(fly, event); #ifdef WITH_INPUT_NDOF - if (fly->ndof) { /* 3D mouse overrules [2D mouse + timer] */ + if (fly->ndof) { /* 3D mouse overrules [2D mouse + timer]. */ if (event->type == NDOF_MOTION) { flyApply_ndof(C, fly, false); } @@ -1129,18 +1147,18 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event) void VIEW3D_OT_fly(wmOperatorType *ot) { - /* identifiers */ + /* Identifiers. */ ot->name = "Fly Navigation"; ot->description = "Interactively fly around the scene"; ot->idname = "VIEW3D_OT_fly"; - /* api callbacks */ + /* API callbacks. */ ot->invoke = fly_invoke; ot->cancel = fly_cancel; ot->modal = fly_modal; ot->poll = ED_operator_region_view3d_active; - /* flags */ + /* Flags. */ ot->flag = OPTYPE_BLOCKING; } diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.cc b/source/blender/editors/space_view3d/view3d_navigate_walk.cc index 1a120e06435..77efb22914b 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_walk.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_walk.cc @@ -18,10 +18,10 @@ #include "MEM_guardedalloc.h" -#include "BLI_blenlib.h" #include "BLI_kdopbvh.h" #include "BLI_math_matrix.h" #include "BLI_math_rotation.h" +#include "BLI_rect.h" #include "BLI_utildefines.h" #include "BKE_context.h" @@ -52,7 +52,7 @@ #ifdef WITH_INPUT_NDOF //# define NDOF_WALK_DEBUG -/* is this needed for ndof? - commented so redraw doesn't thrash - campbell */ +/* NOTE(@ideasman42): Is this needed for NDOF? commented so redraw doesn't thrash. */ //# define NDOF_WALK_DRAW_TOOMUCH #endif @@ -62,8 +62,8 @@ /** \name Modal Key-map * \{ */ -/* NOTE: these defines are saved in keymap files, - * do not change values but just add new ones */ +/* NOTE: these defines are saved in key-map files, + * do not change values but just add new ones. */ enum { WALK_MODAL_CANCEL = 1, WALK_MODAL_CONFIRM, @@ -127,15 +127,15 @@ enum eWalkGravityState { WALK_GRAVITY_STATE_ON, }; -/* Relative view axis z axis locking. */ +/** Relative view axis Z axis locking. */ enum eWalkLockState { - /* Disabled. */ + /** Disabled. */ WALK_AXISLOCK_STATE_OFF = 0, - /* Moving. */ + /** Moving. */ WALK_AXISLOCK_STATE_ACTIVE = 2, - /* Done moving, it cannot be activated again. */ + /** Done moving, it cannot be activated again. */ WALK_AXISLOCK_STATE_DONE = 3, }; @@ -204,7 +204,7 @@ void walk_modal_keymap(wmKeyConfig *keyconf) keymap = WM_modalkeymap_ensure(keyconf, "View3D Walk Modal", modal_items); - /* assign map to operators */ + /* Assign map to operators. */ WM_modalkeymap_assign(keymap, "VIEW3D_OT_walk"); } @@ -216,11 +216,13 @@ void walk_modal_keymap(wmKeyConfig *keyconf) struct WalkTeleport { eWalkTeleportState state; - float duration; /* from user preferences */ + /** From user preferences. */ + float duration; float origin[3]; float direction[3]; double initial_time; - eWalkMethod navigation_mode; /* teleport always set FREE mode on */ + /** Teleport always set FREE mode on. */ + eWalkMethod navigation_mode; }; /** #WalkInfo::state */ @@ -269,25 +271,24 @@ struct WalkInfo { /* Walk state. */ /** The base speed without run/slow down modifications. */ float base_speed; - /** The speed the view is moving per redraw. */ + /** The speed the view is moving per redraw (in m/s). */ float speed; /** World scale 1.0 default. */ float grid; - /* compare between last state */ + /* Compare between last state. */ /** Time between draws. */ double time_lastdraw; void *draw_handle_pixel; - /* use for some lag */ /** Keep the previous value to smooth transitions (use lag). */ float dvec_prev[3]; /** Walk/free movement. */ eWalkMethod navigation_mode; - /* teleport */ + /** Teleport struct. */ WalkTeleport teleport; /** Look speed factor - user preferences. */ @@ -337,7 +338,7 @@ struct WalkInfo { /** \name Internal Walk Drawing * \{ */ -/* prototypes */ +/* Prototypes. */ #ifdef WITH_INPUT_NDOF static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm); #endif /* WITH_INPUT_NDOF */ @@ -346,7 +347,7 @@ static float getVelocityZeroTime(const float gravity, const float velocity); static void drawWalkPixel(const bContext * /*C*/, ARegion *region, void *arg) { - /* draws an aim/cross in the center */ + /* Draws an aim/cross in the center. */ WalkInfo *walk = static_cast(arg); const int outter_length = 24; @@ -374,19 +375,19 @@ static void drawWalkPixel(const bContext * /*C*/, ARegion *region, void *arg) immBegin(GPU_PRIM_LINES, 8); - /* North */ + /* North. */ immVertex2i(pos, xoff, yoff + inner_length); immVertex2i(pos, xoff, yoff + outter_length); - /* East */ + /* East. */ immVertex2i(pos, xoff + inner_length, yoff); immVertex2i(pos, xoff + outter_length, yoff); - /* South */ + /* South. */ immVertex2i(pos, xoff, yoff - inner_length); immVertex2i(pos, xoff, yoff - outter_length); - /* West */ + /* West. */ immVertex2i(pos, xoff - inner_length, yoff); immVertex2i(pos, xoff - outter_length, yoff); @@ -413,7 +414,7 @@ static void walk_navigation_mode_set(WalkInfo *walk, eWalkMethod mode) } /** - * \param r_distance: Distance to the hit point + * \param r_distance: Distance to the hit point. */ static bool walk_floor_distance_get(RegionView3D *rv3d, WalkInfo *walk, @@ -465,7 +466,7 @@ static bool walk_ray_cast(RegionView3D *rv3d, float r_normal[3], float *r_ray_distance) { - float ray_normal[3] = {0, 0, -1}; /* forward */ + float ray_normal[3] = {0, 0, -1}; /* Forward axis. */ float ray_start[3]; *r_ray_distance = BVH_RAYCAST_DIST_MAX; @@ -489,12 +490,12 @@ static bool walk_ray_cast(RegionView3D *rv3d, r_location, r_normal); - /* dot is positive if both rays are facing the same direction */ + /* Dot is positive if both rays are facing the same direction. */ if (dot_v3v3(ray_normal, r_normal) > 0) { negate_v3(r_normal); } - /* artificially scale the distance to the scene size */ + /* Artificially scale the distance to the scene size. */ *r_ray_distance /= walk->grid; return ret; @@ -521,7 +522,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int puts("\n-- walk begin --"); #endif - /* sanity check: for rare but possible case (if lib-linking the camera fails) */ + /* Sanity check: for rare but possible case (if lib-linking the camera fails). */ if ((walk->rv3d->persp == RV3D_CAMOB) && (walk->v3d->camera == nullptr)) { walk->rv3d->persp = RV3D_PERSP; } @@ -566,7 +567,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int 1.0f : 1.0f / walk->scene->unit.scale_length; - /* user preference settings */ + /* User preference settings. */ walk->teleport.duration = U.walk_navigation.teleport_time; walk->mouse_speed = U.walk_navigation.mouse_speed; @@ -714,21 +715,22 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) } #ifdef WITH_INPUT_NDOF else if (event->type == NDOF_MOTION) { - /* do these automagically get delivered? yes. */ + /* Do these auto-magically get delivered? yes. */ // puts("ndof motion detected in walk mode!"); // static const char *tag_name = "3D mouse position"; const wmNDOFMotionData *incoming_ndof = static_cast( event->customdata); switch (incoming_ndof->progress) { - case P_STARTING: - /* start keeping track of 3D mouse position */ + case P_STARTING: { + /* Start keeping track of 3D mouse position. */ # ifdef NDOF_WALK_DEBUG puts("start keeping track of 3D mouse position"); # endif - /* fall-through */ - case P_IN_PROGRESS: - /* update 3D mouse position */ + /* Fall-through. */ + } + case P_IN_PROGRESS: { + /* Update 3D mouse position. */ # ifdef NDOF_WALK_DEBUG putchar('.'); fflush(stdout); @@ -742,8 +744,9 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) memcpy(walk->ndof, incoming_ndof, sizeof(wmNDOFMotionData)); } break; - case P_FINISHING: - /* stop keeping track of 3D mouse position */ + } + case P_FINISHING: { + /* Stop keeping track of 3D mouse position. */ # ifdef NDOF_WALK_DEBUG puts("stop keeping track of 3D mouse position"); # endif @@ -753,105 +756,128 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) walk->ndof = nullptr; } - /* update the time else the view will jump when 2D mouse/timer resume */ + /* Update the time else the view will jump when 2D mouse/timer resume. */ walk->time_lastdraw = PIL_check_seconds_timer(); break; - default: - break; /* should always be one of the above 3 */ + } + default: { + /* Should always be one of the above 3. */ + break; + } } } #endif /* WITH_INPUT_NDOF */ - /* handle modal keymap first */ + /* Handle modal key-map first. */ else if (event->type == EVT_MODAL_MAP) { switch (event->val) { - case WALK_MODAL_CANCEL: + case WALK_MODAL_CANCEL: { walk->state = WALK_CANCEL; break; - case WALK_MODAL_CONFIRM: + } + case WALK_MODAL_CONFIRM: { walk->state = WALK_CONFIRM; break; - - case WALK_MODAL_ACCELERATE: + } + case WALK_MODAL_ACCELERATE: { base_speed *= 1.0f + (walk->is_slow ? 0.01f : 0.1f); break; - case WALK_MODAL_DECELERATE: + } + case WALK_MODAL_DECELERATE: { base_speed /= 1.0f + (walk->is_slow ? 0.01f : 0.1f); break; - - /* implement WASD keys */ - case WALK_MODAL_DIR_FORWARD: + } + /* Implement WASD keys. */ + case WALK_MODAL_DIR_FORWARD: { walk->active_directions |= WALK_BIT_FORWARD; break; - case WALK_MODAL_DIR_BACKWARD: + } + case WALK_MODAL_DIR_BACKWARD: { walk->active_directions |= WALK_BIT_BACKWARD; break; - case WALK_MODAL_DIR_LEFT: + } + case WALK_MODAL_DIR_LEFT: { walk->active_directions |= WALK_BIT_LEFT; break; - case WALK_MODAL_DIR_RIGHT: + } + case WALK_MODAL_DIR_RIGHT: { walk->active_directions |= WALK_BIT_RIGHT; break; - case WALK_MODAL_DIR_UP: + } + case WALK_MODAL_DIR_UP: { walk->active_directions |= WALK_BIT_UP; break; - case WALK_MODAL_DIR_DOWN: + } + case WALK_MODAL_DIR_DOWN: { walk->active_directions |= WALK_BIT_DOWN; break; - case WALK_MODAL_DIR_LOCAL_UP: + } + case WALK_MODAL_DIR_LOCAL_UP: { walk->active_directions |= WALK_BIT_LOCAL_UP; break; - case WALK_MODAL_DIR_LOCAL_DOWN: + } + case WALK_MODAL_DIR_LOCAL_DOWN: { walk->active_directions |= WALK_BIT_LOCAL_DOWN; break; - - case WALK_MODAL_DIR_FORWARD_STOP: + } + case WALK_MODAL_DIR_FORWARD_STOP: { walk->active_directions &= ~WALK_BIT_FORWARD; break; - case WALK_MODAL_DIR_BACKWARD_STOP: + } + case WALK_MODAL_DIR_BACKWARD_STOP: { walk->active_directions &= ~WALK_BIT_BACKWARD; break; - case WALK_MODAL_DIR_LEFT_STOP: + } + case WALK_MODAL_DIR_LEFT_STOP: { walk->active_directions &= ~WALK_BIT_LEFT; break; - case WALK_MODAL_DIR_RIGHT_STOP: + } + case WALK_MODAL_DIR_RIGHT_STOP: { walk->active_directions &= ~WALK_BIT_RIGHT; break; - case WALK_MODAL_DIR_UP_STOP: + } + case WALK_MODAL_DIR_UP_STOP: { walk->active_directions &= ~WALK_BIT_UP; break; - case WALK_MODAL_DIR_DOWN_STOP: + } + case WALK_MODAL_DIR_DOWN_STOP: { walk->active_directions &= ~WALK_BIT_DOWN; break; - case WALK_MODAL_DIR_LOCAL_UP_STOP: + } + case WALK_MODAL_DIR_LOCAL_UP_STOP: { walk->active_directions &= ~WALK_BIT_LOCAL_UP; break; - case WALK_MODAL_DIR_LOCAL_DOWN_STOP: + } + case WALK_MODAL_DIR_LOCAL_DOWN_STOP: { walk->active_directions &= ~WALK_BIT_LOCAL_DOWN; break; - - case WALK_MODAL_FAST_ENABLE: + } + case WALK_MODAL_FAST_ENABLE: { walk->is_fast = true; break; - case WALK_MODAL_FAST_DISABLE: + } + case WALK_MODAL_FAST_DISABLE: { walk->is_fast = false; break; - case WALK_MODAL_SLOW_ENABLE: + } + case WALK_MODAL_SLOW_ENABLE: { walk->is_slow = true; break; - case WALK_MODAL_SLOW_DISABLE: + } + case WALK_MODAL_SLOW_DISABLE: { walk->is_slow = false; break; + } #define JUMP_SPEED_MIN 1.0f #define JUMP_TIME_MAX 0.2f /* s */ #define JUMP_SPEED_MAX sqrtf(2.0f * walk->gravity * walk->jump_height) - case WALK_MODAL_JUMP_STOP: + case WALK_MODAL_JUMP_STOP: { if (walk->gravity_state == WALK_GRAVITY_STATE_JUMP) { float t; - /* delta time */ + /* Delta time. */ t = float(PIL_check_seconds_timer() - walk->teleport.initial_time); /* Reduce the velocity, if JUMP wasn't hold for long enough. */ @@ -859,42 +885,42 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) walk->speed_jump = JUMP_SPEED_MIN + t * (JUMP_SPEED_MAX - JUMP_SPEED_MIN) / JUMP_TIME_MAX; - /* when jumping, duration is how long it takes before we start going down */ + /* When jumping, duration is how long it takes before we start going down. */ walk->teleport.duration = getVelocityZeroTime(walk->gravity, walk->speed_jump); - /* no more increase of jump speed */ + /* No more increase of jump speed. */ walk->gravity_state = WALK_GRAVITY_STATE_ON; } break; - case WALK_MODAL_JUMP: + } + case WALK_MODAL_JUMP: { if ((walk->navigation_mode == WALK_MODE_GRAVITY) && (walk->gravity_state == WALK_GRAVITY_STATE_OFF) && (walk->teleport.state == WALK_TELEPORT_STATE_OFF)) { - /* no need to check for ground, - * walk->gravity wouldn't be off - * if we were over a hole */ + /* No need to check for ground, `walk->gravity` + * wouldn't be off if we were over a hole. */ walk->gravity_state = WALK_GRAVITY_STATE_JUMP; walk->speed_jump = JUMP_SPEED_MAX; walk->teleport.initial_time = PIL_check_seconds_timer(); copy_v3_v3(walk->teleport.origin, walk->rv3d->viewinv[3]); - /* using previous vec because WASD keys are not called when SPACE is */ + /* Using previous vector because WASD keys are not called when SPACE is. */ copy_v2_v2(walk->teleport.direction, walk->dvec_prev); - /* when jumping, duration is how long it takes before we start going down */ + /* When jumping, duration is how long it takes before we start going down. */ walk->teleport.duration = getVelocityZeroTime(walk->gravity, walk->speed_jump); } - break; + } case WALK_MODAL_TELEPORT: { float loc[3], nor[3]; float distance; const bool ret = walk_ray_cast(walk->rv3d, walk, loc, nor, &distance); - /* in case we are teleporting middle way from a jump */ + /* In case we are teleporting middle way from a jump. */ walk->speed_jump = 0.0f; if (ret) { @@ -912,13 +938,12 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) copy_v3_v3(teleport->origin, walk->rv3d->viewinv[3]); - /* stop the camera from a distance (camera height) */ + /* Stop the camera from a distance (camera height). */ normalize_v3_length(nor, walk->view_height); add_v3_v3(loc, nor); sub_v3_v3v3(teleport->direction, loc, teleport->origin); } - break; } @@ -926,7 +951,7 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) #undef JUMP_TIME_MAX #undef JUMP_SPEED_MIN - case WALK_MODAL_GRAVITY_TOGGLE: + case WALK_MODAL_GRAVITY_TOGGLE: { if (walk->navigation_mode == WALK_MODE_GRAVITY) { walk_navigation_mode_set(walk, WALK_MODE_FREE); } @@ -934,24 +959,28 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event) walk_navigation_mode_set(walk, WALK_MODE_GRAVITY); } break; + } - case WALK_MODAL_AXIS_LOCK_Z: + case WALK_MODAL_AXIS_LOCK_Z: { if (walk->zlock != WALK_AXISLOCK_STATE_DONE) { walk->zlock = WALK_AXISLOCK_STATE_ACTIVE; walk->zlock_momentum = 0.0f; } break; + } #define JUMP_HEIGHT_FACTOR 1.5f #define JUMP_HEIGHT_MIN 0.1f #define JUMP_HEIGHT_MAX 10.0f - case WALK_MODAL_INCREASE_JUMP: + case WALK_MODAL_INCREASE_JUMP: { jump_height = min_ff(jump_height * JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MAX); break; - case WALK_MODAL_DECREASE_JUMP: + } + case WALK_MODAL_DECREASE_JUMP: { jump_height = max_ff(jump_height / JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MIN); break; + } #undef JUMP_HEIGHT_FACTOR #undef JUMP_HEIGHT_MIN @@ -966,7 +995,7 @@ static void walkMoveCamera(bContext *C, const bool do_translate, const bool is_confirm) { - /* we only consider autokeying on playback or if user confirmed walk on the same frame + /* We only consider auto-keying on playback or if user confirmed walk on the same frame * otherwise we get a keyframe even if the user cancels. */ const bool use_autokey = is_confirm || walk->anim_playing; ED_view3d_cameracontrol_update( @@ -1002,13 +1031,13 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) RegionView3D *rv3d = walk->rv3d; ARegion *region = walk->region; - /* 3x3 copy of the view matrix so we can move along the view axis */ + /* 3x3 copy of the view matrix so we can move along the view axis. */ float mat[3][3]; - /* this is the direction that's added to the view offset per redraw */ + /* This is the direction that's added to the view offset per redraw. */ float dvec[3] = {0.0f, 0.0f, 0.0f}; - int moffset[2]; /* mouse offset from the views center */ - float tmp_quat[4]; /* used for rotating the view */ + int moffset[2]; /* Mouse offset from the views center. */ + float tmp_quat[4]; /* Used for rotating the view. */ #ifdef NDOF_WALK_DEBUG { @@ -1018,19 +1047,19 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) #endif { - /* mouse offset from the center */ + /* Mouse offset from the center. */ copy_v2_v2_int(moffset, walk->moffset); - /* apply moffset so we can re-accumulate */ + /* Apply `moffset` so we can re-accumulate. */ walk->moffset[0] = 0; walk->moffset[1] = 0; - /* revert mouse */ + /* Revert mouse. */ if (walk->is_reversed) { moffset[1] = -moffset[1]; } - /* update jump height */ + /* Update jump height. */ if (walk->gravity_state != WALK_GRAVITY_STATE_JUMP) { walk->jump_height = WALK_JUMP_HEIGHT; } @@ -1043,8 +1072,8 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) { float dvec_tmp[3]; - /* time how fast it takes for us to redraw, - * this is so simple scenes don't walk too fast */ + /* Time how fast it takes for us to redraw, + * this is so simple scenes don't walk too fast. */ double time_current; float time_redraw; float time_redraw_clamped; @@ -1059,7 +1088,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) walk->time_lastdraw = time_current; - /* base speed in m/s */ + /* Base speed in m/s. */ walk->speed = WALK_MOVE_SPEED; if (walk->is_fast) { @@ -1072,13 +1101,13 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) copy_m3_m4(mat, rv3d->viewinv); { - /* rotate about the X axis- look up/down */ + /* Rotate about the X axis- look up/down. */ if (moffset[1]) { float upvec[3]; float angle; float y; - /* relative offset */ + /* Relative offset. */ y = float(moffset[1]); /* Speed factor. */ @@ -1093,11 +1122,10 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) y *= WALK_ROTATE_CONSTANT_FAC; } - /* user adjustment factor */ + /* User adjustment factor. */ y *= walk->mouse_speed; - /* clamp the angle limits */ - /* it ranges from 90.0f to -90.0f */ + /* Clamp the angle limits: it ranges from 90.0f to -90.0f. */ angle = -asinf(rv3d->viewmat[2][2]); if (angle > WALK_TOP_LIMIT && y > 0.0f) { @@ -1109,17 +1137,17 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f); mul_m3_v3(mat, upvec); - /* Rotate about the relative up vec */ + /* Rotate about the relative up vector. */ axis_angle_to_quat(tmp_quat, upvec, -y); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); } - /* rotate about the Y axis- look left/right */ + /* Rotate about the Y axis- look left/right. */ if (moffset[0]) { float upvec[3]; float x; - /* if we're upside down invert the moffset */ + /* If we're upside down invert the `moffset`. */ copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f); mul_m3_v3(mat, upvec); @@ -1127,7 +1155,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) moffset[0] = -moffset[0]; } - /* relative offset */ + /* Relative offset. */ x = float(moffset[0]); /* Speed factor. */ @@ -1142,10 +1170,10 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) x *= WALK_ROTATE_CONSTANT_FAC; } - /* user adjustment factor */ + /* User adjustment factor. */ x *= walk->mouse_speed; - /* Rotate about the relative up vec */ + /* Rotate about the relative up vector */ axis_angle_to_quat_single(tmp_quat, 'Z', x); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); } @@ -1155,13 +1183,13 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f); mul_m3_v3(mat, upvec); - /* Make sure we have some z rolling. */ + /* Make sure we have some Z rolling. */ if (fabsf(upvec[2]) > 0.00001f) { float roll = upvec[2] * 5.0f; /* Rotate the view about this axis. */ copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f); mul_m3_v3(mat, upvec); - /* Rotate about the relative up vec. */ + /* Rotate about the relative up vector. */ axis_angle_to_quat(tmp_quat, upvec, roll * time_redraw_clamped * walk->zlock_momentum * @@ -1177,7 +1205,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) } } - /* WASD - 'move' translation code */ + /* WASD - 'move' translation code. */ if ((walk->active_directions) && (walk->gravity_state == WALK_GRAVITY_STATE_OFF)) { short direction; @@ -1263,11 +1291,11 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) normalize_v3(dvec); - /* apply movement */ + /* Apply movement. */ mul_v3_fl(dvec, walk->speed * time_redraw); } - /* stick to the floor */ + /* Stick to the floor. */ if (walk->navigation_mode == WALK_MODE_GRAVITY && ELEM(walk->gravity_state, WALK_GRAVITY_STATE_OFF, WALK_GRAVITY_STATE_START)) { @@ -1279,21 +1307,21 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) difference = walk->view_height - ray_distance; } - /* the distance we would fall naturally smoothly enough that we - * can manually drop the object without activating gravity */ + /* 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; if (fabsf(difference) < fall_distance) { /* slope/stairs */ dvec[2] -= difference; - /* in case we switched from FREE to GRAVITY too close to the ground */ + /* In case we switched from FREE to GRAVITY too close to the ground. */ if (walk->gravity_state == WALK_GRAVITY_STATE_START) { walk->gravity_state = WALK_GRAVITY_STATE_OFF; } } else { - /* hijack the teleport variables */ + /* Hijack the teleport variables. */ walk->teleport.initial_time = PIL_check_seconds_timer(); walk->gravity_state = WALK_GRAVITY_STATE_ON; walk->teleport.duration = 0.0f; @@ -1303,14 +1331,14 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) } } - /* Falling or jumping) */ + /* Falling or jumping). */ if (ELEM(walk->gravity_state, WALK_GRAVITY_STATE_ON, WALK_GRAVITY_STATE_JUMP)) { float ray_distance, difference = -100.0f; - /* delta time */ + /* Delta time. */ const bool t = float(PIL_check_seconds_timer() - walk->teleport.initial_time); - /* keep moving if we were moving */ + /* Keep moving if we were moving. */ copy_v2_v2(dvec, walk->teleport.direction); const float z_cur = walk->rv3d->viewinv[3][2] / walk->grid; @@ -1319,42 +1347,42 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) /* Jump. */ (t * walk->speed_jump); - /* duration is the jump duration */ + /* Duration is the jump duration. */ if (t > walk->teleport.duration) { - /* check to see if we are landing */ + /* Check to see if we are landing. */ if (walk_floor_distance_get(rv3d, walk, dvec, &ray_distance)) { difference = walk->view_height - ray_distance; } if (difference > 0.0f) { - /* quit falling, lands at "view_height" from the floor */ + /* Quit falling, lands at "view_height" from the floor. */ dvec[2] -= difference; walk->gravity_state = WALK_GRAVITY_STATE_OFF; walk->speed_jump = 0.0f; } else { - /* keep falling */ + /* Keep falling. */ dvec[2] = z_cur - z_new; } } else { - /* keep going up (jump) */ + /* Keep going up (jump). */ dvec[2] = z_cur - z_new; } } - /* Teleport */ + /* Teleport. */ else if (walk->teleport.state == WALK_TELEPORT_STATE_ON) { float t; /* factor */ float new_loc[3]; float cur_loc[3]; - /* linear interpolation */ + /* Linear interpolation. */ t = float(PIL_check_seconds_timer() - walk->teleport.initial_time); t /= walk->teleport.duration; - /* clamp so we don't go past our limit */ + /* Clamp so we don't go past our limit. */ if (t >= 1.0f) { t = 1.0f; walk->teleport.state = WALK_TELEPORT_STATE_OFF; @@ -1368,7 +1396,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) sub_v3_v3v3(dvec, cur_loc, new_loc); } - /* scale the movement to the scene size */ + /* Scale the movement to the scene size. */ mul_v3_v3fl(dvec_tmp, dvec, walk->grid); add_v3_v3(rv3d->ofs, dvec_tmp); @@ -1381,10 +1409,10 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) } } else { - /* we're not redrawing but we need to update the time else the view will jump */ + /* We're not redrawing but we need to update the time else the view will jump. */ walk->time_lastdraw = PIL_check_seconds_timer(); } - /* end drawing */ + /* End drawing. */ copy_v3_v3(walk->dvec_prev, dvec); } @@ -1477,7 +1505,7 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event) walkEvent(walk, event); #ifdef WITH_INPUT_NDOF - if (walk->ndof) { /* 3D mouse overrules [2D mouse + timer] */ + if (walk->ndof) { /* 3D mouse overrules [2D mouse + timer]. */ if (event->type == NDOF_MOTION) { walkApply_ndof(C, walk, false); } @@ -1505,7 +1533,7 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event) WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, walk_object); } - /* too frequent, commented with NDOF_WALK_DRAW_TOOMUCH for now */ + /* Too frequent, commented with `NDOF_WALK_DRAW_TOOMUCH` for now. */ // puts("redraw!"); ED_region_tag_redraw(CTX_wm_region(C)); } @@ -1514,12 +1542,12 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event) void VIEW3D_OT_walk(wmOperatorType *ot) { - /* identifiers */ + /* Identifiers. */ ot->name = "Walk Navigation"; ot->description = "Interactively walk around the scene"; ot->idname = "VIEW3D_OT_walk"; - /* api callbacks */ + /* API callbacks. */ ot->invoke = walk_invoke; ot->cancel = walk_cancel; ot->modal = walk_modal;