26 HAS_TRANSLATE = (1 << 0),
27 HAS_ROTATE = (1 << 0),
30static bool ndof_has_translate(
const wmNDOFMotionData *ndof,
37static bool ndof_has_rotate(
const wmNDOFMotionData *ndof,
const RegionView3D *rv3d)
45static float view3d_ndof_pan_speed_calc_ex(
RegionView3D *rv3d,
const float depth_pt[3])
56static float view3d_ndof_pan_speed_calc_from_dist(
RegionView3D *rv3d,
const float dist)
72 return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
75static float view3d_ndof_pan_speed_calc(
RegionView3D *rv3d)
80 return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
89static void view3d_ndof_pan_zoom(
const wmNDOFMotionData *ndof,
92 const bool has_translate,
99 if (has_translate ==
false && has_zoom ==
false) {
103 WM_event_ndof_pan_get(ndof, pan_vec,
false);
117 float zoom_distance = rv3d->
dist * ndof->dt * ndof->tvec[2];
120 zoom_distance = -zoom_distance;
123 rv3d->
dist += zoom_distance;
136 const float speed = view3d_ndof_pan_speed_calc(rv3d);
153static void view3d_ndof_orbit(
const wmNDOFMotionData *ndof,
157 const bool apply_dyn_ofs)
159 View3D *v3d =
static_cast<View3D *
>(area->spacedata.first);
176 float angle, quat[4];
177 float xvec[3] = {1, 0, 0};
180 WM_event_ndof_rotate_get(ndof,
rot);
186 angle = ndof->dt *
rot[0];
191 angle = ndof->dt *
rot[1];
205 float angle = WM_event_ndof_to_axis_angle(ndof, axis);
225void view3d_ndof_fly(
const wmNDOFMotionData *ndof,
228 const bool use_precision,
229 const short protectflag,
230 bool *r_has_translate,
233 bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
234 bool has_rotate = ndof_has_rotate(ndof, rv3d);
244 float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f);
245 float trans[3], trans_orig_y;
251 WM_event_ndof_pan_get(ndof, trans,
false);
253 trans_orig_y = trans[1];
264 trans[2] = trans_orig_y;
284 has_translate =
true;
287 has_translate =
false;
292 const float turn_sensitivity = 1.0f;
296 float angle = turn_sensitivity * WM_event_ndof_to_axis_angle(ndof, axis);
298 if (
fabsf(angle) > 0.0001f) {
315 float view_horizon[3] = {1.0f, 0.0f, 0.0f};
316 float view_direction[3] = {0.0f, 0.0f, -1.0f};
328 angle = -
asinf(view_horizon[2]);
342 *r_has_translate = has_translate;
343 *r_has_rotate = has_rotate;
356static int view3d_ndof_cameraview_pan_zoom(
ViewOpsData *vod,
const wmNDOFMotionData *ndof)
370 const bool has_translate = !
is_zero_v2(ndof->tvec);
371 const bool has_zoom = ndof->tvec[2] != 0.0f;
374 WM_event_ndof_pan_get(ndof, pan_vec,
true);
388 if (!(has_translate || has_zoom)) {
392 bool changed =
false;
420static int ndof_orbit_invoke_impl(
bContext *C,
434 const wmNDOFMotionData *ndof =
static_cast<const wmNDOFMotionData *
>(
event->customdata);
440 const bool has_rotation = ndof_has_rotate(ndof, rv3d);
442 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) &&
444 const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->
is_persp;
446 if (has_translate || has_zoom) {
447 view3d_ndof_pan_zoom(ndof, vod->
area, vod->
region, has_translate, has_zoom);
448 xform_flag |= HAS_TRANSLATE;
452 view3d_ndof_orbit(ndof, vod->
area, vod->
region, vod,
true);
453 xform_flag |= HAS_ROTATE;
460 v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
480 ot->
name =
"NDOF Orbit View";
482 ot->
idname = ViewOpsType_ndof_orbit.idname;
498static int ndof_orbit_zoom_invoke_impl(
bContext *C,
507 const wmNDOFMotionData *ndof =
static_cast<const wmNDOFMotionData *
>(
event->customdata);
510 const int camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof);
512 return camera_retval;
528 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
531 if (has_translate || has_zoom) {
532 view3d_ndof_pan_zoom(ndof, vod->
area, vod->
region, has_translate,
true);
533 xform_flag |= HAS_TRANSLATE;
542 const bool has_rotation = ndof_has_rotate(ndof, rv3d);
543 bool has_translate, has_zoom;
545 if (is_orbit_around_pivot) {
547 has_translate = !
is_zero_v2(ndof->tvec) && ndof_has_translate(ndof, v3d, rv3d);
548 has_zoom = (ndof->tvec[2] != 0.0f);
552 has_translate = ndof_has_translate(ndof, v3d, rv3d);
558 const float dist_backup = rv3d->
dist;
559 if (!is_orbit_around_pivot) {
562 view3d_ndof_orbit(ndof, vod->
area, vod->
region, vod, is_orbit_around_pivot);
563 xform_flag |= HAS_ROTATE;
564 if (!is_orbit_around_pivot) {
569 if (has_translate || has_zoom) {
570 view3d_ndof_pan_zoom(ndof, vod->
area, vod->
region, has_translate, has_zoom);
571 xform_flag |= HAS_TRANSLATE;
578 v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
598 ot->
name =
"NDOF Orbit View with Zoom";
599 ot->
description =
"Orbit and zoom the view using the 3D mouse";
600 ot->
idname = ViewOpsType_ndof_orbit_zoom.idname;
603 ot->
invoke = ndof_orbit_zoom_invoke;
616static int ndof_pan_invoke_impl(
bContext *C,
625 const wmNDOFMotionData *ndof =
static_cast<const wmNDOFMotionData *
>(
event->customdata);
628 const int camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof);
630 return camera_retval;
640 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
641 const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->
is_persp;
646 if (!(has_translate || has_zoom)) {
655 if (has_translate || has_zoom) {
656 view3d_ndof_pan_zoom(ndof, area, region, has_translate, has_zoom);
657 xform_flag |= HAS_TRANSLATE;
683 ot->
name =
"NDOF Pan View";
685 ot->
idname = ViewOpsType_ndof_pan.idname;
704static int ndof_all_invoke_impl(
bContext *C,
710 const int ndof_flag =
U.ndof_flag;
713 U.ndof_flag &= ~NDOF_MODE_ORBIT;
715 ret = ndof_orbit_zoom_invoke_impl(C, vod, event,
nullptr);
717 U.ndof_flag = ndof_flag;
734 ot->
name =
"NDOF Transform View";
735 ot->
description =
"Pan and rotate the view with the 3D mouse";
736 ot->
idname = ViewOpsType_ndof_all.idname;
748 "VIEW3D_OT_ndof_orbit",
750 ndof_orbit_invoke_impl,
756 "VIEW3D_OT_ndof_orbit_zoom",
758 ndof_orbit_zoom_invoke_impl,
764 "VIEW3D_OT_ndof_pan",
766 ndof_pan_invoke_impl,
772 "VIEW3D_OT_ndof_all",
774 ndof_all_invoke_impl,
MINLINE float max_ff(float a, float b)
void mul_mat3_m4_v3(const float mat[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 bool is_zero_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
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 void copy_v3_fl3(float v[3], float x, float y, float z)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
#define NDOF_PIXELS_PER_SECOND
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_LOCK_FLAGS(rv3d)
bool ED_operator_view3d_active(bContext *C)
void ED_region_tag_redraw(ARegion *region)
void ED_view3d_distance_set(RegionView3D *rv3d, float dist)
bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *region)
bool ED_view3d_offset_lock_check(const View3D *v3d, const RegionView3D *rv3d)
bool ED_view3d_camera_view_zoom_scale(RegionView3D *rv3d, const float scale)
void ED_view3d_camera_lock_init_ex(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, bool calc_dist)
bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
bool ED_view3d_camera_lock_autokey(View3D *v3d, RegionView3D *rv3d, bContext *C, bool do_rotate, bool do_translate)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
const Depsgraph * depsgraph
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
void view3d_boxview_sync(ScrArea *area, ARegion *region)
int view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const ViewOpsType *nav_type)
void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
@ VIEWOPS_FLAG_ORBIT_SELECT