The open source OpenXR runtime

d/simulated: Make hmd center be pose and make it possible to pass it in at start

+31 -21
+24 -17
src/xrt/drivers/simulated/simulated_hmd.c
··· 43 43 struct xrt_device base; 44 44 45 45 struct xrt_pose pose; 46 - struct xrt_vec3 center; 46 + struct xrt_pose center; 47 47 48 48 uint64_t created_ns; 49 49 float diameter_m; ··· 112 112 113 113 switch (dh->movement) { 114 114 default: 115 - case SIMULATED_MOVEMENT_WOBBLE: 115 + case SIMULATED_MOVEMENT_WOBBLE: { 116 + struct xrt_pose tmp = XRT_POSE_IDENTITY; 117 + 116 118 // Wobble time. 117 - dh->pose.position.x = dh->center.x + sin((time_s / t2) * M_PI) * d2 - d; 118 - dh->pose.position.y = dh->center.y + sin((time_s / t) * M_PI) * d; 119 - dh->pose.orientation.x = sin((time_s / t3) * M_PI) / 64.0f; 120 - dh->pose.orientation.y = sin((time_s / t4) * M_PI) / 16.0f; 121 - dh->pose.orientation.z = sin((time_s / t4) * M_PI) / 64.0f; 122 - dh->pose.orientation.w = 1; 123 - math_quat_normalize(&dh->pose.orientation); 124 - break; 125 - case SIMULATED_MOVEMENT_ROTATE: 126 - // Reset position. 127 - dh->pose.position = dh->center; 119 + tmp.position.x = sin((time_s / t2) * M_PI) * d2 - d; 120 + tmp.position.y = sin((time_s / t) * M_PI) * d; 121 + tmp.orientation.x = sin((time_s / t3) * M_PI) / 64.0f; 122 + tmp.orientation.y = sin((time_s / t4) * M_PI) / 16.0f; 123 + tmp.orientation.z = sin((time_s / t4) * M_PI) / 64.0f; 124 + math_quat_normalize(&tmp.orientation); 125 + 126 + // Transform with center to set it. 127 + math_pose_transform(&dh->center, &tmp, &dh->pose); 128 + } break; 129 + case SIMULATED_MOVEMENT_ROTATE: { 130 + struct xrt_pose tmp = XRT_POSE_IDENTITY; 128 131 129 132 // Rotate around the up vector. 130 133 math_quat_from_angle_vector(time_s / 4, &up, &dh->pose.orientation); 131 - break; 134 + 135 + // Transform with center to set it. 136 + math_pose_transform(&dh->center, &tmp, &dh->pose); 137 + } break; 132 138 case SIMULATED_MOVEMENT_STATIONARY: 133 139 // Reset pose. 134 - dh->pose = (struct xrt_pose)XRT_POSE_IDENTITY; 140 + dh->pose = dh->center; 135 141 break; 136 142 } 137 143 ··· 155 161 } 156 162 157 163 struct xrt_device * 158 - simulated_hmd_create(enum simulated_movement movement) 164 + simulated_hmd_create(enum simulated_movement movement, const struct xrt_pose *center) 159 165 { 160 166 enum u_device_alloc_flags flags = 161 167 (enum u_device_alloc_flags)(U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE); ··· 167 173 dh->base.name = XRT_DEVICE_GENERIC_HMD; 168 174 dh->base.device_type = XRT_DEVICE_TYPE_HMD; 169 175 dh->pose.orientation.w = 1.0f; // All other values set to zero. 176 + dh->center = *center; 170 177 dh->created_ns = os_monotonic_get_ns(); 171 178 dh->diameter_m = 0.05f; 172 179 dh->log_level = debug_get_log_option_simulated_log(); ··· 199 206 // Setup variable tracker. 200 207 u_var_add_root(dh, "Simulated HMD", true); 201 208 u_var_add_pose(dh, &dh->pose, "pose"); 202 - u_var_add_vec3_f32(dh, &dh->center, "center"); 209 + u_var_add_pose(dh, &dh->center, "center"); 203 210 u_var_add_f32(dh, &dh->diameter_m, "diameter_m"); 204 211 u_var_add_log_level(dh, &dh->log_level, "log_level"); 205 212
+1 -1
src/xrt/drivers/simulated/simulated_interface.h
··· 56 56 * @ingroup drv_simulated 57 57 */ 58 58 struct xrt_device * 59 - simulated_hmd_create(enum simulated_movement movement); 59 + simulated_hmd_create(enum simulated_movement movement, const struct xrt_pose *center); 60 60 61 61 62 62 #ifdef __cplusplus
+2 -1
src/xrt/drivers/simulated/simulated_prober.c
··· 66 66 movement = SIMULATED_MOVEMENT_ROTATE; 67 67 } 68 68 69 - out_xdevs[0] = simulated_hmd_create(movement); 69 + const struct xrt_pose center = XRT_POSE_IDENTITY; 70 + out_xdevs[0] = simulated_hmd_create(movement, &center); 70 71 71 72 return 1; 72 73 }
+2 -1
src/xrt/targets/common/target_builder_rgb_tracking.c
··· 340 340 } 341 341 #endif 342 342 } else { 343 - head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE); 343 + const struct xrt_pose center = XRT_POSE_IDENTITY; 344 + head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE, &center); 344 345 } 345 346 346 347
+2 -1
src/xrt/targets/sdl_test/sdl_instance.c
··· 97 97 sp->xsysd_base.destroy = sdl_system_devices_destroy; 98 98 99 99 #ifdef USE_SIMULATED 100 - struct xrt_device *head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE); 100 + const struct xrt_pose center = XRT_POSE_IDENTITY; 101 + struct xrt_device *head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE, &center); 101 102 #else 102 103 struct xrt_device *head = &sp->xdev_base; 103 104 #endif