Cleanup: various minor chances to the NDOF API

- Use return values for NDOF access functions.
- Pass in event data by const reference as this is never null.
- Don't scale the angle from WM_event_ndof_to_axis_angle by the time
  delta since other functions don't do this, it's strange to make
  this an exception.
- Replace the term "pan" with "translation" since pan in Blender
  typically refers to moving the view in 2D using cursor input,
  not 3D transaction.
- Use a more descriptive term "time_delta" for the time between NDOF
  motion events.
This commit is contained in:
Campbell Barton
2025-06-14 04:48:21 +00:00
parent fac42009ff
commit 6046b81e21
13 changed files with 128 additions and 135 deletions

View File

@@ -6909,7 +6909,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
#ifdef WITH_INPUT_NDOF
static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
uiHandleButtonData *data,
const wmNDOFMotionData *ndof,
const wmNDOFMotionData &ndof,
const enum eSnapType snap,
const bool shift)
{
@@ -6917,7 +6917,7 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
float *hsv = cpicker->hsv_perceptual;
const float hsv_v_max = max_ff(hsv[2], hsv_but->softmax);
float rgb[3];
const float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
const float sensitivity = (shift ? 0.15f : 0.3f) * ndof.time_delta;
ui_but_v3_get(hsv_but, rgb);
ui_scene_linear_to_perceptual_space(hsv_but, rgb);
@@ -6925,32 +6925,32 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
switch (hsv_but->gradient_type) {
case UI_GRAD_SV:
hsv[1] += ndof->rvec[2] * sensitivity;
hsv[2] += ndof->rvec[0] * sensitivity;
hsv[1] += ndof.rvec[2] * sensitivity;
hsv[2] += ndof.rvec[0] * sensitivity;
break;
case UI_GRAD_HV:
hsv[0] += ndof->rvec[2] * sensitivity;
hsv[2] += ndof->rvec[0] * sensitivity;
hsv[0] += ndof.rvec[2] * sensitivity;
hsv[2] += ndof.rvec[0] * sensitivity;
break;
case UI_GRAD_HS:
hsv[0] += ndof->rvec[2] * sensitivity;
hsv[1] += ndof->rvec[0] * sensitivity;
hsv[0] += ndof.rvec[2] * sensitivity;
hsv[1] += ndof.rvec[0] * sensitivity;
break;
case UI_GRAD_H:
hsv[0] += ndof->rvec[2] * sensitivity;
hsv[0] += ndof.rvec[2] * sensitivity;
break;
case UI_GRAD_S:
hsv[1] += ndof->rvec[2] * sensitivity;
hsv[1] += ndof.rvec[2] * sensitivity;
break;
case UI_GRAD_V:
hsv[2] += ndof->rvec[2] * sensitivity;
hsv[2] += ndof.rvec[2] * sensitivity;
break;
case UI_GRAD_V_ALT:
case UI_GRAD_L_ALT:
/* vertical 'value' strip */
/* exception only for value strip - use the range set in but->min/max */
hsv[2] += ndof->rvec[0] * sensitivity;
hsv[2] += ndof.rvec[0] * sensitivity;
CLAMP(hsv[2], hsv_but->softmin, hsv_but->softmax);
break;
@@ -7003,7 +7003,7 @@ static int ui_do_but_HSVCUBE(
}
#ifdef WITH_INPUT_NDOF
if (event->type == NDOF_MOTION) {
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
const enum eSnapType snap = ui_event_to_snap(event);
ui_ndofedit_but_HSVCUBE(hsv_but, data, ndof, snap, event->modifier & KM_SHIFT);
@@ -7175,7 +7175,7 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but,
#ifdef WITH_INPUT_NDOF
static void ui_ndofedit_but_HSVCIRCLE(uiBut *but,
uiHandleButtonData *data,
const wmNDOFMotionData *ndof,
const wmNDOFMotionData &ndof,
const enum eSnapType snap,
const bool shift)
{
@@ -7183,7 +7183,7 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but,
float *hsv = cpicker->hsv_perceptual;
float rgb[3];
float phi, r, v[2];
const float sensitivity = (shift ? 0.06f : 0.3f) * ndof->dt;
const float sensitivity = (shift ? 0.06f : 0.3f) * ndof.time_delta;
ui_but_v3_get(but, rgb);
ui_scene_linear_to_perceptual_space(but, rgb);
@@ -7199,14 +7199,14 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but,
v[1] = r * sinf(phi);
/* Use ndof device y and x rotation to move the vector in 2d space */
v[0] += ndof->rvec[2] * sensitivity;
v[1] += ndof->rvec[0] * sensitivity;
v[0] += ndof.rvec[2] * sensitivity;
v[1] += ndof.rvec[0] * sensitivity;
/* convert back to polar coords on circle */
phi = atan2f(v[0], v[1]) / (2.0f * float(M_PI)) + 0.5f;
/* use ndof Y rotation to additionally rotate hue */
phi += ndof->rvec[1] * sensitivity * 0.5f;
phi += ndof.rvec[1] * sensitivity * 0.5f;
r = len_v2(v);
/* convert back to hsv values, in range [0,1] */
@@ -7278,7 +7278,7 @@ static int ui_do_but_HSVCIRCLE(
#ifdef WITH_INPUT_NDOF
if (event->type == NDOF_MOTION) {
const enum eSnapType snap = ui_event_to_snap(event);
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->modifier & KM_SHIFT);

View File

@@ -1521,19 +1521,18 @@ static wmOperatorStatus view2d_ndof_invoke(bContext *C, wmOperator *op, const wm
return OPERATOR_CANCELLED;
}
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
/* tune these until it feels right */
const float zoom_sensitivity = 0.5f;
const float pan_speed = NDOF_PIXELS_PER_SECOND;
const bool has_translate = !is_zero_v2(ndof->tvec) && view_pan_poll(C);
const bool has_zoom = (ndof->tvec[2] != 0.0f) && view_zoom_poll(C);
const bool has_translate = !is_zero_v2(ndof.tvec) && view_pan_poll(C);
const bool has_zoom = (ndof.tvec[2] != 0.0f) && view_zoom_poll(C);
float pan_vec[3];
WM_event_ndof_pan_get(ndof, pan_vec);
blender::float3 pan_vec = WM_event_ndof_translation_get(ndof);
if (has_translate) {
mul_v2_fl(pan_vec, ndof->dt * pan_speed);
mul_v2_fl(pan_vec, ndof.time_delta * pan_speed);
view_pan_init(C, op);
@@ -1544,7 +1543,7 @@ static wmOperatorStatus view2d_ndof_invoke(bContext *C, wmOperator *op, const wm
}
if (has_zoom) {
float zoom_factor = zoom_sensitivity * ndof->dt * pan_vec[2];
float zoom_factor = zoom_sensitivity * ndof.time_delta * pan_vec[2];
bool do_zoom_xy[2];
view_zoom_axis_lock_defaults(C, do_zoom_xy);

View File

@@ -1649,15 +1649,11 @@ static wmOperatorStatus clip_view_ndof_invoke(bContext *C,
SpaceClip *sc = CTX_wm_space_clip(C);
ARegion *region = CTX_wm_region(C);
float pan_vec[3];
const wmNDOFMotionData *ndof = static_cast<wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<wmNDOFMotionData *>(event->customdata);
const float pan_speed = NDOF_PIXELS_PER_SECOND;
WM_event_ndof_pan_get(ndof, pan_vec);
negate_v3(pan_vec);
mul_v3_fl(pan_vec, ndof->dt);
blender::float3 pan_vec = -ndof.time_delta * WM_event_ndof_translation_get(ndof);
mul_v2_fl(pan_vec, pan_speed / sc->zoom);
sclip_zoom_set_factor(C, max_ff(0.0f, 1.0f - pan_vec[2]), nullptr, false);

View File

@@ -790,15 +790,12 @@ static wmOperatorStatus image_view_ndof_invoke(bContext *C,
SpaceImage *sima = CTX_wm_space_image(C);
ARegion *region = CTX_wm_region(C);
float pan_vec[3];
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
const float pan_speed = NDOF_PIXELS_PER_SECOND;
WM_event_ndof_pan_get(ndof, pan_vec);
negate_v3(pan_vec);
blender::float3 pan_vec = -ndof.time_delta * WM_event_ndof_translation_get(ndof);
mul_v3_fl(pan_vec, ndof->dt);
mul_v2_fl(pan_vec, pan_speed / sima->zoom);
sima_zoom_set_factor(sima, region, max_ff(0.0f, 1.0f - pan_vec[2]), nullptr, false);

View File

@@ -286,7 +286,7 @@ struct wmNDOFMotionData;
/**
* Called from both fly mode and walk mode,
*/
void view3d_ndof_fly(const wmNDOFMotionData *ndof,
void view3d_ndof_fly(const wmNDOFMotionData &ndof,
View3D *v3d,
RegionView3D *rv3d,
bool use_precision,

View File

@@ -1041,7 +1041,7 @@ static void flyApply_ndof(bContext *C, FlyInfo *fly, bool is_confirm)
Object *lock_ob = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
bool has_translate, has_rotate;
view3d_ndof_fly(fly->ndof,
view3d_ndof_fly(*fly->ndof,
fly->v3d,
fly->rv3d,
fly->use_precision,

View File

@@ -53,16 +53,16 @@ enum {
HAS_ROTATE = (1 << 0),
};
static bool ndof_has_translate(const wmNDOFMotionData *ndof,
static bool ndof_has_translate(const wmNDOFMotionData &ndof,
const View3D *v3d,
const RegionView3D *rv3d)
{
return !is_zero_v3(ndof->tvec) && !ED_view3d_offset_lock_check(v3d, rv3d);
return !is_zero_v3(ndof.tvec) && !ED_view3d_offset_lock_check(v3d, rv3d);
}
static bool ndof_has_rotate(const wmNDOFMotionData *ndof, const RegionView3D *rv3d)
static bool ndof_has_rotate(const wmNDOFMotionData &ndof, const RegionView3D *rv3d)
{
return !is_zero_v3(ndof->rvec) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0);
return !is_zero_v3(ndof.rvec) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0);
}
/**
@@ -135,30 +135,22 @@ static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d)
* \param has_zoom: zoom, otherwise dolly,
* often `!rv3d->is_persp` since it doesn't make sense to dolly in ortho.
*/
static void view3d_ndof_pan_zoom(const wmNDOFMotionData *ndof,
static void view3d_ndof_pan_zoom(const wmNDOFMotionData &ndof,
ScrArea *area,
ARegion *region,
const bool has_translate,
const bool has_zoom)
{
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
float view_inv[4];
float pan_vec[3];
float pan_vec_no_navigation[3];
if (has_translate == false && has_zoom == false) {
return;
}
WM_event_ndof_pan_get(ndof, pan_vec_no_navigation);
negate_v3(pan_vec_no_navigation);
if (view3d_ndof_use_navigation_mode(rv3d)) {
WM_event_ndof_pan_get_for_navigation(ndof, pan_vec);
}
else {
copy_v3_v3(pan_vec, pan_vec_no_navigation);
}
blender::float3 pan_vec_no_navigation = -WM_event_ndof_translation_get(ndof);
blender::float3 pan_vec = view3d_ndof_use_navigation_mode(rv3d) ?
WM_event_ndof_translation_get_for_navigation(ndof) :
pan_vec_no_navigation;
if (has_zoom) {
/* zoom with Z */
@@ -171,8 +163,8 @@ static void view3d_ndof_pan_zoom(const wmNDOFMotionData *ndof,
pan_vec[2] = 0.0f;
/* "zoom in" or "translate"? depends on zoom mode in user settings? */
if (ndof->tvec[2]) {
float zoom_distance = rv3d->dist * ndof->dt * pan_vec_no_navigation[2];
if (ndof.tvec[2]) {
float zoom_distance = rv3d->dist * ndof.time_delta * pan_vec_no_navigation[2];
rv3d->dist += zoom_distance;
}
}
@@ -188,9 +180,10 @@ static void view3d_ndof_pan_zoom(const wmNDOFMotionData *ndof,
if (has_translate) {
const float speed = view3d_ndof_pan_speed_calc(rv3d);
mul_v3_fl(pan_vec, speed * ndof->dt);
pan_vec *= speed * ndof.time_delta;
/* transform motion from view to world coordinates */
float view_inv[4];
invert_qt_qt_normalized(view_inv, rv3d->viewquat);
mul_qt_v3(view_inv, pan_vec);
@@ -203,7 +196,7 @@ static void view3d_ndof_pan_zoom(const wmNDOFMotionData *ndof,
}
}
static void view3d_ndof_orbit(const wmNDOFMotionData *ndof,
static void view3d_ndof_orbit(const wmNDOFMotionData &ndof,
ScrArea *area,
ARegion *region,
ViewOpsData *vod,
@@ -223,15 +216,13 @@ static void view3d_ndof_orbit(const wmNDOFMotionData *ndof,
invert_qt_qt_normalized(view_inv, rv3d->viewquat);
if (U.ndof_flag & NDOF_LOCK_HORIZON) {
float rot[3];
/* Turntable view code adapted for 3D mouse use. */
float angle, quat[4];
float xvec[3] = {1, 0, 0};
float yvec[3] = {0, 1, 0};
/* only use XY, ignore Z */
WM_event_ndof_rotate_get_for_navigation(ndof, rot);
blender::float3 rot = WM_event_ndof_rotation_get_for_navigation(ndof);
/* Determine the direction of the X vector (for rotating up and down). */
mul_qt_v3(view_inv, xvec);
@@ -239,12 +230,12 @@ static void view3d_ndof_orbit(const wmNDOFMotionData *ndof,
mul_qt_v3(view_inv, yvec);
/* Perform the up/down rotation */
angle = ndof->dt * rot[0];
angle = ndof.time_delta * rot[0];
axis_angle_to_quat(quat, xvec, angle);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
/* Perform the Z rotation. */
angle = ndof->dt * rot[1];
angle = ndof.time_delta * rot[1];
/* Flip the turntable angle when the view is upside down. */
if (yvec[2] < 0.0f) {
@@ -263,7 +254,7 @@ static void view3d_ndof_orbit(const wmNDOFMotionData *ndof,
else {
float quat[4];
float axis[3];
float angle = WM_event_ndof_to_axis_angle(ndof, axis);
float angle = ndof.time_delta * WM_event_ndof_to_axis_angle(ndof, axis);
/* transform rotation axis from view to world coordinates */
mul_qt_v3(view_inv, axis);
@@ -295,7 +286,7 @@ static void view3d_ndof_orbit(const wmNDOFMotionData *ndof,
}
}
void view3d_ndof_fly(const wmNDOFMotionData *ndof,
void view3d_ndof_fly(const wmNDOFMotionData &ndof,
View3D *v3d,
RegionView3D *rv3d,
const bool use_precision,
@@ -315,14 +306,14 @@ void view3d_ndof_fly(const wmNDOFMotionData *ndof,
/* ignore real 'dist' since fly has its own speed settings,
* also its overwritten at this point. */
float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f);
float trans[3], trans_orig_y;
float trans_orig_y;
if (use_precision) {
speed *= 0.2f;
}
WM_event_ndof_pan_get(ndof, trans);
mul_v3_fl(trans, speed * ndof->dt);
blender::float3 trans = WM_event_ndof_translation_get(ndof);
mul_v3_fl(trans, speed * ndof.time_delta);
trans_orig_y = trans[1];
if (U.ndof_flag & NDOF_FLY_HELICOPTER) {
@@ -362,11 +353,9 @@ void view3d_ndof_fly(const wmNDOFMotionData *ndof,
}
if (has_rotate) {
const float turn_sensitivity = 1.0f;
float rotation[4];
float axis[3];
float angle = turn_sensitivity * WM_event_ndof_to_axis_angle(ndof, axis);
float angle = ndof.time_delta * WM_event_ndof_to_axis_angle(ndof, axis);
if (fabsf(angle) > 0.0001f) {
has_rotate = true;
@@ -602,7 +591,7 @@ static std::optional<float3> ndof_orbit_center_calc(Depsgraph *depsgraph,
* Support navigating the camera view instead of leaving the camera-view and navigating in 3D.
*/
static wmOperatorStatus view3d_ndof_cameraview_pan_zoom(ViewOpsData *vod,
const wmNDOFMotionData *ndof)
const wmNDOFMotionData &ndof)
{
View3D *v3d = vod->v3d;
ARegion *region = vod->region;
@@ -616,13 +605,11 @@ static wmOperatorStatus view3d_ndof_cameraview_pan_zoom(ViewOpsData *vod,
}
const float pan_speed = NDOF_PIXELS_PER_SECOND;
const bool has_translate = !is_zero_v2(ndof->tvec);
const bool has_zoom = ndof->tvec[2] != 0.0f;
const bool has_translate = !is_zero_v2(ndof.tvec);
const bool has_zoom = ndof.tvec[2] != 0.0f;
float pan_vec[3];
WM_event_ndof_pan_get(ndof, pan_vec);
blender::float3 pan_vec = ndof.time_delta * WM_event_ndof_translation_get(ndof);
mul_v3_fl(pan_vec, ndof->dt);
/* NOTE: unlike image and clip views, the 2D pan doesn't have to be scaled by the zoom level.
* #ED_view3d_camera_view_pan already takes the zoom level into account. */
mul_v2_fl(pan_vec, pan_speed);
@@ -684,17 +671,17 @@ static wmOperatorStatus ndof_orbit_invoke_impl(bContext *C,
RegionView3D *rv3d = vod->rv3d;
char xform_flag = 0;
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
/* off by default, until changed later this function */
rv3d->ndof_rot_angle = 0.0f;
if (ndof->progress != P_FINISHING) {
if (ndof.progress != P_FINISHING) {
const bool has_rotation = ndof_has_rotate(ndof, rv3d);
/* if we can't rotate, fall back to translate (locked axis views) */
const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) &&
(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION);
const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp;
const bool has_zoom = (ndof.tvec[2] != 0.0f) && !rv3d->is_persp;
if (has_translate || has_zoom) {
view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom);
@@ -757,7 +744,7 @@ static wmOperatorStatus ndof_orbit_zoom_invoke_impl(bContext *C,
return OPERATOR_CANCELLED;
}
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
if (U.ndof_flag & NDOF_CAMERA_PAN_ZOOM) {
const wmOperatorStatus camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof);
@@ -773,10 +760,10 @@ static wmOperatorStatus ndof_orbit_zoom_invoke_impl(bContext *C,
/* off by default, until changed later this function */
rv3d->ndof_rot_angle = 0.0f;
if (ndof->progress == P_FINISHING) {
if (ndof.progress == P_FINISHING) {
/* pass */
}
else if (ndof->progress == P_STARTING) {
else if (ndof.progress == P_STARTING) {
if (ndof_orbit_center_is_auto(v3d, rv3d)) {
/* If center was recalculated then update the point location for drawing. */
if (std::optional<float3> center_test = ndof_orbit_center_calc(
@@ -798,7 +785,7 @@ static wmOperatorStatus ndof_orbit_zoom_invoke_impl(bContext *C,
else if ((rv3d->persp == RV3D_ORTHO) && RV3D_VIEW_IS_AXIS(rv3d->view)) {
/* if we can't rotate, fall back to translate (locked axis views) */
const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
const bool has_zoom = (ndof->tvec[2] != 0.0f) && ED_view3d_offset_lock_check(v3d, rv3d);
const bool has_zoom = (ndof.tvec[2] != 0.0f) && ED_view3d_offset_lock_check(v3d, rv3d);
if (has_translate || has_zoom) {
view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, true);
@@ -816,8 +803,8 @@ static wmOperatorStatus ndof_orbit_zoom_invoke_impl(bContext *C,
if (is_orbit_around_pivot) {
/* Orbit preference or forced lock (Z zooms). */
has_translate = !is_zero_v2(ndof->tvec) && ndof_has_translate(ndof, v3d, rv3d);
has_zoom = (ndof->tvec[2] != 0.0f);
has_translate = !is_zero_v2(ndof.tvec) && ndof_has_translate(ndof, v3d, rv3d);
has_zoom = (ndof.tvec[2] != 0.0f);
}
else {
/* Free preference (Z translates). */
@@ -894,7 +881,7 @@ static wmOperatorStatus ndof_pan_invoke_impl(bContext *C,
return OPERATOR_CANCELLED;
}
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
if (U.ndof_flag & NDOF_CAMERA_PAN_ZOOM) {
const wmOperatorStatus camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof);
@@ -910,7 +897,7 @@ static wmOperatorStatus ndof_pan_invoke_impl(bContext *C,
char xform_flag = 0;
const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp;
const bool has_zoom = (ndof.tvec[2] != 0.0f) && !rv3d->is_persp;
/* we're panning here! so erase any leftover rotation from other operators */
rv3d->ndof_rot_angle = 0.0f;
@@ -921,7 +908,7 @@ static wmOperatorStatus ndof_pan_invoke_impl(bContext *C,
ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false);
if (ndof->progress != P_FINISHING) {
if (ndof.progress != P_FINISHING) {
ScrArea *area = vod->area;
if (has_translate || has_zoom) {

View File

@@ -1441,7 +1441,7 @@ static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm)
Object *lock_ob = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control);
bool has_translate, has_rotate;
view3d_ndof_fly(walk->ndof,
view3d_ndof_fly(*walk->ndof,
walk->v3d,
walk->rv3d,
walk->is_slow,

View File

@@ -30,6 +30,7 @@
# include "DNA_userdef_types.h"
# include "BLI_math_vector.h"
# include "BLI_string.h"
# include "BLI_string_utf8.h"
@@ -810,8 +811,8 @@ static void rna_Event_tilt_get(PointerRNA *ptr, float *values)
static void rna_NDOFMotionEventData_translation_get(PointerRNA *ptr, float *values)
{
# ifdef WITH_INPUT_NDOF
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(ptr->data);
WM_event_ndof_pan_get(ndof, values);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(ptr->data);
copy_v3_v3(values, WM_event_ndof_translation_get(ndof));
# else
UNUSED_VARS(ptr);
ARRAY_SET_ITEMS(values, 0, 0, 0);
@@ -821,8 +822,8 @@ static void rna_NDOFMotionEventData_translation_get(PointerRNA *ptr, float *valu
static void rna_NDOFMotionEventData_rotation_get(PointerRNA *ptr, float *values)
{
# ifdef WITH_INPUT_NDOF
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(ptr->data);
WM_event_ndof_rotate_get(ndof, values);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(ptr->data);
copy_v3_v3(values, WM_event_ndof_rotation_get(ndof));
# else
UNUSED_VARS(ptr);
ARRAY_SET_ITEMS(values, 0, 0, 0);
@@ -832,8 +833,8 @@ static void rna_NDOFMotionEventData_rotation_get(PointerRNA *ptr, float *values)
static float rna_NDOFMotionEventData_time_delta_get(PointerRNA *ptr)
{
# ifdef WITH_INPUT_NDOF
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(ptr->data);
return ndof->dt;
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(ptr->data);
return ndof.time_delta;
# else
UNUSED_VARS(ptr);
return 0.0f;
@@ -843,8 +844,8 @@ static float rna_NDOFMotionEventData_time_delta_get(PointerRNA *ptr)
static int rna_NDOFMotionEventData_progress_get(PointerRNA *ptr)
{
# ifdef WITH_INPUT_NDOF
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(ptr->data);
return static_cast<int>(ndof->progress);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(ptr->data);
return static_cast<int>(ndof.progress);
# else
UNUSED_VARS(ptr);
return 0;

View File

@@ -2011,13 +2011,13 @@ int WM_userdef_event_map(int kmitype);
int WM_userdef_event_type_from_keymap_type(int kmitype);
#ifdef WITH_INPUT_NDOF
void WM_event_ndof_pan_get_for_navigation(const wmNDOFMotionData *ndof, float r_pan[3]);
void WM_event_ndof_rotate_get_for_navigation(const wmNDOFMotionData *ndof, float r_rot[3]);
void WM_event_ndof_pan_get(const wmNDOFMotionData *ndof, float r_pan[3]);
void WM_event_ndof_rotate_get(const wmNDOFMotionData *ndof, float r_rot[3]);
blender::float3 WM_event_ndof_translation_get_for_navigation(const wmNDOFMotionData &ndof);
blender::float3 WM_event_ndof_rotation_get_for_navigation(const wmNDOFMotionData &ndof);
blender::float3 WM_event_ndof_translation_get(const wmNDOFMotionData &ndof);
blender::float3 WM_event_ndof_rotation_get(const wmNDOFMotionData &ndof);
float WM_event_ndof_to_axis_angle(const wmNDOFMotionData *ndof, float axis[3]);
void WM_event_ndof_to_quat(const wmNDOFMotionData *ndof, float q[4]);
float WM_event_ndof_to_axis_angle(const wmNDOFMotionData &ndof, float axis[3]);
void WM_event_ndof_to_quat(const wmNDOFMotionData &ndof, float q[4]);
#endif /* WITH_INPUT_NDOF */
#ifdef WITH_XR_OPENXR

View File

@@ -875,7 +875,7 @@ struct wmNDOFMotionData {
* This is reset when motion begins: when progress changes from #P_NOT_STARTED to #P_STARTING.
* In this case a dummy value is used, see #GHOST_NDOF_TIME_DELTA_STARTING.
*/
float dt;
float time_delta;
/** Is this the first event, the last, or one of many in between? */
wmProgress progress;
};

View File

@@ -133,7 +133,7 @@ void WM_event_print(const wmEvent *event)
#ifdef WITH_INPUT_NDOF
if (ISNDOF(event->type)) {
const wmNDOFMotionData *ndof = static_cast<const wmNDOFMotionData *>(event->customdata);
const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
if (event->type == NDOF_MOTION) {
const char *ndof_progress = unknown;
@@ -142,7 +142,7 @@ void WM_event_print(const wmEvent *event)
ndof_progress = STRINGIFY(id); \
break; \
}
switch (ndof->progress) {
switch (ndof.progress) {
CASE_NDOF_PROGRESS(NOT_STARTED);
CASE_NDOF_PROGRESS(STARTING);
CASE_NDOF_PROGRESS(IN_PROGRESS);
@@ -151,11 +151,16 @@ void WM_event_print(const wmEvent *event)
}
# undef CASE_NDOF_PROGRESS
printf(", ndof: rot: (%.4f %.4f %.4f), tx: (%.4f %.4f %.4f), dt: %.4f, progress: %s",
UNPACK3(ndof->rvec),
UNPACK3(ndof->tvec),
ndof->dt,
ndof_progress);
printf(
", ndof: "
"rot: (%.4f %.4f %.4f), "
"tx: (%.4f %.4f %.4f), "
"time_delta: %.4f, "
"progress: %s",
UNPACK3(ndof.rvec),
UNPACK3(ndof.tvec),
ndof.time_delta,
ndof_progress);
}
else {
/* NDOF buttons printed already. */
@@ -503,49 +508,57 @@ int WM_userdef_event_type_from_keymap_type(int kmitype)
#ifdef WITH_INPUT_NDOF
void WM_event_ndof_pan_get_for_navigation(const wmNDOFMotionData *ndof, float r_pan[3])
blender::float3 WM_event_ndof_translation_get_for_navigation(const wmNDOFMotionData &ndof)
{
const float sign = (U.ndof_navigation_mode == NDOF_NAVIGATION_MODE_OBJECT) ? -1.0f : 1.0f;
r_pan[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -sign : sign);
r_pan[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -sign : sign);
r_pan[2] = ndof->tvec[2] * ((U.ndof_flag & NDOF_PANZ_INVERT_AXIS) ? -sign : sign);
return {
ndof.tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -sign : sign),
ndof.tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -sign : sign),
ndof.tvec[2] * ((U.ndof_flag & NDOF_PANZ_INVERT_AXIS) ? -sign : sign),
};
}
void WM_event_ndof_rotate_get_for_navigation(const wmNDOFMotionData *ndof, float r_rot[3])
blender::float3 WM_event_ndof_rotation_get_for_navigation(const wmNDOFMotionData &ndof)
{
const float sign = (U.ndof_navigation_mode == NDOF_NAVIGATION_MODE_OBJECT) ? -1.0f : 1.0f;
r_rot[0] = ndof->rvec[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -sign : sign);
r_rot[1] = ndof->rvec[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -sign : sign);
r_rot[2] = ndof->rvec[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -sign : sign);
return {
ndof.rvec[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -sign : sign),
ndof.rvec[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -sign : sign),
ndof.rvec[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -sign : sign),
};
}
void WM_event_ndof_pan_get(const wmNDOFMotionData *ndof, float r_pan[3])
blender::float3 WM_event_ndof_translation_get(const wmNDOFMotionData &ndof)
{
r_pan[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f);
r_pan[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f);
r_pan[2] = ndof->tvec[2] * ((U.ndof_flag & NDOF_PANZ_INVERT_AXIS) ? -1.0f : 1.0f);
return {
ndof.tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f),
ndof.tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f),
ndof.tvec[2] * ((U.ndof_flag & NDOF_PANZ_INVERT_AXIS) ? -1.0f : 1.0f),
};
}
void WM_event_ndof_rotate_get(const wmNDOFMotionData *ndof, float r_rot[3])
blender::float3 WM_event_ndof_rotation_get(const wmNDOFMotionData &ndof)
{
r_rot[0] = ndof->rvec[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -1.0f : 1.0f);
r_rot[1] = ndof->rvec[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -1.0f : 1.0f);
r_rot[2] = ndof->rvec[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -1.0f : 1.0f);
return {
ndof.rvec[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -1.0f : 1.0f),
ndof.rvec[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -1.0f : 1.0f),
ndof.rvec[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -1.0f : 1.0f),
};
}
float WM_event_ndof_to_axis_angle(const wmNDOFMotionData *ndof, float axis[3])
float WM_event_ndof_to_axis_angle(const wmNDOFMotionData &ndof, float axis[3])
{
float angle;
angle = normalize_v3_v3(axis, ndof->rvec);
angle = normalize_v3_v3(axis, ndof.rvec);
axis[0] = axis[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -1.0f : 1.0f);
axis[1] = axis[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -1.0f : 1.0f);
axis[2] = axis[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -1.0f : 1.0f);
return ndof->dt * angle;
return angle;
}
void WM_event_ndof_to_quat(const wmNDOFMotionData *ndof, float q[4])
void WM_event_ndof_to_quat(const wmNDOFMotionData &ndof, float q[4])
{
float axis[3];
float angle;

View File

@@ -5617,7 +5617,7 @@ static void attach_ndof_data(wmEvent *event, const GHOST_TEventNDOFMotionData *g
data->tvec[2] = t;
}
data->dt = ghost->dt;
data->time_delta = ghost->dt;
data->progress = (wmProgress)ghost->progress;