24 #ifdef WITH_INPUT_NDOF
27 HAS_TRANSLATE = (1 << 0),
28 HAS_ROTATE = (1 << 0),
31 static bool ndof_has_translate(
const wmNDOFMotionData *ndof,
38 static bool ndof_has_rotate(
const wmNDOFMotionData *ndof,
const RegionView3D *rv3d)
46 static float view3d_ndof_pan_speed_calc_ex(
RegionView3D *rv3d,
const float depth_pt[3])
57 static float view3d_ndof_pan_speed_calc_from_dist(
RegionView3D *rv3d,
const float dist)
73 return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
76 static float view3d_ndof_pan_speed_calc(
RegionView3D *rv3d)
81 return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
90 static void view3d_ndof_pan_zoom(
const struct wmNDOFMotionData *ndof,
93 const bool has_translate,
100 if (has_translate ==
false && has_zoom ==
false) {
104 WM_event_ndof_pan_get(ndof, pan_vec,
false);
118 float zoom_distance = rv3d->
dist * ndof->dt * ndof->tvec[2];
121 zoom_distance = -zoom_distance;
124 rv3d->
dist += zoom_distance;
137 const float speed = view3d_ndof_pan_speed_calc(rv3d);
154 static void view3d_ndof_orbit(
const struct wmNDOFMotionData *ndof,
158 const bool apply_dyn_ofs)
177 float angle, quat[4];
178 float xvec[3] = {1, 0, 0};
181 WM_event_ndof_rotate_get(ndof,
rot);
206 float angle = WM_event_ndof_to_axis_angle(ndof, axis);
226 void view3d_ndof_fly(
const wmNDOFMotionData *ndof,
229 const bool use_precision,
230 const short protectflag,
231 bool *r_has_translate,
234 bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
235 bool has_rotate = ndof_has_rotate(ndof, rv3d);
245 float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f);
246 float trans[3], trans_orig_y;
252 WM_event_ndof_pan_get(ndof, trans,
false);
254 trans_orig_y = trans[1];
265 trans[2] = trans_orig_y;
285 has_translate =
true;
288 has_translate =
false;
293 const float turn_sensitivity = 1.0f;
297 float angle = turn_sensitivity * WM_event_ndof_to_axis_angle(ndof, axis);
316 float view_horizon[3] = {1.0f, 0.0f, 0.0f};
317 float view_direction[3] = {0.0f, 0.0f, -1.0f};
343 *r_has_translate = has_translate;
344 *r_has_rotate = has_rotate;
357 static int view3d_ndof_cameraview_pan_zoom(
bContext *
C,
const wmEvent *event)
359 const wmNDOFMotionData *ndof =
event->customdata;
373 const bool has_translate = !
is_zero_v2(ndof->tvec);
374 const bool has_zoom = ndof->tvec[2] != 0.0f;
377 WM_event_ndof_pan_get(ndof, pan_vec,
true);
380 pan_vec[2] *= -ndof->dt;
389 if (!(has_translate || has_zoom)) {
393 bool changed =
false;
397 float event_ofs[2] = {pan_vec[0] * speed, pan_vec[1] * speed};
404 const float scale = 1.0f + pan_vec[2];
435 const wmNDOFMotionData *ndof =
event->customdata;
451 const bool has_rotation = ndof_has_rotate(ndof, rv3d);
453 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) &&
455 const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->
is_persp;
457 if (has_translate || has_zoom) {
458 view3d_ndof_pan_zoom(ndof, vod->
area, vod->
region, has_translate, has_zoom);
459 xform_flag |= HAS_TRANSLATE;
463 view3d_ndof_orbit(ndof, vod->
area, vod->
region, vod,
true);
464 xform_flag |= HAS_ROTATE;
471 v3d, rv3d,
C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
485 ot->
name =
"NDOF Orbit View";
487 ot->
idname =
"VIEW3D_OT_ndof_orbit";
510 const int camera_retval = view3d_ndof_cameraview_pan_zoom(
C, event);
512 return camera_retval;
522 const wmNDOFMotionData *ndof =
event->customdata;
542 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
545 if (has_translate || has_zoom) {
546 view3d_ndof_pan_zoom(ndof, vod->
area, vod->
region, has_translate,
true);
547 xform_flag |= HAS_TRANSLATE;
556 const bool has_rotation = ndof_has_rotate(ndof, rv3d);
557 bool has_translate, has_zoom;
559 if (is_orbit_around_pivot) {
561 has_translate = !
is_zero_v2(ndof->tvec) && ndof_has_translate(ndof, v3d, rv3d);
562 has_zoom = (ndof->tvec[2] != 0.0f);
566 has_translate = ndof_has_translate(ndof, v3d, rv3d);
572 const float dist_backup = rv3d->
dist;
573 if (!is_orbit_around_pivot) {
576 view3d_ndof_orbit(ndof, vod->
area, vod->
region, vod, is_orbit_around_pivot);
577 xform_flag |= HAS_ROTATE;
578 if (!is_orbit_around_pivot) {
583 if (has_translate || has_zoom) {
584 view3d_ndof_pan_zoom(ndof, vod->
area, vod->
region, has_translate, has_zoom);
585 xform_flag |= HAS_TRANSLATE;
592 v3d, rv3d,
C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
606 ot->
name =
"NDOF Orbit View with Zoom";
607 ot->
description =
"Orbit and zoom the view using the 3D mouse";
608 ot->
idname =
"VIEW3D_OT_ndof_orbit_zoom";
611 ot->
invoke = ndof_orbit_zoom_invoke;
631 const int camera_retval = view3d_ndof_cameraview_pan_zoom(
C, event);
633 return camera_retval;
640 const wmNDOFMotionData *ndof =
event->customdata;
643 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
644 const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->
is_persp;
649 if (!(has_translate || has_zoom)) {
659 if (has_translate || has_zoom) {
660 view3d_ndof_pan_zoom(ndof,
area, region, has_translate, has_zoom);
661 xform_flag |= HAS_TRANSLATE;
678 ot->
name =
"NDOF Pan View";
702 const int ndof_flag =
U.ndof_flag;
707 ret = ndof_orbit_zoom_invoke(
C, op, event);
709 U.ndof_flag = ndof_flag;
717 ot->
name =
"NDOF Transform View";
718 ot->
description =
"Pan and rotate the view with the 3D mouse";
struct ScrArea * CTX_wm_area(const bContext *C)
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
struct View3D * CTX_wm_view3d(const bContext *C)
struct ARegion * CTX_wm_region(const bContext *C)
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
void mul_mat3_m4_v3(const float M[4][4], float r[3])
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void axis_angle_to_quat_single(float q[4], char axis, float angle)
void mul_qt_v3(const float q[4], float r[3])
void invert_qt_qt_normalized(float q1[4], const float q2[4])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
MINLINE bool is_zero_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
struct Depsgraph Depsgraph
#define NDOF_PIXELS_PER_SECOND
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_LOCK_FLAGS(rv3d)
void ED_region_tag_redraw(struct ARegion *region)
bool ED_operator_view3d_active(struct bContext *C)
bool ED_view3d_camera_view_pan(struct ARegion *region, const float event_ofs[2])
void ED_view3d_distance_set(struct RegionView3D *rv3d, float dist)
bool ED_view3d_camera_lock_sync(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d)
bool ED_view3d_offset_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d)
bool ED_view3d_persp_ensure(const struct Depsgraph *depsgraph, struct View3D *v3d, struct ARegion *region)
bool ED_view3d_camera_view_zoom_scale(struct RegionView3D *rv3d, const float scale)
bool ED_view3d_camera_lock_autokey(struct View3D *v3d, struct RegionView3D *rv3d, struct bContext *C, bool do_rotate, bool do_translate)
void ED_view3d_camera_lock_init_ex(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d, bool calc_dist)
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3])
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
const Depsgraph * depsgraph
static void area(int d1, int d2, int e1, int e2, float weights[2])
struct RegionView3D * rv3d
struct Depsgraph * depsgraph
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
void view3d_boxview_sync(struct ScrArea *area, struct ARegion *region)
void viewops_data_free(bContext *C, ViewOpsData *vod)
ViewOpsData * viewops_data_create(bContext *C, const wmEvent *event, enum eViewOpsFlag viewops_flag)
enum eViewOpsFlag viewops_flag_from_prefs(void)
void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
@ VIEWOPS_FLAG_DEPTH_NAVIGATE
void ED_view3d_smooth_view_force_finish(struct bContext *C, struct View3D *v3d, struct ARegion *region)