Blender V5.3
view3d_navigate_walk.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#include "DNA_object_types.h"
17#include "DNA_scene_types.h"
18
19#include "MEM_guardedalloc.h"
20
21#include "BLI_enum_flags.hh"
22#include "BLI_kdopbvh.hh"
23#include "BLI_listbase.hh"
24#include "BLI_math_matrix.hh"
25#include "BLI_math_matrix_c.hh"
26#include "BLI_math_rotation.hh"
28#include "BLI_math_vector_c.hh"
29#include "BLI_rect.hh"
30#include "BLI_time.hh" /* Smooth-view. */
31
32#include "BKE_camera.h"
33#include "BKE_constraint.h"
34#include "BKE_context.hh"
35#include "BKE_lib_id.hh"
36#include "BKE_report.hh"
37#include "BKE_screen.hh"
38
39#include "BLT_translation.hh"
40
41#include "WM_api.hh"
42#include "WM_types.hh"
43
44#include "ED_screen.hh"
45#include "ED_space_api.hh"
47#include "ED_undo.hh"
48
49#include "UI_resources.hh"
50
51#include "GPU_immediate.hh"
52
53#include "view3d_intern.hh" /* own include */
54#include "view3d_navigate.hh"
55
56#include <fmt/format.h>
57
58#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
59
60namespace blender {
61
62#ifdef WITH_INPUT_NDOF
63// # define NDOF_WALK_DEBUG
64/* NOTE(@ideasman42): Is this needed for NDOF? commented so redraw doesn't thrash. */
65// # define NDOF_WALK_DRAW_TOOMUCH
66#endif
67
68#define USE_TABLET_SUPPORT
69
70/* -------------------------------------------------------------------- */
73
74/* NOTE: these defines are saved in key-map files,
75 * do not change values but just add new ones. */
76enum {
108};
109
121
126
131
138
150
152{
153 static const EnumPropertyItem modal_items[] = {
154 {WALK_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
155 {WALK_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
156
157 {WALK_MODAL_DIR_FORWARD, "FORWARD", 0, "Forward", ""},
158 {WALK_MODAL_DIR_BACKWARD, "BACKWARD", 0, "Backward", ""},
159 {WALK_MODAL_DIR_LEFT, "LEFT", 0, "Left", ""},
160 {WALK_MODAL_DIR_RIGHT, "RIGHT", 0, "Right", ""},
161 {WALK_MODAL_DIR_UP, "UP", 0, "Up", ""},
162 {WALK_MODAL_DIR_DOWN, "DOWN", 0, "Down", ""},
163 {WALK_MODAL_DIR_LOCAL_UP, "LOCAL_UP", 0, "Local Up", ""},
164 {WALK_MODAL_DIR_LOCAL_DOWN, "LOCAL_DOWN", 0, "Local Down", ""},
165
166 {WALK_MODAL_DIR_FORWARD_STOP, "FORWARD_STOP", 0, "Stop Move Forward", ""},
167 {WALK_MODAL_DIR_BACKWARD_STOP, "BACKWARD_STOP", 0, "Stop Move Backward", ""},
168 {WALK_MODAL_DIR_LEFT_STOP, "LEFT_STOP", 0, "Stop Move Left", ""},
169 {WALK_MODAL_DIR_RIGHT_STOP, "RIGHT_STOP", 0, "Stop Move Right", ""},
170 {WALK_MODAL_DIR_UP_STOP, "UP_STOP", 0, "Stop Move Global Up", ""},
171 {WALK_MODAL_DIR_DOWN_STOP, "DOWN_STOP", 0, "Stop Move Global Down", ""},
172 {WALK_MODAL_DIR_LOCAL_UP_STOP, "LOCAL_UP_STOP", 0, "Stop Move Local Up", ""},
173 {WALK_MODAL_DIR_LOCAL_DOWN_STOP, "LOCAL_DOWN_STOP", 0, "Stop Move Local Down", ""},
174
175 {WALK_MODAL_TELEPORT, "TELEPORT", 0, "Teleport", "Move forward a few units at once"},
176
177 {WALK_MODAL_ACCELERATE, "ACCELERATE", 0, "Accelerate", ""},
178 {WALK_MODAL_DECELERATE, "DECELERATE", 0, "Decelerate", ""},
179
180 {WALK_MODAL_FAST_ENABLE, "FAST_ENABLE", 0, "Fast", "Move faster (walk or fly)"},
181 {WALK_MODAL_FAST_DISABLE, "FAST_DISABLE", 0, "Fast (Off)", "Resume regular speed"},
182
183 {WALK_MODAL_SLOW_ENABLE, "SLOW_ENABLE", 0, "Slow", "Move slower (walk or fly)"},
184 {WALK_MODAL_SLOW_DISABLE, "SLOW_DISABLE", 0, "Slow (Off)", "Resume regular speed"},
185
186 {WALK_MODAL_JUMP, "JUMP", 0, "Jump", "Jump when in walk mode"},
187 {WALK_MODAL_JUMP_STOP, "JUMP_STOP", 0, "Jump (Off)", "Stop pushing jump"},
188
189 {WALK_MODAL_GRAVITY_TOGGLE, "GRAVITY_TOGGLE", 0, "Toggle Gravity", "Toggle gravity effect"},
190
191 {WALK_MODAL_AXIS_LOCK_Z, "AXIS_LOCK_Z", 0, "Z Axis Correction", "Z axis correction"},
192
194 "INCREASE_JUMP",
195 0,
196 "Increase Jump Height",
197 "Increase jump height"},
199 "DECREASE_JUMP",
200 0,
201 "Decrease Jump Height",
202 "Decrease jump height"},
203
204 {0, nullptr, 0, nullptr, nullptr},
205 };
206
207 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Walk Modal");
208
209 /* This function is called for each space-type, only needs to add map once. */
210 if (keymap && keymap->modal_items) {
211 return;
212 }
213
214 keymap = WM_modalkeymap_ensure(keyconf, "View3D Walk Modal", modal_items);
215
216 /* Assign map to operators. */
217 WM_modalkeymap_assign(keymap, "VIEW3D_OT_walk");
218}
219
221
222/* -------------------------------------------------------------------- */
225
236
243
244struct WalkInfo {
245 /* context stuff */
249 Depsgraph *depsgraph;
251
254
256 bool redraw;
257
267
269 int prev_mval[2];
271 int init_mval[2];
272
273 int moffset[2];
274
275#ifdef WITH_INPUT_NDOF
277 wmNDOFMotionData *ndof;
278#endif
279
280 /* Walk state. */
284 float speed;
286 float grid;
287
288 /* Compare between last state. */
291
293
295 float dvec_prev[3];
296
299
302
305
309
312
313#ifdef USE_TABLET_SUPPORT
316#endif
317
320 float gravity;
321
324
327
331
334
338
340
342};
343
345
346/* -------------------------------------------------------------------- */
349
350/* Prototypes. */
351#ifdef WITH_INPUT_NDOF
352static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm);
353#endif /* WITH_INPUT_NDOF */
354static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm);
355static float walk_calc_velocity_zero_time(const float gravity, const float velocity);
356
357static void drawWalkPixel(const bContext * /*C*/, ARegion *region, void *arg)
358{
359 /* Draws an aim/cross in the center. */
360 WalkInfo *walk = static_cast<WalkInfo *>(arg);
361
362 const float outer_length = 24.0f;
363 const float inner_length = 14.0f;
364 float xoff, yoff;
365 rctf viewborder;
366
368 viewborder = BKE_camera_view_border(walk->scene,
369 walk->depsgraph,
370 walk->v3d,
371 walk->rv3d,
372 region->winx,
373 region->winy,
374 false,
375 false,
376 false);
377 xoff = viewborder.xmin + BLI_rctf_size_x(&viewborder) * 0.5f;
378 yoff = viewborder.ymin + BLI_rctf_size_y(&viewborder) * 0.5f;
379 }
380 else {
381 xoff = float(walk->region->winx) / 2.0f;
382 yoff = float(walk->region->winy) / 2.0f;
383 }
384
385 GPUVertFormat *format = immVertexFormat();
386 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
387
389
391
393
394 /* North. */
395 immVertex2f(pos, xoff, yoff + inner_length);
396 immVertex2f(pos, xoff, yoff + outer_length);
397
398 /* East. */
399 immVertex2f(pos, xoff + inner_length, yoff);
400 immVertex2f(pos, xoff + outer_length, yoff);
401
402 /* South. */
403 immVertex2f(pos, xoff, yoff - inner_length);
404 immVertex2f(pos, xoff, yoff - outer_length);
405
406 /* West. */
407 immVertex2f(pos, xoff - inner_length, yoff);
408 immVertex2f(pos, xoff - outer_length, yoff);
409
410 immEnd();
412}
413
415
416/* -------------------------------------------------------------------- */
419
421{
422 if (mode == WALK_MODE_FREE) {
425 }
426 else { /* WALK_MODE_GRAVITY */
429 }
430}
431
436 WalkInfo *walk,
437 const float dvec[3],
438 float *r_distance)
439{
440 const float ray_normal[3] = {0, 0, -1}; /* down */
441 float ray_start[3];
442 float location_dummy[3];
443 float normal_dummy[3];
444 float dvec_tmp[3];
445
446 *r_distance = BVH_RAYCAST_DIST_MAX;
447
448 copy_v3_v3(ray_start, rv3d->viewinv[3]);
449
450 mul_v3_v3fl(dvec_tmp, dvec, walk->grid);
451 add_v3_v3(ray_start, dvec_tmp);
452
453 ed::transform::SnapObjectParams snap_params = {};
455 /* Avoid having to convert the edit-mesh to a regular mesh. */
457
459 walk->depsgraph,
460 walk->v3d,
461 &snap_params,
462 ray_start,
463 ray_normal,
464 r_distance,
465 location_dummy,
466 normal_dummy);
467
468 /* Artificially scale the distance to the scene size. */
469 *r_distance /= walk->grid;
470 return ret;
471}
472
478static bool walk_ray_cast(RegionView3D *rv3d,
479 WalkInfo *walk,
480 float r_location[3],
481 float r_normal[3],
482 float *r_ray_distance)
483{
484 float ray_normal[3] = {0, 0, -1}; /* Forward axis. */
485 float ray_start[3];
486
487 *r_ray_distance = BVH_RAYCAST_DIST_MAX;
488
489 copy_v3_v3(ray_start, rv3d->viewinv[3]);
490
491 mul_mat3_m4_v3(rv3d->viewinv, ray_normal);
492
493 normalize_v3(ray_normal);
494
495 ed::transform::SnapObjectParams snap_params = {};
497
499 walk->depsgraph,
500 walk->v3d,
501 &snap_params,
502 ray_start,
503 ray_normal,
504 nullptr,
505 r_location,
506 r_normal);
507
508 /* Dot is positive if both rays are facing the same direction. */
509 if (dot_v3v3(ray_normal, r_normal) > 0) {
510 negate_v3(r_normal);
511 }
512
513 /* Artificially scale the distance to the scene size. */
514 *r_ray_distance /= walk->grid;
515
516 return ret;
517}
518
520static struct {
521 float base_speed;
523 float userdef_speed;
524
525 float jump_height;
528 float grid;
529} g_walk = {
530 /*base_speed*/ -1.0f,
531 /*userdef_speed*/ -1.0f,
532 /*jump_height*/ -1.0f,
533 /*userdef_jump_height*/ -1.0f,
535
536static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int mval[2])
537{
539 wmWindow *win = CTX_wm_window(C);
540
541 walk->rv3d = CTX_wm_region_view3d(C);
542 walk->v3d = CTX_wm_view3d(C);
543 walk->region = CTX_wm_region(C);
545 walk->scene = CTX_data_scene(C);
546
547#ifdef NDOF_WALK_DEBUG
548 puts("\n-- walk begin --");
549#endif
550
551 /* Sanity check: for rare but possible case (if lib-linking the camera fails). */
552 if ((walk->rv3d->persp == RV3D_CAMOB) && (walk->v3d->camera == nullptr)) {
553 walk->rv3d->persp = RV3D_PERSP;
554 }
555
556 if (walk->rv3d->persp == RV3D_CAMOB &&
558 {
560 RPT_ERROR,
561 "Cannot navigate a camera from an external library or non-editable override");
562 return false;
563 }
564
565 if (ED_view3d_offset_lock_check(walk->v3d, walk->rv3d)) {
566 BKE_report(op->reports, RPT_ERROR, "Cannot navigate when the view offset is locked");
567 return false;
568 }
569
570 if (walk->rv3d->persp == RV3D_CAMOB) {
571 for (const bConstraint &con : walk->v3d->camera->constraints) {
572 if (!BKE_constraint_has_influence(&con)) {
573 continue;
574 }
575 BKE_report(op->reports, RPT_ERROR, "Cannot navigate an object with effective constraints");
576 return false;
577 }
578 }
579
580 walk->state = WALK_RUNNING;
581
582 walk->grid = (walk->scene->unit.system == USER_UNIT_NONE) ?
583 1.0f :
584 1.0f / walk->scene->unit.scale_length;
585
586 const float userdef_jump_height = U.walk_navigation.jump_height / walk->grid;
587 const float userdef_view_height = U.walk_navigation.view_height / walk->grid;
588
589 if (fabsf(U.walk_navigation.walk_speed - g_walk.userdef_speed) > 0.1f ||
590 fabsf(walk->grid - g_walk.grid) > FLT_EPSILON)
591 {
592 g_walk.base_speed = U.walk_navigation.walk_speed / walk->grid;
593 g_walk.userdef_speed = U.walk_navigation.walk_speed;
594 }
595
596 if (fabsf(userdef_jump_height - g_walk.userdef_jump_height) > 0.1f ||
597 fabsf(walk->grid - g_walk.grid) > FLT_EPSILON)
598 {
599 g_walk.jump_height = userdef_jump_height;
600 g_walk.userdef_jump_height = userdef_jump_height;
601 g_walk.grid = walk->grid;
602 }
603
604 walk->jump_height = 0.0f;
605
606 walk->speed = 0.0f;
607 walk->is_fast = false;
608 walk->is_slow = false;
609
610 /* User preference settings. */
611 walk->teleport.duration = U.walk_navigation.teleport_time;
612 walk->mouse_speed = U.walk_navigation.mouse_speed;
613
614 if (U.walk_navigation.flag & USER_WALK_GRAVITY) {
616 }
617 else {
619 }
620
621 walk->view_height = userdef_view_height;
622 walk->jump_height = userdef_jump_height;
623 walk->speed = U.walk_navigation.walk_speed / walk->grid;
624 walk->speed_factor = U.walk_navigation.walk_speed_factor;
626
628
630 walk->gravity = fabsf(walk->scene->physics_settings.gravity[2]) / walk->grid;
631 }
632 else {
633 walk->gravity = 9.80668f / walk->grid; /* m/s2 */
634 }
635
636 walk->is_reversed = ((U.walk_navigation.flag & USER_WALK_MOUSE_REVERSE) != 0);
637
638#ifdef USE_TABLET_SUPPORT
639 walk->is_cursor_absolute = false;
640#endif
641
643
644#ifdef NDOF_WALK_DRAW_TOOMUCH
645 walk->redraw = true;
646#endif
647 zero_v3(walk->dvec_prev);
648
649 walk->timer = WM_event_timer_add(CTX_wm_manager(C), win, TIMER, 0.01f);
650
651#ifdef WITH_INPUT_NDOF
652 walk->ndof = nullptr;
653#endif
654
656 walk->need_rotation_keyframe = false;
657 walk->need_translation_keyframe = false;
658
660
663
664 walk->rv3d->rflag |= RV3D_NAVIGATING;
665
667
669 walk->depsgraph, walk->scene, walk->v3d, walk->rv3d);
670
671 copy_v2_v2_int(walk->init_mval, mval);
672 copy_v2_v2_int(walk->prev_mval, mval);
673
675
676 return true;
677}
678
680{
681 wmWindow *win;
682 RegionView3D *rv3d;
683
684 if (walk->state == WALK_RUNNING) {
686 }
687 if (walk->state == WALK_CONFIRM) {
688 /* Needed for auto_keyframe. */
689#ifdef WITH_INPUT_NDOF
690 if (walk->ndof) {
691 walkApply_ndof(C, walk, true);
692 }
693 else
694#endif /* WITH_INPUT_NDOF */
695 {
696 walkApply(C, walk, true);
697 }
698 }
699
700#ifdef NDOF_WALK_DEBUG
701 puts("\n-- walk end --");
702#endif
703
704 win = CTX_wm_window(C);
705 rv3d = walk->rv3d;
706
707 ED_workspace_status_text(C, nullptr);
708
710
712
714
716
717 rv3d->rflag &= ~RV3D_NAVIGATING;
718
719#ifdef WITH_INPUT_NDOF
720 if (walk->ndof) {
721 MEM_delete(walk->ndof);
722 }
723#endif
724
725 WM_cursor_grab_disable(win, nullptr);
726
727 if (walk->state == WALK_CONFIRM) {
728 MEM_delete(walk);
729 return OPERATOR_FINISHED;
730 }
731
732 MEM_delete(walk);
733 return OPERATOR_CANCELLED;
734}
735
736static void walkEvent(WalkInfo *walk, const wmEvent *event)
737{
738 if (event->type == TIMER && event->customdata == walk->timer) {
739 walk->redraw = true;
740 }
741 else if (ISMOUSE_MOTION(event->type)) {
742
743#ifdef USE_TABLET_SUPPORT
744 if ((walk->is_cursor_absolute == false) && event->tablet.is_motion_absolute) {
745 walk->is_cursor_absolute = true;
746 }
747#endif /* USE_TABLET_SUPPORT */
748
749 walk->moffset[0] += event->mval[0] - walk->prev_mval[0];
750 walk->moffset[1] += event->mval[1] - walk->prev_mval[1];
751
752 copy_v2_v2_int(walk->prev_mval, event->mval);
753
754 if (walk->moffset[0] || walk->moffset[1]) {
755 walk->redraw = true;
756 }
757 }
758#ifdef WITH_INPUT_NDOF
759 else if (event->type == NDOF_MOTION) {
760 /* Do these auto-magically get delivered? yes. */
761 // puts("ndof motion detected in walk mode!");
762 // static const char *tag_name = "3D mouse position";
763
764 const wmNDOFMotionData *incoming_ndof = static_cast<const wmNDOFMotionData *>(
765 event->customdata);
766 switch (incoming_ndof->progress) {
767 case P_STARTING: {
768 /* Start keeping track of 3D mouse position. */
769# ifdef NDOF_WALK_DEBUG
770 puts("start keeping track of 3D mouse position");
771# endif
772 /* Fall-through. */
773 }
774 case P_IN_PROGRESS: {
775 /* Update 3D mouse position. */
776# ifdef NDOF_WALK_DEBUG
777 putchar('.');
778 fflush(stdout);
779# endif
780 if (walk->ndof == nullptr) {
781 // walk->ndof = MEM_new_uninitialized<wmNDOFMotionData>(tag_name);
782 walk->ndof = MEM_dupalloc(incoming_ndof);
783 // walk->ndof = malloc(sizeof(wmNDOFMotionData));
784 }
785 else {
786 memcpy(walk->ndof, incoming_ndof, sizeof(wmNDOFMotionData));
787 }
788 break;
789 }
790 case P_FINISHING: {
791 /* Stop keeping track of 3D mouse position. */
792# ifdef NDOF_WALK_DEBUG
793 puts("stop keeping track of 3D mouse position");
794# endif
795 if (walk->ndof) {
796 MEM_delete(walk->ndof);
797 // free(walk->ndof);
798 walk->ndof = nullptr;
799 }
800
801 /* Update the time else the view will jump when 2D mouse/timer resume. */
803
804 break;
805 }
806 default: {
807 /* Should always be one of the above 3. */
808 break;
809 }
810 }
811 }
812#endif /* WITH_INPUT_NDOF */
813 /* Handle modal key-map first. */
814 else if (event->type == EVT_MODAL_MAP) {
815 switch (event->val) {
816 case WALK_MODAL_CANCEL: {
817 walk->state = WALK_CANCEL;
818 break;
819 }
820 case WALK_MODAL_CONFIRM: {
821 walk->state = WALK_CONFIRM;
822 break;
823 }
825 g_walk.base_speed *= 1.0f + (walk->is_slow ? 0.01f : 0.1f);
826 break;
827 }
829 g_walk.base_speed /= 1.0f + (walk->is_slow ? 0.01f : 0.1f);
830 break;
831 }
832 /* Implement WASD keys. */
835 break;
836 }
839 break;
840 }
841 case WALK_MODAL_DIR_LEFT: {
843 break;
844 }
847 break;
848 }
849 case WALK_MODAL_DIR_UP: {
851 break;
852 }
853 case WALK_MODAL_DIR_DOWN: {
855 break;
856 }
859 break;
860 }
863 break;
864 }
867 break;
868 }
871 break;
872 }
875 break;
876 }
879 break;
880 }
883 break;
884 }
887 break;
888 }
891 break;
892 }
895 break;
896 }
898 walk->is_fast = true;
899 break;
900 }
902 walk->is_fast = false;
903 break;
904 }
906 walk->is_slow = true;
907 break;
908 }
910 walk->is_slow = false;
911 break;
912 }
913
914#define JUMP_SPEED_MIN 1.0f
915#define JUMP_TIME_MAX 0.2f /* s */
916#define JUMP_SPEED_MAX sqrtf(2.0f * walk->gravity * walk->jump_height)
917
920 float t;
921
922 /* Delta time. */
924
925 /* Reduce the velocity, if JUMP wasn't hold for long enough. */
926 t = min_ff(t, JUMP_TIME_MAX);
927 walk->speed_jump = JUMP_SPEED_MIN +
929
930 /* When jumping, duration is how long it takes before we start going down. */
932
933 /* No more increase of jump speed. */
935 }
936 break;
937 }
938 case WALK_MODAL_JUMP: {
939 if ((walk->navigation_mode == WALK_MODE_GRAVITY) &&
942 {
943 /* No need to check for ground, `walk->gravity`
944 * wouldn't be off if we were over a hole. */
947
949 copy_v3_v3(walk->teleport.origin, walk->rv3d->viewinv[3]);
950
951 /* Using previous vector because WASD keys are not called when SPACE is. */
953
954 /* When jumping, duration is how long it takes before we start going down. */
956 }
957 break;
958 }
959
960 case WALK_MODAL_TELEPORT: {
961 float loc[3], nor[3];
962 float distance;
963 const bool ret = walk_ray_cast(walk->rv3d, walk, loc, nor, &distance);
964
965 /* In case we are teleporting middle way from a jump. */
966 walk->speed_jump = 0.0f;
967
968 if (ret) {
969 WalkTeleport *teleport = &walk->teleport;
970
971 /* Store the current navigation mode if we are not already teleporting. */
972 if (teleport->state == WALK_TELEPORT_STATE_OFF) {
973 teleport->navigation_mode = walk->navigation_mode;
974 }
975 teleport->state = WALK_TELEPORT_STATE_ON;
977 teleport->duration = U.walk_navigation.teleport_time;
978
980
981 copy_v3_v3(teleport->origin, walk->rv3d->viewinv[3]);
982
983 /* Stop the camera from a distance (camera height). */
985 add_v3_v3(loc, nor);
986
987 sub_v3_v3v3(teleport->direction, loc, teleport->origin);
988 }
989 break;
990 }
991
992#undef JUMP_SPEED_MAX
993#undef JUMP_TIME_MAX
994#undef JUMP_SPEED_MIN
995
997 if (walk->navigation_mode == WALK_MODE_GRAVITY) {
999 }
1000 else { /* WALK_MODE_FREE */
1002 }
1003 break;
1004 }
1005
1007 if (walk->zlock != WALK_AXISLOCK_STATE_DONE) {
1009 walk->zlock_momentum = 0.0f;
1010 }
1011 break;
1012 }
1013
1014#define JUMP_HEIGHT_FACTOR 1.5f
1015#define JUMP_HEIGHT_MIN 0.1f
1016#define JUMP_HEIGHT_MAX 10.0f
1017
1019 g_walk.jump_height = min_ff(g_walk.jump_height * JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MAX);
1020 break;
1021 }
1023 g_walk.jump_height = max_ff(g_walk.jump_height / JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MIN);
1024 break;
1025 }
1026
1027#undef JUMP_HEIGHT_FACTOR
1028#undef JUMP_HEIGHT_MIN
1029#undef JUMP_HEIGHT_MAX
1030 }
1031 }
1032}
1033
1035 WalkInfo *walk,
1036 const bool do_rotate,
1037 const bool do_translate,
1038 const bool is_confirm)
1039{
1040 /* We only consider auto-keying on playback or if user confirmed walk on the same frame
1041 * otherwise we get a keyframe even if the user cancels. */
1042 const bool use_autokey = is_confirm || walk->anim_playing;
1044 walk->v3d_camera_control, use_autokey, C, do_rotate, do_translate);
1045 if (use_autokey) {
1046 walk->need_rotation_keyframe = false;
1047 walk->need_translation_keyframe = false;
1048 }
1049}
1050
1051static float walk_calc_free_fall_distance(const float gravity, const float time)
1052{
1053 return gravity * (time * time) * 0.5f;
1054}
1055
1056static float walk_calc_velocity_zero_time(const float gravity, const float velocity)
1057{
1058 return velocity / gravity;
1059}
1060
1061static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
1062{
1063#define WALK_ROTATE_TABLET_FAC 8.8f /* Higher is faster, relative to region size. */
1064#define WALK_ROTATE_CONSTANT_FAC DEG2RADF(0.15f) /* Higher is faster, radians per-pixel. */
1065#define WALK_TOP_LIMIT DEG2RADF(85.0f)
1066#define WALK_BOTTOM_LIMIT DEG2RADF(-80.0f)
1067#define WALK_MOVE_SPEED (0 ? 0.0f : g_walk.base_speed)
1068#define WALK_JUMP_HEIGHT (0 ? 0.0f : g_walk.jump_height)
1069#define WALK_BOOST_FACTOR ((void)0, walk->speed_factor)
1070#define WALK_ZUP_CORRECT_FAC 0.1f /* Amount to correct per step. */
1071#define WALK_ZUP_CORRECT_ACCEL 0.05f /* Increase upright momentum each step. */
1072
1073 RegionView3D *rv3d = walk->rv3d;
1074 ARegion *region = walk->region;
1075
1076 /* 3x3 copy of the view matrix so we can move along the view axis. */
1077 float mat[3][3];
1078 /* This is the direction that's added to the view offset per redraw. */
1079 float dvec[3] = {0.0f, 0.0f, 0.0f};
1080
1081 int moffset[2]; /* Mouse offset from the views center. */
1082 float tmp_quat[4]; /* Used for rotating the view. */
1083
1084#ifdef NDOF_WALK_DEBUG
1085 {
1086 static uint iteration = 1;
1087 printf("walk timer %d\n", iteration++);
1088 }
1089#endif
1090
1091 /* Mouse offset from the center. */
1092 copy_v2_v2_int(moffset, walk->moffset);
1093
1094 /* Apply `moffset` so we can re-accumulate. */
1095 walk->moffset[0] = 0;
1096 walk->moffset[1] = 0;
1097
1098 /* Revert mouse. */
1099 if (walk->is_reversed) {
1100 moffset[1] = -moffset[1];
1101 }
1102
1103 if (walk->rv3d->persp == RV3D_CAMOB && (walk->rv3d->rflag & RV3D_FLIP_X) != 0) {
1104 moffset[0] = -moffset[0];
1105 moffset[1] = -moffset[1];
1106 }
1107
1108 /* Update jump height. */
1111 }
1112
1113 /* Should we redraw? */
1114 if ((walk->active_directions) || moffset[0] || moffset[1] ||
1116 walk->teleport.state == WALK_TELEPORT_STATE_ON || is_confirm)
1117 {
1118 bool changed_viewquat = false;
1119
1120 /* Apply the "scene" grid scale to support navigation around scenes of different sizes. */
1121 bool dvec_grid_scale = true;
1122 float dvec_tmp[3];
1123
1124 /* Time how fast it takes for us to redraw,
1125 * this is so simple scenes don't walk too fast. */
1126 double time_current;
1127 float time_redraw;
1128 float time_redraw_clamped;
1129#ifdef NDOF_WALK_DRAW_TOOMUCH
1130 walk->redraw = true;
1131#endif
1132 time_current = BLI_time_now_seconds();
1133 time_redraw = float(time_current - walk->time_lastdraw);
1134
1135 /* Clamp redraw time to avoid jitter in roll correction. */
1136 time_redraw_clamped = min_ff(0.05f, time_redraw);
1137
1138 walk->time_lastdraw = time_current;
1139
1140 /* Base speed in m/s. */
1141 walk->speed = WALK_MOVE_SPEED;
1142
1143 if (walk->is_fast) {
1144 walk->speed *= WALK_BOOST_FACTOR;
1145 }
1146 else if (walk->is_slow) {
1147 walk->speed *= 1.0f / WALK_BOOST_FACTOR;
1148 }
1149
1150 copy_m3_m4(mat, rv3d->viewinv);
1151
1152 {
1153 /* Rotate about the X axis- look up/down. */
1154 if (moffset[1]) {
1155 float upvec[3];
1156 float angle;
1157 float y;
1158
1159 /* Relative offset. */
1160 y = float(moffset[1]);
1161
1162 /* Speed factor. */
1163#ifdef USE_TABLET_SUPPORT
1164 if (walk->is_cursor_absolute) {
1165 y /= region->winy;
1167 }
1168 else
1169#endif
1170 {
1172 }
1173
1174 /* User adjustment factor. */
1175 y *= walk->mouse_speed;
1176
1177 /* Clamp the angle limits: it ranges from 90.0f to -90.0f. */
1178 angle = -asinf(rv3d->viewmat[2][2]);
1179
1180 if (angle > WALK_TOP_LIMIT && y > 0.0f) {
1181 y = 0.0f;
1182 }
1183 else if (angle < WALK_BOTTOM_LIMIT && y < 0.0f) {
1184 y = 0.0f;
1185 }
1186
1187 copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
1188 mul_m3_v3(mat, upvec);
1189 /* Rotate about the relative up vector. */
1190 axis_angle_to_quat(tmp_quat, upvec, -y);
1191 mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
1192 changed_viewquat = true;
1193 }
1194
1195 /* Rotate about the Y axis- look left/right. */
1196 if (moffset[0]) {
1197 float upvec[3];
1198 float x;
1199
1200 /* If we're upside down invert the `moffset`. */
1201 copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f);
1202 mul_m3_v3(mat, upvec);
1203
1204 if (upvec[2] < 0.0f) {
1205 moffset[0] = -moffset[0];
1206 }
1207
1208 /* Relative offset. */
1209 x = float(moffset[0]);
1210
1211 /* Speed factor. */
1212#ifdef USE_TABLET_SUPPORT
1213 if (walk->is_cursor_absolute) {
1214 x /= region->winx;
1216 }
1217 else
1218#endif
1219 {
1221 }
1222
1223 /* User adjustment factor. */
1224 x *= walk->mouse_speed;
1225
1226 /* Rotate about the relative up vector */
1227 axis_angle_to_quat_single(tmp_quat, 'Z', x);
1228 mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
1229 changed_viewquat = true;
1230 }
1231
1232 if (walk->zlock == WALK_AXISLOCK_STATE_ACTIVE) {
1233 const float horizon_plane[3] = {0.0f, 0.0f, 1.0f};
1234 const float factor = 5.0f * time_redraw_clamped * walk->zlock_momentum *
1236 /* Make sure we have some Z rolling. */
1237 if (view3d_horizon_correct_quat_ease_out(rv3d->viewquat, horizon_plane, false, factor) !=
1238 0.0f)
1239 {
1240 changed_viewquat = true;
1241
1243 }
1244 else {
1245 /* Lock fixed, don't need to check it ever again. */
1247 }
1248 }
1249 }
1250
1251 /* WASD - 'move' translation code. */
1252 if ((walk->active_directions) && (walk->gravity_state == WALK_GRAVITY_STATE_OFF)) {
1253
1254 short direction;
1255 zero_v3(dvec);
1256
1259 {
1260
1261 direction = 0;
1262
1264 direction += 1;
1265 }
1266
1268 direction -= 1;
1269 }
1270
1271 copy_v3_fl3(dvec_tmp, 0.0f, 0.0f, direction);
1272 mul_m3_v3(mat, dvec_tmp);
1273
1274 if (walk->navigation_mode == WALK_MODE_GRAVITY) {
1275 dvec_tmp[2] = 0.0f;
1276 }
1277
1278 add_v3_v3(dvec, dvec_tmp);
1279 }
1280
1281 if ((walk->active_directions & WALK_BIT_LOCAL_LEFT) ||
1283 {
1284
1285 direction = 0;
1286
1288 direction += 1;
1289 }
1290
1292 direction -= 1;
1293 }
1294
1295 dvec_tmp[0] = direction * rv3d->viewinv[0][0];
1296 dvec_tmp[1] = direction * rv3d->viewinv[0][1];
1297 dvec_tmp[2] = 0.0f;
1298
1299 add_v3_v3(dvec, dvec_tmp);
1300 }
1301
1302 /* Up and down movement is only available in free mode, not gravity mode. */
1303 if (walk->navigation_mode == WALK_MODE_FREE) {
1304
1306
1307 direction = 0;
1308
1310 direction -= 1;
1311 }
1312
1314 direction += 1;
1315 }
1316
1317 copy_v3_fl3(dvec_tmp, 0.0f, 0.0f, direction);
1318 add_v3_v3(dvec, dvec_tmp);
1319 }
1320
1322
1323 direction = 0;
1324
1326 direction -= 1;
1327 }
1328
1330 direction += 1;
1331 }
1332
1333 madd_v3_v3fl(dvec, rv3d->viewinv[1], direction);
1334 }
1335 }
1336
1337 normalize_v3(dvec);
1338
1339 /* Apply movement. */
1340 mul_v3_fl(dvec, walk->speed * time_redraw);
1341 }
1342
1343 /* Stick to the floor. */
1344 if (walk->navigation_mode == WALK_MODE_GRAVITY &&
1346 {
1347 float ray_distance;
1348 float difference = -100.0f;
1349
1350 if (walk_floor_distance_get(rv3d, walk, dvec, &ray_distance)) {
1351 difference = walk->view_height - ray_distance;
1352 }
1353
1354 /* The distance we would fall naturally smoothly enough that we
1355 * can manually drop the object without activating gravity. */
1356 const float fall_distance = time_redraw * walk->speed * WALK_BOOST_FACTOR;
1357
1358 if (fabsf(difference) < fall_distance) {
1359 /* slope/stairs */
1360 dvec[2] -= difference;
1361
1362 /* In case we switched from FREE to GRAVITY too close to the ground. */
1365 }
1366 }
1367 else {
1368 /* Hijack the teleport variables. */
1371 walk->teleport.duration = 0.0f;
1372
1373 copy_v3_v3(walk->teleport.origin, walk->rv3d->viewinv[3]);
1374 copy_v2_v2(walk->teleport.direction, dvec);
1375 }
1376 }
1377
1378 /* Falling or jumping. */
1380 float ray_distance, difference = -100.0f;
1381 /* Delta time. */
1382 const float t = float(BLI_time_now_seconds() - walk->teleport.initial_time);
1383
1384 /* Keep moving if we were moving. */
1385 copy_v2_v2(dvec, walk->teleport.direction);
1386
1387 const float z_cur = walk->rv3d->viewinv[3][2] / walk->grid;
1388 const float z_new = ((walk->teleport.origin[2] / walk->grid) -
1390 /* Jump. */
1391 (t * walk->speed_jump);
1392
1393 /* Duration is the jump duration. */
1394 if (t > walk->teleport.duration) {
1395
1396 /* Check to see if we are landing. */
1397 if (walk_floor_distance_get(rv3d, walk, dvec, &ray_distance)) {
1398 difference = walk->view_height - ray_distance;
1399 }
1400
1401 if (difference > 0.0f) {
1402 /* Quit falling, lands at "view_height" from the floor. */
1403 dvec[2] -= difference;
1405 walk->speed_jump = 0.0f;
1406 }
1407 else {
1408 /* Keep falling. */
1409 dvec[2] = z_cur - z_new;
1410 }
1411 }
1412 else {
1413 /* Keep going up (jump). */
1414 dvec[2] = z_cur - z_new;
1415 }
1416 }
1417
1418 /* Teleport. */
1419 else if (walk->teleport.state == WALK_TELEPORT_STATE_ON) {
1420 float t; /* factor */
1421 float new_loc[3];
1422 float cur_loc[3];
1423
1424 /* Linear interpolation. */
1426 t /= walk->teleport.duration;
1427
1428 /* Clamp so we don't go past our limit. */
1429 if (t >= 1.0f) {
1430 t = 1.0f;
1433 }
1434
1435 mul_v3_v3fl(new_loc, walk->teleport.direction, t);
1436 add_v3_v3(new_loc, walk->teleport.origin);
1437
1438 copy_v3_v3(cur_loc, walk->rv3d->viewinv[3]);
1439 sub_v3_v3v3(dvec, cur_loc, new_loc);
1440
1441 /* It doesn't make sense to scale the direction for teleport
1442 * as this value is interpolate between two points. */
1443 dvec_grid_scale = false;
1444 }
1445
1446 /* Scale the movement to the scene size. */
1447 mul_v3_v3fl(dvec_tmp, dvec, dvec_grid_scale ? walk->grid : 1.0f);
1448 add_v3_v3(rv3d->ofs, dvec_tmp);
1449
1450 if (changed_viewquat) {
1451 /* While operations here are expected to keep the quaternion normalized,
1452 * over time floating point error can accumulate error and eventually cause
1453 * it not to be normalized, so - normalize when modified to avoid errors.
1454 * See: #125586. */
1455 normalize_qt(rv3d->viewquat);
1456 }
1457
1458 if (rv3d->persp == RV3D_CAMOB) {
1459 walk->need_rotation_keyframe |= (moffset[0] || moffset[1] ||
1463 C, walk, walk->need_rotation_keyframe, walk->need_translation_keyframe, is_confirm);
1464 }
1465 }
1466 else {
1467 /* We're not redrawing but we need to update the time else the view will jump. */
1469 }
1470 /* End drawing. */
1471 copy_v3_v3(walk->dvec_prev, dvec);
1472
1473 return OPERATOR_FINISHED;
1474#undef WALK_ROTATE_TABLET_FAC
1475#undef WALK_TOP_LIMIT
1476#undef WALK_BOTTOM_LIMIT
1477#undef WALK_MOVE_SPEED
1478#undef WALK_JUMP_HEIGHT
1479#undef WALK_BOOST_FACTOR
1480}
1481
1482#ifdef WITH_INPUT_NDOF
1483static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm)
1484{
1485 Object *lock_ob = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control);
1486 bool has_translate, has_rotate;
1487
1488 view3d_ndof_fly(*walk->ndof,
1489 walk->v3d,
1490 walk->rv3d,
1491 walk->is_slow,
1492 lock_ob ? lock_ob->protectflag : 0,
1493 &has_translate,
1494 &has_rotate);
1495
1496 if (has_translate || has_rotate) {
1497 walk->redraw = true;
1498
1499 if (walk->rv3d->persp == RV3D_CAMOB) {
1500 walk->need_rotation_keyframe |= has_rotate;
1501 walk->need_translation_keyframe |= has_translate;
1503 C, walk, walk->need_rotation_keyframe, walk->need_translation_keyframe, is_confirm);
1504 }
1505 }
1506}
1507#endif /* WITH_INPUT_NDOF */
1508
1510
1511/* -------------------------------------------------------------------- */
1514
1516{
1517 WalkInfo *walk = static_cast<WalkInfo *>(op->customdata);
1518
1519 WorkspaceStatus status(C);
1520
1521 status.opmodal(IFACE_("Confirm"), op->type, WALK_MODAL_CONFIRM);
1522 status.opmodal(IFACE_("Cancel"), op->type, WALK_MODAL_CANCEL);
1523
1524 status.opmodal(
1527 status.opmodal(
1529 status.opmodal(
1531 status.item(IFACE_("Move"), ICON_NONE);
1532
1534 status.opmodal(
1536 status.item(IFACE_("Up/Down"), ICON_NONE);
1537
1538 status.opmodal(
1540 status.opmodal(
1542 status.item(IFACE_("Local Up/Down"), ICON_NONE);
1543
1544 status.opmodal(
1546
1547 status.opmodal(IFACE_("Teleport"),
1548 op->type,
1551
1552 status.opmodal(IFACE_("Fast"), op->type, WALK_MODAL_FAST_ENABLE, walk->is_fast);
1553 status.opmodal(IFACE_("Slow"), op->type, WALK_MODAL_SLOW_ENABLE, walk->is_slow);
1554
1555 status.opmodal(IFACE_("Gravity"),
1556 op->type,
1559
1560 status.opmodal("", op->type, WALK_MODAL_ACCELERATE);
1561 status.opmodal("", op->type, WALK_MODAL_DECELERATE);
1562 status.item(fmt::format("{} ({:.2f})", IFACE_("Acceleration"), g_walk.base_speed), ICON_NONE);
1563
1564 status.opmodal("", op->type, WALK_MODAL_INCREASE_JUMP);
1565 status.opmodal("", op->type, WALK_MODAL_DECREASE_JUMP);
1566 status.item(fmt::format("{} ({:.2f})", IFACE_("Jump Height"), g_walk.jump_height), ICON_NONE);
1567
1568 status.opmodal(IFACE_("Z Axis Correction"),
1569 op->type,
1572}
1573
1575{
1578 return OPERATOR_CANCELLED;
1579 }
1580
1581 WalkInfo *walk = MEM_new_zeroed<WalkInfo>("NavigationWalkOperation");
1582
1583 op->customdata = walk;
1584
1585 if (initWalkInfo(C, walk, op, event->mval) == false) {
1586 MEM_delete(walk);
1587 return OPERATOR_CANCELLED;
1588 }
1589
1590 walkEvent(walk, event);
1591
1592 walk_draw_status(C, op);
1593
1595
1597}
1598
1600{
1601 WalkInfo *walk = static_cast<WalkInfo *>(op->customdata);
1602
1603 walk->state = WALK_CANCEL;
1604 walkEnd(C, walk);
1605 op->customdata = nullptr;
1606}
1607
1609{
1610 bool do_draw = false;
1611 WalkInfo *walk = static_cast<WalkInfo *>(op->customdata);
1612 ARegion *region = walk->region;
1613 View3D *v3d = walk->v3d;
1614 RegionView3D *rv3d = walk->rv3d;
1616
1617 walk->redraw = false;
1618
1619 walkEvent(walk, event);
1620
1621 walk_draw_status(C, op);
1622
1623#ifdef WITH_INPUT_NDOF
1624 if (walk->ndof) { /* 3D mouse overrules [2D mouse + timer]. */
1625 if (event->type == NDOF_MOTION) {
1626 walkApply_ndof(C, walk, false);
1627 }
1628 }
1629 else
1630#endif /* WITH_INPUT_NDOF */
1631 {
1632 if (event->type == TIMER && event->customdata == walk->timer) {
1633 walkApply(C, walk, false);
1634 }
1635 }
1636
1637 do_draw |= walk->redraw;
1638
1639 const wmOperatorStatus exit_code = walkEnd(C, walk);
1640
1641 if (exit_code != OPERATOR_RUNNING_MODAL) {
1642 do_draw = true;
1643 }
1644 if (exit_code == OPERATOR_FINISHED) {
1645 const bool is_undo_pushed = ED_view3d_camera_lock_undo_push(op->type->name, v3d, rv3d, C);
1646 /* If generic 'locked camera' code did not push an undo, but there is a valid 'walking
1647 * object', an undo push is still needed, since that object transform was modified. */
1648 if (!is_undo_pushed && walk_object && ED_undo_is_memfile_compatible(C)) {
1649 ED_undo_push(C, op->type->name);
1650 }
1651 }
1652
1653 if (do_draw) {
1654 if (rv3d->persp == RV3D_CAMOB) {
1656 }
1657
1658 /* Too frequent, commented with `NDOF_WALK_DRAW_TOOMUCH` for now. */
1659 // puts("redraw!");
1660 ED_region_tag_redraw(region);
1661 }
1662 return exit_code;
1663}
1664
1666{
1667 /* Identifiers. */
1668 ot->name = "Walk Navigation";
1669 ot->description = "Interactively walk around the scene";
1670 ot->idname = "VIEW3D_OT_walk";
1671
1672 /* API callbacks. */
1673 ot->invoke = walk_invoke;
1674 ot->cancel = walk_cancel;
1675 ot->modal = walk_modal;
1677
1678 /* flags */
1679 /* NOTE: #OPTYPE_BLOCKING isn't used because this needs to grab & hide the cursor.
1680 * where as blocking confines the cursor to the window bounds, even when hidden. */
1681 ot->flag = 0;
1682}
1683
1685
1686} // namespace blender
Camera data-block and utility functions.
#define ENUM_OPERATORS(_enum_type)
#define BVH_RAYCAST_DIST_MAX
Platform independent time functions.
#define IFACE_(msgid)
Object is a sort of wrapper for general info.
#define RV3D_LOCK_FLAGS(rv3d)
#define REGION_DRAW_POST_PIXEL
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_TRANSFORM
Definition WM_types.hh:475
#define NC_OBJECT
Definition WM_types.hh:392
#define ELEM(...)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
Definition area.cc:1107
#define asinf(x)
#define FLT_EPSILON
float distance(float, float) RET
void snap_object_context_destroy(SnapObjectContext *sctx)
SnapObjectContext * snap_object_context_create()
bool snap_object_project_ray(SnapObjectContext *sctx, Depsgraph *depsgraph, const View3D *v3d, const SnapObjectParams *params, const float ray_start[3], const float ray_normal[3], float *ray_depth, float r_co[3], float r_no[3])
BMesh Iterators.
MINLINE float min_ff(float a, float b)
UserDef U
Definition blender.cc:58
void mul_m3_v3(const float M[3][3], float r[3])
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
void immEnd()
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
bool ED_undo_is_memfile_compatible(const bContext *C)
Definition ed_undo.cc:588
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static void drawWalkPixel(const bContext *, ARegion *region, void *arg)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
@ WM_CURSOR_WRAP_NONE
Definition WM_types.hh:239
static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
Object * ED_view3d_cameracontrol_object_get(View3DCameraControl *vctrl)
static void walk_draw_status(bContext *C, wmOperator *op)
float normalize_qt(float q[4])
bool ED_view3d_camera_lock_undo_push(const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
void immBegin(GPUPrimType, uint vertex_len)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
wmWindow * CTX_wm_window(const bContext *C)
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
static struct blender::@320262344277007237041155264327207227220301061033 g_walk
@ RV3D_LOCK_ANY_TRANSFORM
void immUniformThemeColorAlpha(int color_id, float a)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void immUnbindProgram()
static void walk_cancel(bContext *C, wmOperator *op)
MINLINE void mul_v3_fl(float r[3], float f)
static float walk_calc_free_fall_distance(const float gravity, const float time)
void ED_view3d_cameracontrol_release(View3DCameraControl *vctrl, const bool restore)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
static wmOperatorStatus walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
static void walkMoveCamera(bContext *C, WalkInfo *walk, const bool do_rotate, const bool do_translate, const bool is_confirm)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void WM_cursor_grab_enable(wmWindow *win, const eWM_CursorWrapAxis wrap, const rcti *wrap_region, const bool hide)
bool BKE_constraint_has_influence(const struct bConstraint *con)
static float walk_calc_velocity_zero_time(const float gravity, const float velocity)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
View3DCameraControl * ED_view3d_cameracontrol_acquire(Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
rctf BKE_camera_view_border(const struct Scene *scene, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winx, int winy, bool no_shift, bool no_zoom, bool no_roll)
void axis_angle_to_quat_single(float q[4], char axis, float angle)
static void walkEvent(WalkInfo *walk, const wmEvent *event)
MINLINE void negate_v3(float r[3])
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
static wmOperatorStatus walkEnd(bContext *C, WalkInfo *walk)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float n[3])
bool ED_view3d_offset_lock_check(const View3D *v3d, const RegionView3D *rv3d)
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
Main * CTX_data_main(const bContext *C)
static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int mval[2])
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
MINLINE float max_ff(float a, float b)
MINLINE float normalize_v3_length(float n[3], float unit_length)
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool ED_operator_region_view3d_active(bContext *C)
@ P_STARTING
Definition WM_types.hh:913
@ P_FINISHING
Definition WM_types.hh:917
@ P_IN_PROGRESS
Definition WM_types.hh:915
static bool walk_ray_cast(RegionView3D *rv3d, WalkInfo *walk, float r_location[3], float r_normal[3], float *r_ray_distance)
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
double BLI_time_now_seconds()
Definition time.cc:30
Scene * CTX_data_scene(const bContext *C)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
void VIEW3D_OT_walk(wmOperatorType *ot)
static bool walk_floor_distance_get(RegionView3D *rv3d, WalkInfo *walk, const float dvec[3], float *r_distance)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
void ED_view3d_cameracontrol_update(View3DCameraControl *vctrl, const bool use_autokey, bContext *C, const bool do_rotate, const bool do_translate)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
float view3d_horizon_correct_quat_ease_out(float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float factor)
View3D * CTX_wm_view3d(const bContext *C)
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
void walk_modal_keymap(wmKeyConfig *keyconf)
static wmOperatorStatus walk_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void walk_navigation_mode_set(WalkInfo *walk, eWalkMethod mode)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
ListBaseT< bConstraint > constraints
eRegionView3D_Flag rflag
eRegionView3D_Persp persp
struct PhysicsSettings physics_settings
struct UnitSettings unit
struct Object * camera
ed::transform::SnapObjectContext * snap_context
eWalkGravityState gravity_state
eWalkDirectionFlag active_directions
View3DCameraControl * v3d_camera_control
struct ARegionType * type
wmTabletData tablet
Definition WM_types.hh:846
wmEventType type
Definition WM_types.hh:817
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
struct wmOperatorType * type
#define WALK_JUMP_HEIGHT
#define WALK_ROTATE_TABLET_FAC
#define JUMP_SPEED_MAX
#define WALK_MOVE_SPEED
#define WALK_ROTATE_CONSTANT_FAC
#define JUMP_TIME_MAX
#define JUMP_HEIGHT_MAX
#define WALK_TOP_LIMIT
#define WALK_ZUP_CORRECT_ACCEL
#define WALK_ZUP_CORRECT_FAC
#define WALK_BOOST_FACTOR
#define JUMP_HEIGHT_FACTOR
#define JUMP_HEIGHT_MIN
#define JUMP_SPEED_MIN
#define WALK_BOTTOM_LIMIT
#define ISMOUSE_MOTION(event_type)