The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/simulated: Make it possible to pass in movement mode

And a little bit of tidy.

+49 -30
+11 -18
src/xrt/drivers/simulated/simulated_hmd.c
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 22 22 #include "util/u_logging.h" 23 23 #include "util/u_distortion_mesh.h" 24 24 25 + #include "simulated_interface.h" 26 + 25 27 #include <stdio.h> 26 28 27 29 ··· 31 33 * 32 34 */ 33 35 34 - enum simulated_movement 35 - { 36 - SIMULATED_WOBBLE, 37 - SIMULATED_ROTATE, 38 - }; 39 - 40 - 41 36 /*! 42 37 * A example HMD device. 43 38 * ··· 71 66 } 72 67 73 68 DEBUG_GET_ONCE_LOG_OPTION(simulated_log, "SIMULATED_LOG", U_LOGGING_WARN) 74 - DEBUG_GET_ONCE_BOOL_OPTION(simulated_rotate, "SIMULATED_ROTATE", false) 75 69 76 70 #define DH_TRACE(p, ...) U_LOG_XDEV_IFL_T(&dh->base, dh->log_level, __VA_ARGS__) 77 71 #define DH_DEBUG(p, ...) U_LOG_XDEV_IFL_D(&dh->base, dh->log_level, __VA_ARGS__) ··· 118 112 119 113 switch (dh->movement) { 120 114 default: 121 - case SIMULATED_WOBBLE: 115 + case SIMULATED_MOVEMENT_WOBBLE: 122 116 // Wobble time. 123 117 dh->pose.position.x = dh->center.x + sin((time_s / t2) * M_PI) * d2 - d; 124 118 dh->pose.position.y = dh->center.y + sin((time_s / t) * M_PI) * d; ··· 128 122 dh->pose.orientation.w = 1; 129 123 math_quat_normalize(&dh->pose.orientation); 130 124 break; 131 - case SIMULATED_ROTATE: 125 + case SIMULATED_MOVEMENT_ROTATE: 132 126 // Reset position. 133 127 dh->pose.position = dh->center; 134 128 135 129 // Rotate around the up vector. 136 130 math_quat_from_angle_vector(time_s / 4, &up, &dh->pose.orientation); 131 + break; 132 + case SIMULATED_MOVEMENT_STATIONARY: 133 + // Reset pose. 134 + dh->pose = (struct xrt_pose)XRT_POSE_IDENTITY; 137 135 break; 138 136 } 139 137 ··· 157 155 } 158 156 159 157 struct xrt_device * 160 - simulated_hmd_create(void) 158 + simulated_hmd_create(enum simulated_movement movement) 161 159 { 162 160 enum u_device_alloc_flags flags = 163 161 (enum u_device_alloc_flags)(U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE); ··· 172 170 dh->created_ns = os_monotonic_get_ns(); 173 171 dh->diameter_m = 0.05f; 174 172 dh->log_level = debug_get_log_option_simulated_log(); 173 + dh->movement = movement; 175 174 176 175 // Print name. 177 176 snprintf(dh->base.str, XRT_DEVICE_NAME_LEN, "Simulated HMD"); ··· 195 194 DH_ERROR(dh, "Failed to setup basic device info"); 196 195 simulated_hmd_destroy(&dh->base); 197 196 return NULL; 198 - } 199 - 200 - // Select the type of movement. 201 - dh->movement = SIMULATED_WOBBLE; 202 - if (debug_get_bool_option_simulated_rotate()) { 203 - dh->movement = SIMULATED_ROTATE; 204 197 } 205 198 206 199 // Setup variable tracker.
+24 -8
src/xrt/drivers/simulated/simulated_interface.h
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 9 9 10 10 #pragma once 11 11 12 + #include "xrt/xrt_compiler.h" 13 + 14 + 12 15 #ifdef __cplusplus 13 16 extern "C" { 14 17 #endif 18 + 15 19 16 20 /*! 17 21 * @defgroup drv_simulated Simulated driver ··· 21 25 */ 22 26 23 27 /*! 28 + * @dir drivers/simulated 29 + * 30 + * @brief @ref drv_simulated files. 31 + */ 32 + 33 + /*! 34 + * What type of movement should the simulated device do. 35 + * 36 + * @ingroup drv_simulated 37 + */ 38 + enum simulated_movement 39 + { 40 + SIMULATED_MOVEMENT_WOBBLE, 41 + SIMULATED_MOVEMENT_ROTATE, 42 + SIMULATED_MOVEMENT_STATIONARY, 43 + }; 44 + 45 + /*! 24 46 * Create a auto prober for simulated devices. 25 47 * 26 48 * @ingroup drv_simulated ··· 34 56 * @ingroup drv_simulated 35 57 */ 36 58 struct xrt_device * 37 - simulated_hmd_create(void); 38 - 39 - /*! 40 - * @dir drivers/simulated 41 - * 42 - * @brief @ref drv_simulated files. 43 - */ 59 + simulated_hmd_create(enum simulated_movement movement); 44 60 45 61 46 62 #ifdef __cplusplus
+12 -2
src/xrt/drivers/simulated/simulated_prober.c
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 16 16 #include "util/u_debug.h" 17 17 18 18 #include "simulated_interface.h" 19 + 20 + 21 + DEBUG_GET_ONCE_BOOL_OPTION(simulated_rotate, "SIMULATED_ROTATE", false) 19 22 20 23 /*! 21 24 * @implements xrt_auto_prober ··· 57 60 return 0; 58 61 } 59 62 60 - out_xdevs[0] = simulated_hmd_create(); 63 + // Select the type of movement. 64 + enum simulated_movement movement = SIMULATED_MOVEMENT_WOBBLE; 65 + if (debug_get_bool_option_simulated_rotate()) { 66 + movement = SIMULATED_MOVEMENT_ROTATE; 67 + } 68 + 69 + out_xdevs[0] = simulated_hmd_create(movement); 70 + 61 71 return 1; 62 72 } 63 73
+1 -1
src/xrt/targets/common/target_builder_rgb_tracking.c
··· 340 340 } 341 341 #endif 342 342 } else { 343 - head = simulated_hmd_create(); 343 + head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE); 344 344 } 345 345 346 346
+1 -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(); 100 + struct xrt_device *head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE); 101 101 #else 102 102 struct xrt_device *head = &sp->xdev_base; 103 103 #endif