The open source OpenXR runtime
0
fork

Configure Feed

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

d/simulated: Add builder

+186
+4
src/xrt/targets/common/CMakeLists.txt
··· 32 32 target_sources(target_lists PRIVATE target_builder_lighthouse.c) 33 33 endif() 34 34 35 + if(XRT_BUILD_DRIVER_SIMULATED) 36 + target_sources(target_lists PRIVATE target_builder_simulated.c) 37 + endif() 38 + 35 39 if(XRT_BUILD_DRIVER_SIMULAVR) 36 40 target_sources(target_lists PRIVATE target_builder_simulavr.c) 37 41 endif()
+13
src/xrt/targets/common/target_builder_interface.h
··· 35 35 #define T_BUILDER_RGB_TRACKING 36 36 #endif 37 37 38 + #if defined(XRT_BUILD_DRIVER_SIMULATED) || defined(XRT_DOXYGEN) 39 + #define T_BUILDER_SIMULATED 40 + #endif 41 + 38 42 #if defined(XRT_BUILD_DRIVER_SIMULAVR) || defined(XRT_DOXYGEN) 39 43 #define T_BUILDER_SIMULAVR 40 44 #endif ··· 85 89 struct xrt_builder * 86 90 t_builder_rgb_tracking_create(void); 87 91 #endif 92 + 93 + #ifdef T_BUILDER_SIMULATED 94 + /*! 95 + * Builder for @drv_simulated devices. 96 + */ 97 + struct xrt_builder * 98 + t_builder_simulated_create(void); 99 + #endif 100 + 88 101 89 102 #ifdef T_BUILDER_SIMULAVR 90 103 /*!
+165
src/xrt/targets/common/target_builder_simulated.c
··· 1 + // Copyright 2022-2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Simulated driver builder. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup xrt_iface 8 + */ 9 + 10 + #include "xrt/xrt_config_drivers.h" 11 + #include "xrt/xrt_prober.h" 12 + 13 + #include "util/u_debug.h" 14 + #include "util/u_builders.h" 15 + #include "util/u_config_json.h" 16 + #include "util/u_system_helpers.h" 17 + 18 + #include "target_builder_interface.h" 19 + 20 + #include "simulated/simulated_interface.h" 21 + 22 + #include <assert.h> 23 + 24 + 25 + #ifndef XRT_BUILD_DRIVER_SIMULATED 26 + #error "Must only be built with XRT_BUILD_DRIVER_SIMULATED set" 27 + #endif 28 + 29 + DEBUG_GET_ONCE_BOOL_OPTION(simulated_enabled, "SIMULATED_ENABLE", false) 30 + DEBUG_GET_ONCE_OPTION(simulated_left, "SIMULATED_LEFT", NULL) 31 + DEBUG_GET_ONCE_OPTION(simulated_right, "SIMULATED_RIGHT", NULL) 32 + 33 + 34 + /* 35 + * 36 + * Helper functions. 37 + * 38 + */ 39 + 40 + static const char *driver_list[] = { 41 + "simulated", 42 + }; 43 + 44 + struct xrt_device * 45 + create_controller(const char *str, 46 + enum xrt_device_type type, 47 + const struct xrt_pose *center, 48 + struct xrt_tracking_origin *origin) 49 + { 50 + enum xrt_device_name name = XRT_DEVICE_SIMPLE_CONTROLLER; 51 + 52 + if (str == NULL) { 53 + return NULL; 54 + } else if (strcmp(str, "simple") == 0) { 55 + name = XRT_DEVICE_SIMPLE_CONTROLLER; 56 + type = XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER; // Override left/right 57 + } else if (strcmp(str, "wmr") == 0) { 58 + name = XRT_DEVICE_WMR_CONTROLLER; 59 + } else if (strcmp(str, "ml2") == 0) { 60 + name = XRT_DEVICE_ML2_CONTROLLER; 61 + type = XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER; // Override left/right 62 + } else { 63 + U_LOG_E("Unsupported controller '%s' available are: simple, wmr, ml2.", str); 64 + return NULL; 65 + } 66 + 67 + return simulated_create_controller(name, type, center, origin); 68 + } 69 + 70 + 71 + /* 72 + * 73 + * Member functions. 74 + * 75 + */ 76 + 77 + static xrt_result_t 78 + simulated_estimate_system(struct xrt_builder *xb, 79 + cJSON *config, 80 + struct xrt_prober *xp, 81 + struct xrt_builder_estimate *estimate) 82 + { 83 + estimate->certain.head = true; 84 + estimate->certain.left = true; 85 + estimate->certain.right = true; 86 + estimate->priority = -50; 87 + 88 + return XRT_SUCCESS; 89 + } 90 + 91 + static xrt_result_t 92 + simulated_open_system(struct xrt_builder *xb, 93 + cJSON *config, 94 + struct xrt_prober *xp, 95 + struct xrt_system_devices **out_xsysd) 96 + { 97 + assert(out_xsysd != NULL); 98 + assert(*out_xsysd == NULL); 99 + 100 + const struct xrt_pose head_center = {XRT_QUAT_IDENTITY, {0.0f, 1.6f, 0.0f}}; // "nominal height" 1.6m 101 + const struct xrt_pose left_center = {XRT_QUAT_IDENTITY, {-0.2f, 1.3f, -0.5f}}; 102 + const struct xrt_pose right_center = {XRT_QUAT_IDENTITY, {0.2f, 1.3f, -0.5f}}; 103 + const enum xrt_device_type left_type = XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER; 104 + const enum xrt_device_type right_type = XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER; 105 + 106 + const char *left_str = debug_get_option_simulated_left(); 107 + const char *right_str = debug_get_option_simulated_right(); 108 + 109 + struct xrt_device *head = simulated_hmd_create(SIMULATED_MOVEMENT_WOBBLE, &head_center); 110 + struct xrt_device *left = create_controller(left_str, left_type, &left_center, head->tracking_origin); 111 + struct xrt_device *right = create_controller(right_str, right_type, &right_center, head->tracking_origin); 112 + 113 + // Make the objects be tracked in space. 114 + //! @todo Make these be a option to the hmd create function, or just make it be there from the start. 115 + head->orientation_tracking_supported = true; 116 + head->position_tracking_supported = true; 117 + //! @todo Create a shared tracking origin on the system deviecs struct instead. 118 + head->tracking_origin->type = XRT_TRACKING_TYPE_OTHER; // Just anything other then none. 119 + 120 + struct u_system_devices *usysd = u_system_devices_allocate(); 121 + usysd->base.roles.head = head; 122 + usysd->base.roles.left = left; 123 + usysd->base.roles.right = right; 124 + 125 + usysd->base.xdevs[usysd->base.xdev_count++] = head; 126 + if (left != NULL) { 127 + usysd->base.xdevs[usysd->base.xdev_count++] = left; 128 + } 129 + if (right != NULL) { 130 + usysd->base.xdevs[usysd->base.xdev_count++] = right; 131 + } 132 + 133 + *out_xsysd = &usysd->base; 134 + 135 + return XRT_SUCCESS; 136 + } 137 + 138 + static void 139 + simulated_destroy(struct xrt_builder *xb) 140 + { 141 + free(xb); 142 + } 143 + 144 + 145 + /* 146 + * 147 + * 'Exported' functions. 148 + * 149 + */ 150 + 151 + struct xrt_builder * 152 + t_builder_simulated_create(void) 153 + { 154 + struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 155 + xb->estimate_system = simulated_estimate_system; 156 + xb->open_system = simulated_open_system; 157 + xb->destroy = simulated_destroy; 158 + xb->identifier = "simulated"; 159 + xb->name = "Simulated devices builder"; 160 + xb->driver_identifiers = driver_list; 161 + xb->driver_identifier_count = ARRAY_SIZE(driver_list); 162 + xb->exclude_from_automatic_discovery = !debug_get_bool_option_simulated_enabled(); 163 + 164 + return xb; 165 + }
+4
src/xrt/targets/common/target_lists.c
··· 100 100 t_builder_rgb_tracking_create, 101 101 #endif // T_BUILDER_RGB_TRACKING 102 102 103 + #ifdef T_BUILDER_SIMULATED 104 + t_builder_simulated_create, 105 + #endif // T_BUILDER_SIMULATED 106 + 103 107 #ifdef T_BUILDER_SIMULAVR 104 108 t_builder_simula_create, 105 109 #endif // T_BUILDER_SIMULAVR