Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/xr/intern/wm_xr_draw.c
| Show All 32 Lines | |||||
| #include "GPU_viewport.h" | #include "GPU_viewport.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "wm_surface.h" | #include "wm_surface.h" | ||||
| #include "wm_xr_intern.h" | #include "wm_xr_intern.h" | ||||
| void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4]) | void wm_xr_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4]) | ||||
| { | { | ||||
| float iquat[4]; | quat_to_mat4(r_mat, pose->orientation_quat); | ||||
| invert_qt_qt_normalized(iquat, pose->orientation_quat); | copy_v3_v3(r_mat[3], pose->position); | ||||
| quat_to_mat4(r_viewmat, iquat); | |||||
| translate_m4(r_viewmat, -pose->position[0], -pose->position[1], -pose->position[2]); | |||||
| } | } | ||||
| void wm_xr_controller_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4]) | void wm_xr_pose_to_imat(const GHOST_XrPose *pose, float r_imat[4][4]) | ||||
| { | { | ||||
| quat_to_mat4(r_mat, pose->orientation_quat); | float iquat[4]; | ||||
| copy_v3_v3(r_mat[3], pose->position); | invert_qt_qt_normalized(iquat, pose->orientation_quat); | ||||
| quat_to_mat4(r_imat, iquat); | |||||
| translate_m4(r_imat, -pose->position[0], -pose->position[1], -pose->position[2]); | |||||
| } | } | ||||
| static void wm_xr_draw_matrices_create(const wmXrDrawData *draw_data, | static void wm_xr_draw_matrices_create(const wmXrDrawData *draw_data, | ||||
| const GHOST_XrDrawViewInfo *draw_view, | const GHOST_XrDrawViewInfo *draw_view, | ||||
| const XrSessionSettings *session_settings, | const XrSessionSettings *session_settings, | ||||
| float r_view_mat[4][4], | float r_view_mat[4][4], | ||||
| float r_proj_mat[4][4]) | float r_proj_mat[4][4]) | ||||
| { | { | ||||
| GHOST_XrPose eye_pose; | GHOST_XrPose eye_pose; | ||||
| float eye_inv[4][4], base_inv[4][4]; | |||||
| copy_qt_qt(eye_pose.orientation_quat, draw_view->eye_pose.orientation_quat); | copy_qt_qt(eye_pose.orientation_quat, draw_view->eye_pose.orientation_quat); | ||||
| copy_v3_v3(eye_pose.position, draw_view->eye_pose.position); | copy_v3_v3(eye_pose.position, draw_view->eye_pose.position); | ||||
| if ((session_settings->flag & XR_SESSION_USE_POSITION_TRACKING) == 0) { | if ((session_settings->flag & XR_SESSION_USE_POSITION_TRACKING) == 0) { | ||||
| sub_v3_v3(eye_pose.position, draw_view->local_pose.position); | sub_v3_v3(eye_pose.position, draw_view->local_pose.position); | ||||
| } | } | ||||
| if ((session_settings->flag & XR_SESSION_USE_ABSOLUTE_TRACKING) == 0) { | if ((session_settings->flag & XR_SESSION_USE_ABSOLUTE_TRACKING) == 0) { | ||||
| sub_v3_v3(eye_pose.position, draw_data->eye_position_ofs); | sub_v3_v3(eye_pose.position, draw_data->eye_position_ofs); | ||||
| } | } | ||||
| wm_xr_pose_to_imat(&eye_pose, eye_inv); | |||||
| /* Calculate the base pose matrix (in world space!). */ | |||||
| wm_xr_pose_to_imat(&draw_data->base_pose, base_inv); | |||||
| mul_m4_m4m4(r_view_mat, eye_inv, base_inv); | |||||
| perspective_m4_fov(r_proj_mat, | perspective_m4_fov(r_proj_mat, | ||||
| draw_view->fov.angle_left, | draw_view->fov.angle_left, | ||||
| draw_view->fov.angle_right, | draw_view->fov.angle_right, | ||||
| draw_view->fov.angle_up, | draw_view->fov.angle_up, | ||||
| draw_view->fov.angle_down, | draw_view->fov.angle_down, | ||||
| session_settings->clip_start, | session_settings->clip_start, | ||||
| session_settings->clip_end); | session_settings->clip_end); | ||||
| float eye_mat[4][4]; | |||||
| float base_mat[4][4]; | |||||
| wm_xr_pose_to_viewmat(&eye_pose, eye_mat); | |||||
| /* Calculate the base pose matrix (in world space!). */ | |||||
| wm_xr_pose_to_viewmat(&draw_data->base_pose, base_mat); | |||||
| mul_m4_m4m4(r_view_mat, eye_mat, base_mat); | |||||
| } | } | ||||
| static void wm_xr_draw_viewport_buffers_to_active_framebuffer( | static void wm_xr_draw_viewport_buffers_to_active_framebuffer( | ||||
| const wmXrRuntimeData *runtime_data, | const wmXrRuntimeData *runtime_data, | ||||
| const wmXrSurfaceData *surface_data, | const wmXrSurfaceData *surface_data, | ||||
| const GHOST_XrDrawViewInfo *draw_view) | const GHOST_XrDrawViewInfo *draw_view) | ||||
| { | { | ||||
| const wmXrViewportPair *vp = BLI_findlink(&surface_data->viewports, draw_view->view_idx); | const wmXrViewportPair *vp = BLI_findlink(&surface_data->viewports, draw_view->view_idx); | ||||
| ▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines | |||||