90 xrStringToPath(
context->getXrInstance(),
"/user/hand/left", &leftHandPath);
91 xrStringToPath(
context->getXrInstance(),
"/user/hand/right", &rightHandPath);
92 handPaths = { leftHandPath , rightHandPath };
95 XrActionSetCreateInfo actionSetCreateInfo{ XR_TYPE_ACTION_SET_CREATE_INFO };
96 strcpy(actionSetCreateInfo.actionSetName,
"actionset");
97 strcpy(actionSetCreateInfo.localizedActionSetName,
"Actions");
98 actionSetCreateInfo.priority = 0;
103 XrActionCreateInfo poseActionCreateInfo{ XR_TYPE_ACTION_CREATE_INFO };
104 strcpy(poseActionCreateInfo.actionName,
"handpose");
105 strcpy(poseActionCreateInfo.localizedActionName,
"Hand Pose");
106 poseActionCreateInfo.actionType = XR_ACTION_TYPE_POSE_INPUT;
107 poseActionCreateInfo.countSubactionPaths =
static_cast<uint32_t
>(
handPaths.size());
108 poseActionCreateInfo.subactionPaths =
handPaths.data();
114 XrActionCreateInfo thumbstickCreateInfo{ XR_TYPE_ACTION_CREATE_INFO };
115 strcpy(thumbstickCreateInfo.actionName,
"thumbstick");
116 strcpy(thumbstickCreateInfo.localizedActionName,
"Thumbstick");
117 thumbstickCreateInfo.actionType = XR_ACTION_TYPE_VECTOR2F_INPUT;
118 thumbstickCreateInfo.countSubactionPaths =
static_cast<uint32_t
>(
handPaths.size());
119 thumbstickCreateInfo.subactionPaths =
handPaths.data();
125 XrActionCreateInfo triggerCreateInfo{ XR_TYPE_ACTION_CREATE_INFO };
126 strcpy(triggerCreateInfo.actionName,
"trigger");
127 strcpy(triggerCreateInfo.localizedActionName,
"Trigger");
128 triggerCreateInfo.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
129 triggerCreateInfo.countSubactionPaths =
static_cast<uint32_t
>(
handPaths.size());
130 triggerCreateInfo.subactionPaths =
handPaths.data();
136 XrActionCreateInfo gripCreateInfo{ XR_TYPE_ACTION_CREATE_INFO };
137 strcpy(gripCreateInfo.actionName,
"grip");
138 strcpy(gripCreateInfo.localizedActionName,
"Grip");
139 gripCreateInfo.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
140 gripCreateInfo.countSubactionPaths =
static_cast<uint32_t
>(
handPaths.size());
141 gripCreateInfo.subactionPaths =
handPaths.data();
146 constexpr XrVector3f defaultVector3f = { 0.0f, 0.0f, 0.0f };
147 constexpr XrVector2f defaultVector2f = { 0.0f, 0.0f };
148 constexpr XrQuaternionf defaultQuat = { 0.0f, 0.0f, 0.0f, 1.0f };
151 XrActionSpaceCreateInfo handPoseActionSpaceCreateInfo{ XR_TYPE_ACTION_SPACE_CREATE_INFO };
153 handPoseActionSpaceCreateInfo.poseInActionSpace.position = defaultVector3f;
154 handPoseActionSpaceCreateInfo.poseInActionSpace.orientation = defaultQuat;
155 handPoseActionSpaceCreateInfo.subactionPath = handPoseInfo.handPath;
156 PLOG_FN_XR(xrCreateActionSpace(
headset->getSession(), &handPoseActionSpaceCreateInfo, &handPoseInfo.space));
161 XrPath aimPoseLeftHandPath = {};
162 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/left/input/aim/pose", &aimPoseLeftHandPath));
164 XrPath aimPoseRightHandPath = {};
165 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/right/input/aim/pose", &aimPoseRightHandPath));
167 std::vector<XrActionSuggestedBinding> actionBindings = {
172 XrPath interactionProfilePath;
175 XrInteractionProfileSuggestedBinding suggestedBindings{ XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING };
176 suggestedBindings.interactionProfile = interactionProfilePath;
177 suggestedBindings.countSuggestedBindings =
static_cast<uint32_t
>(actionBindings.size());
178 suggestedBindings.suggestedBindings = actionBindings.data();
180 PLOG_FN_XR(xrSuggestInteractionProfileBindings(
context->getXrInstance(), &suggestedBindings));
184 XrPath aimPoseLeftPath, aimPoseRightPath;
185 XrPath thumbstickLeftPath, thumbstickRightPath;
186 XrPath triggerLeftPath, triggerRightPath;
187 XrPath gripLeftPath, gripRightPath;
189 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/left/input/aim/pose", &aimPoseLeftPath));
190 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/right/input/aim/pose", &aimPoseRightPath));
191 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/left/input/thumbstick", &thumbstickLeftPath));
192 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/right/input/thumbstick", &thumbstickRightPath));
193 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/left/input/trigger/value", &triggerLeftPath));
194 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/right/input/trigger/value", &triggerRightPath));
195 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/left/input/squeeze/value", &gripLeftPath));
196 PLOG_FN_XR(xrStringToPath(
context->getXrInstance(),
"/user/hand/right/input/squeeze/value", &gripRightPath));
198 std::vector<XrActionSuggestedBinding> oculusBindings = {
209 XrPath oculusProfilePath;
212 XrInteractionProfileSuggestedBinding oculusSuggestedBindings{ XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING };
213 oculusSuggestedBindings.interactionProfile = oculusProfilePath;
214 oculusSuggestedBindings.countSuggestedBindings =
static_cast<uint32_t
>(oculusBindings.size());
215 oculusSuggestedBindings.suggestedBindings = oculusBindings.data();
217 PLOG_FN_XR(xrSuggestInteractionProfileBindings(
context->getXrInstance(), &oculusSuggestedBindings));
220 XrSessionActionSetsAttachInfo attachInfo{ XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO };
221 attachInfo.countActionSets = 1;
223 PLOG_FN_XR(xrAttachSessionActionSets(
headset->getSession(), &attachInfo));
226 PLOGI <<
"Finished xr input handler setup";
231 XrSession xrSession =
headset->getSession();
234 XrActionsSyncInfo syncInfo{ XR_TYPE_ACTIONS_SYNC_INFO };
235 syncInfo.countActiveActionSets = 1;
236 syncInfo.activeActionSets = &activeActionSet;
237 xrSyncActions(xrSession, &syncInfo);
243 XrActionStateGetInfo actionStateGetInfo{ XR_TYPE_ACTION_STATE_GET_INFO };
245 actionStateGetInfo.subactionPath = handPoseInfo.
handPath;
247 XrActionStatePose aimPoseState{ XR_TYPE_ACTION_STATE_POSE };
248 PLOG_THROW_FN_XR(xrGetActionStatePose(xrSession, &actionStateGetInfo, &aimPoseState));
250 if (aimPoseState.isActive) {
251 XrSpaceLocation spaceLocation{ XR_TYPE_SPACE_LOCATION };
252 PLOG_THROW_FN_XR(xrLocateSpace(handPoseInfo.
space, playerSpace, predictedDisplayTime, &spaceLocation));
254 constexpr XrSpaceLocationFlags checkFlags =
255 XR_SPACE_LOCATION_POSITION_VALID_BIT | XR_SPACE_LOCATION_POSITION_TRACKED_BIT |
256 XR_SPACE_LOCATION_ORIENTATION_VALID_BIT | XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT;
258 if ((spaceLocation.locationFlags & checkFlags) == checkFlags) {
266 XrActionStateGetInfo thumbstickGetInfo{ XR_TYPE_ACTION_STATE_GET_INFO };
268 thumbstickGetInfo.subactionPath = handPoseInfo.
handPath;
270 XrActionStateVector2f thumbstickState{ XR_TYPE_ACTION_STATE_VECTOR2F };
271 if (xrGetActionStateVector2f(xrSession, &thumbstickGetInfo, &thumbstickState) == XR_SUCCESS) {
272 if (thumbstickState.isActive) {
273 glm::vec2 value(thumbstickState.currentState.x, thumbstickState.currentState.y);
285 XrActionStateGetInfo triggerGetInfo{ XR_TYPE_ACTION_STATE_GET_INFO };
287 triggerGetInfo.subactionPath = handPoseInfo.
handPath;
289 XrActionStateFloat triggerState{ XR_TYPE_ACTION_STATE_FLOAT };
290 if (xrGetActionStateFloat(xrSession, &triggerGetInfo, &triggerState) == XR_SUCCESS) {
291 if (triggerState.isActive) {
299 XrActionStateGetInfo gripGetInfo{ XR_TYPE_ACTION_STATE_GET_INFO };
301 gripGetInfo.subactionPath = handPoseInfo.
handPath;
303 XrActionStateFloat gripState{ XR_TYPE_ACTION_STATE_FLOAT };
304 if (xrGetActionStateFloat(xrSession, &gripGetInfo, &gripState) == XR_SUCCESS) {
305 if (gripState.isActive) {