Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_walk.c
| Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | typedef struct WalkInfo { | ||||
| /** | /** | ||||
| * Needed for auto-keyframing, when animation isn't playing, only keyframe on confirmation. | * Needed for auto-keyframing, when animation isn't playing, only keyframe on confirmation. | ||||
| * | * | ||||
| * Currently we can't cancel this operator usefully while recording on animation playback | * Currently we can't cancel this operator usefully while recording on animation playback | ||||
| * (this would need to un-key all previous frames). | * (this would need to un-key all previous frames). | ||||
| */ | */ | ||||
| bool anim_playing; | bool anim_playing; | ||||
| bool needs_rotation_keyframe; | |||||
dfelinto: FYI I personally would use bitwise flags for that, makes easy to expand in the future.
That… | |||||
| bool needs_translation_keyframe; | |||||
| /** Previous 2D mouse values. */ | /** Previous 2D mouse values. */ | ||||
| int prev_mval[2]; | int prev_mval[2]; | ||||
| /** Center mouse values. */ | /** Center mouse values. */ | ||||
| int center_mval[2]; | int center_mval[2]; | ||||
| int moffset[2]; | int moffset[2]; | ||||
| ▲ Show 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | #endif | ||||
| walk->timer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, 0.01f); | walk->timer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, 0.01f); | ||||
| #ifdef WITH_INPUT_NDOF | #ifdef WITH_INPUT_NDOF | ||||
| walk->ndof = NULL; | walk->ndof = NULL; | ||||
| #endif | #endif | ||||
| walk->anim_playing = ED_screen_animation_playing(wm); | walk->anim_playing = ED_screen_animation_playing(wm); | ||||
| walk->needs_rotation_keyframe = false; | |||||
| walk->needs_translation_keyframe = false; | |||||
| walk->time_lastdraw = PIL_check_seconds_timer(); | walk->time_lastdraw = PIL_check_seconds_timer(); | ||||
| walk->draw_handle_pixel = ED_region_draw_cb_activate( | walk->draw_handle_pixel = ED_region_draw_cb_activate( | ||||
| walk->ar->type, drawWalkPixel, walk, REGION_DRAW_POST_PIXEL); | walk->ar->type, drawWalkPixel, walk, REGION_DRAW_POST_PIXEL); | ||||
| walk->rv3d->rflag |= RV3D_NAVIGATING; | walk->rv3d->rflag |= RV3D_NAVIGATING; | ||||
| ▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | static void walkMoveCamera(bContext *C, | ||||
| WalkInfo *walk, | WalkInfo *walk, | ||||
| const bool do_rotate, | const bool do_rotate, | ||||
| const bool do_translate, | const bool do_translate, | ||||
| const bool is_confirm) | const bool is_confirm) | ||||
| { | { | ||||
| /* we only consider autokeying on playback or if user confirmed walk on the same frame | /* we only consider autokeying on playback or if user confirmed walk on the same frame | ||||
| * otherwise we get a keyframe even if the user cancels. */ | * otherwise we get a keyframe even if the user cancels. */ | ||||
| const bool use_autokey = is_confirm || walk->anim_playing; | const bool use_autokey = is_confirm || walk->anim_playing; | ||||
| ED_view3d_cameracontrol_update( | ED_view3d_cameracontrol_update( | ||||
| walk->v3d_camera_control, use_autokey, C, do_rotate, do_translate); | walk->v3d_camera_control, use_autokey, C, do_rotate, do_translate); | ||||
| if (use_autokey) { | |||||
| walk->needs_rotation_keyframe = false; | |||||
| walk->needs_translation_keyframe = false; | |||||
| } | |||||
| } | } | ||||
| static float getFreeFallDistance(const float gravity, const float time) | static float getFreeFallDistance(const float gravity, const float time) | ||||
| { | { | ||||
| return gravity * (time * time) * 0.5f; | return gravity * (time * time) * 0.5f; | ||||
| } | } | ||||
| static float getVelocityZeroTime(const float gravity, const float velocity) | static float getVelocityZeroTime(const float gravity, const float velocity) | ||||
| ▲ Show 20 Lines • Show All 331 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| } | } | ||||
| /* scale the movement to the scene size */ | /* scale the movement to the scene size */ | ||||
| mul_v3_v3fl(dvec_tmp, dvec, walk->grid); | mul_v3_v3fl(dvec_tmp, dvec, walk->grid); | ||||
| add_v3_v3(rv3d->ofs, dvec_tmp); | add_v3_v3(rv3d->ofs, dvec_tmp); | ||||
| if (rv3d->persp == RV3D_CAMOB) { | if (rv3d->persp == RV3D_CAMOB) { | ||||
| const bool do_rotate = (moffset[0] || moffset[1]); | walk->needs_rotation_keyframe |= (moffset[0] || moffset[1]); | ||||
| const bool do_translate = (walk->speed != 0.0f); | walk->needs_translation_keyframe |= len_squared_v3(dvec_tmp) > FLT_EPSILON; | ||||
| walkMoveCamera(C, walk, do_rotate, do_translate, is_confirm); | walkMoveCamera( | ||||
| C, walk, walk->needs_rotation_keyframe, walk->needs_translation_keyframe, is_confirm); | |||||
| } | } | ||||
| } | } | ||||
| else { | 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(); | walk->time_lastdraw = PIL_check_seconds_timer(); | ||||
| } | } | ||||
| /* end drawing */ | /* end drawing */ | ||||
| copy_v3_v3(walk->dvec_prev, dvec); | copy_v3_v3(walk->dvec_prev, dvec); | ||||
| Show All 23 Lines | view3d_ndof_fly(walk->ndof, | ||||
| lock_ob ? lock_ob->protectflag : 0, | lock_ob ? lock_ob->protectflag : 0, | ||||
| &has_translate, | &has_translate, | ||||
| &has_rotate); | &has_rotate); | ||||
| if (has_translate || has_rotate) { | if (has_translate || has_rotate) { | ||||
| walk->redraw = true; | walk->redraw = true; | ||||
| if (walk->rv3d->persp == RV3D_CAMOB) { | if (walk->rv3d->persp == RV3D_CAMOB) { | ||||
| walkMoveCamera(C, walk, has_rotate, has_translate, is_confirm); | walk->needs_rotation_keyframe |= has_rotate; | ||||
| walk->needs_translation_keyframe |= has_translate; | |||||
| walkMoveCamera( | |||||
| C, walk, walk->needs_rotation_keyframe, walk->needs_translation_keyframe, is_confirm); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #endif /* WITH_INPUT_NDOF */ | #endif /* WITH_INPUT_NDOF */ | ||||
| /****** walk operator ******/ | /****** walk operator ******/ | ||||
| static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||
FYI I personally would use bitwise flags for that, makes easy to expand in the future.
That aside let me nitpick ;) whatabout: