diff options
author | Julian Eisel <julian@blender.org> | 2020-07-22 00:55:14 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-07-22 01:05:56 +0300 |
commit | 607d745a79e0c1f79fdd026625be4169e5530001 (patch) | |
tree | 7caacdc579f2e5b53b7e39814f53a3eb9350dd28 /source/blender/windowmanager | |
parent | 878d191baee6b6a7997cf21d980f39ea97a0a33b (diff) |
VR: Change how landmarks affect viewer pose
* Changing to a landmark moves the view exactly to it, rather than
keeping the current position offset.
* Disabling positional tracking moves the viewer back to the landmark
position.
This is a more predictable and practical way to use landmarks. See
feedback in T71347.
On the code side, I did some cleanup so the logic flow is more clear.
Note: This is entirely untested. I currently don't have access to a
device. There might be issues, tomorrow I'll hopefully get feedback.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/xr/intern/wm_xr_session.c | 87 |
1 files changed, 61 insertions, 26 deletions
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index 1baac10dbd8..5d85045e8fa 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -159,6 +159,13 @@ static void wm_xr_session_draw_data_populate(wmXrData *xr_data, wm_xr_session_base_pose_calc(r_draw_data->scene, settings, &r_draw_data->base_pose); } +typedef enum wmXrSessionStateEvent { + SESSION_STATE_EVENT_NONE = 0, + SESSION_STATE_EVENT_START, + SESSION_STATE_EVENT_RESET_TO_BASE_POSE, + SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE, +} wmXrSessionStateEvent; + static bool wm_xr_session_draw_data_needs_reset_to_base_pose(const wmXrSessionState *state, const XrSessionSettings *settings) { @@ -170,36 +177,64 @@ static bool wm_xr_session_draw_data_needs_reset_to_base_pose(const wmXrSessionSt (state->prev_base_pose_object != settings->base_pose_object)); } +wmXrSessionStateEvent wm_xr_session_state_to_event(const wmXrSessionState *state, + const XrSessionSettings *settings) +{ + if (!state->is_view_data_set) { + return SESSION_STATE_EVENT_START; + } + else if (wm_xr_session_draw_data_needs_reset_to_base_pose(state, settings)) { + return SESSION_STATE_EVENT_RESET_TO_BASE_POSE; + } + else { + const bool position_tracking_toggled = ((state->prev_settings_flag & + XR_SESSION_USE_POSITION_TRACKING) != + (settings->flag & XR_SESSION_USE_POSITION_TRACKING)); + if (position_tracking_toggled) { + return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE; + } + } + + return SESSION_STATE_EVENT_NONE; +} + void wm_xr_session_draw_data_update(const wmXrSessionState *state, const XrSessionSettings *settings, const GHOST_XrDrawViewInfo *draw_view, wmXrDrawData *draw_data) { - const bool position_tracking_toggled = ((state->prev_settings_flag & - XR_SESSION_USE_POSITION_TRACKING) != - (settings->flag & XR_SESSION_USE_POSITION_TRACKING)); - const bool use_position_tracking = settings->flag & XR_SESSION_USE_POSITION_TRACKING; + const wmXrSessionStateEvent event = wm_xr_session_state_to_event(state, settings); + const bool use_position_tracking = (settings->flag & XR_SESSION_USE_POSITION_TRACKING); - /* Set the eye position offset, it's used to offset the base pose when changing positional - * tracking. */ - if (!state->is_view_data_set || - wm_xr_session_draw_data_needs_reset_to_base_pose(state, settings)) { - /* Always use the exact base pose with no offset when starting the session. */ - copy_v3_fl(draw_data->eye_position_ofs, 0.0f); - } - else if (position_tracking_toggled) { - if (use_position_tracking) { + switch (event) { + case SESSION_STATE_EVENT_START: + /* Always use the exact base pose with no offset when starting the session. */ copy_v3_fl(draw_data->eye_position_ofs, 0.0f); - } - else { - /* Store the current local offset (local pose) so that we can apply that to the eyes. This - * way the eyes stay exactly where they are when disabling positional tracking. */ - copy_v3_v3(draw_data->eye_position_ofs, draw_view->local_pose.position); - } - } - else if (!use_position_tracking) { - /* Keep previous offset when positional tracking is disabled. */ - copy_v3_v3(draw_data->eye_position_ofs, state->prev_eye_position_ofs); + break; + /* This should be triggered by the VR add-on if a landmark changes. */ + case SESSION_STATE_EVENT_RESET_TO_BASE_POSE: + if (use_position_tracking) { + /* Switch exactly to base pose, so use eye offset to cancel out current position delta. */ + copy_v3_v3(draw_data->eye_position_ofs, draw_view->local_pose.position); + } + else { + copy_v3_fl(draw_data->eye_position_ofs, 0.0f); + } + break; + case SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE: + if (use_position_tracking) { + /* Keep the current position, and let the user move from there. */ + copy_v3_v3(draw_data->eye_position_ofs, state->prev_eye_position_ofs); + } + else { + /* Back to the exact base-pose position. */ + copy_v3_fl(draw_data->eye_position_ofs, 0.0f); + } + break; + case SESSION_STATE_EVENT_NONE: + /* Keep previous offset when positional tracking is disabled. */ + copy_v3_v3(draw_data->eye_position_ofs, state->prev_eye_position_ofs); + break; } } @@ -299,9 +334,9 @@ bool WM_xr_session_state_viewer_pose_matrix_info_get(const wmXrData *xr, /** * \brief Call Ghost-XR to draw a frame * - * Draw callback for the XR-session surface. It's expected to be called on each main loop iteration - * and tells Ghost-XR to submit a new frame by drawing its views. Note that for drawing each view, - * #wm_xr_draw_view() will be called through Ghost-XR (see GHOST_XrDrawViewFunc()). + * Draw callback for the XR-session surface. It's expected to be called on each main loop + * iteration and tells Ghost-XR to submit a new frame by drawing its views. Note that for drawing + * each view, #wm_xr_draw_view() will be called through Ghost-XR (see GHOST_XrDrawViewFunc()). */ static void wm_xr_session_surface_draw(bContext *C) { |