mirror of
https://github.com/DrBeef/QuakeQuest.git
synced 2024-11-24 21:12:17 +00:00
Cleaned up input
This commit is contained in:
parent
c67d34354c
commit
844495401f
4 changed files with 179 additions and 767 deletions
|
@ -7,8 +7,8 @@ LOCAL_PATH:= $(call my-dir)
|
|||
include $(CLEAR_VARS)
|
||||
|
||||
# Uncomment for the correct headset - slight changes required in OpenXR implementation
|
||||
#OPENXR_HMD = -DMETA_QUEST
|
||||
OPENXR_HMD = -DPICO_XR
|
||||
OPENXR_HMD = -DMETA_QUEST
|
||||
#OPENXR_HMD = -DPICO_XR
|
||||
|
||||
LOCAL_CFLAGS := $(OPENXR_HMD)
|
||||
LOCAL_MODULE := quakequest
|
||||
|
@ -129,8 +129,7 @@ SRC_COMMON := \
|
|||
SRC_QUEST := \
|
||||
QuakeQuestSrc/argtable3.c \
|
||||
QuakeQuestSrc/QuakeQuest_OpenXR.c \
|
||||
QuakeQuestSrc/OpenXrInput_MetaQuest.c \
|
||||
QuakeQuestSrc/OpenXrInput_PicoXR.c \
|
||||
QuakeQuestSrc/OpenXrInput.c \
|
||||
QuakeQuestSrc/TBXR_Common.c \
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#ifdef PICO_XR
|
||||
|
||||
#include "VrCommon.h"
|
||||
|
||||
extern ovrApp gAppState;
|
||||
|
||||
XrResult CheckXrResult(XrResult res, const char* originator) {
|
||||
if (XR_FAILED(res)) {
|
||||
dpsnprintf("error: %s", originator);
|
||||
ALOGE("error: %s", originator);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -19,38 +17,35 @@ XrResult CheckXrResult(XrResult res, const char* originator) {
|
|||
|
||||
|
||||
XrActionSet actionSet;
|
||||
XrAction grabAction;
|
||||
XrAction poseAction;
|
||||
XrAction vibrateAction;
|
||||
XrAction quitAction;
|
||||
/*************************pico******************/
|
||||
XrAction touchpadAction;
|
||||
XrAction AXAction;
|
||||
XrAction homeAction;
|
||||
XrAction BYAction;
|
||||
XrAction backAction;
|
||||
XrAction sideAction;
|
||||
XrAction triggerAction;
|
||||
XrAction joystickAction;
|
||||
XrAction batteryAction;
|
||||
//---add new----------
|
||||
XrAction AXTouchAction;
|
||||
XrAction BYTouchAction;
|
||||
XrAction RockerTouchAction;
|
||||
XrAction TriggerTouchAction;
|
||||
XrAction ThumbrestTouchAction;
|
||||
XrAction GripAction;
|
||||
//---add new----------zgt
|
||||
XrAction AAction;
|
||||
XrAction BAction;
|
||||
XrAction XAction;
|
||||
XrAction YAction;
|
||||
XrAction ATouchAction;
|
||||
XrAction BTouchAction;
|
||||
XrAction XTouchAction;
|
||||
XrAction YTouchAction;
|
||||
XrAction aimAction;
|
||||
/*************************pico******************/
|
||||
XrAction grabAction = 0;
|
||||
XrAction poseAction = 0;
|
||||
XrAction vibrateAction = 0;
|
||||
XrAction quitAction = 0;
|
||||
XrAction touchpadAction = 0;
|
||||
XrAction AXAction = 0;
|
||||
XrAction homeAction = 0;
|
||||
XrAction BYAction = 0;
|
||||
XrAction backAction = 0;
|
||||
XrAction sideAction = 0;
|
||||
XrAction triggerAction = 0;
|
||||
XrAction joystickAction = 0;
|
||||
XrAction batteryAction = 0;
|
||||
XrAction AXTouchAction = 0;
|
||||
XrAction BYTouchAction = 0;
|
||||
XrAction thumbstickTouchAction = 0;
|
||||
XrAction TriggerTouchAction = 0;
|
||||
XrAction ThumbrestTouchAction = 0;
|
||||
XrAction GripAction = 0;
|
||||
XrAction AAction = 0;
|
||||
XrAction BAction = 0;
|
||||
XrAction XAction = 0;
|
||||
XrAction YAction = 0;
|
||||
XrAction ATouchAction = 0;
|
||||
XrAction BTouchAction = 0;
|
||||
XrAction XTouchAction = 0;
|
||||
XrAction YTouchAction = 0;
|
||||
XrAction aimAction = 0;
|
||||
|
||||
XrSpace aimSpace[SIDE_COUNT];
|
||||
XrPath handSubactionPath[SIDE_COUNT];
|
||||
XrSpace handSpace[SIDE_COUNT];
|
||||
|
@ -103,6 +98,30 @@ XrActionStateVector2f GetActionStateVector2(XrAction action, int hand) {
|
|||
return state;
|
||||
}
|
||||
|
||||
void CreateAction(
|
||||
XrActionSet actionSet,
|
||||
XrActionType type,
|
||||
const char* actionName,
|
||||
const char* localizedName,
|
||||
int countSubactionPaths,
|
||||
XrPath* subactionPaths,
|
||||
XrAction* action) {
|
||||
ALOGV("CreateAction %s, %", actionName, countSubactionPaths);
|
||||
|
||||
XrActionCreateInfo aci = {};
|
||||
aci.type = XR_TYPE_ACTION_CREATE_INFO;
|
||||
aci.next = NULL;
|
||||
aci.actionType = type;
|
||||
if (countSubactionPaths > 0) {
|
||||
aci.countSubactionPaths = countSubactionPaths;
|
||||
aci.subactionPaths = subactionPaths;
|
||||
}
|
||||
strcpy(aci.actionName, actionName);
|
||||
strcpy(aci.localizedActionName, localizedName ? localizedName : actionName);
|
||||
*action = XR_NULL_HANDLE;
|
||||
OXR(xrCreateAction(actionSet, &aci, action));
|
||||
}
|
||||
|
||||
void TBXR_InitActions( void )
|
||||
{
|
||||
// Create an action set.
|
||||
|
@ -122,214 +141,40 @@ void TBXR_InitActions( void )
|
|||
// Create actions.
|
||||
{
|
||||
// Create an input action for grabbing objects with the left and right hands.
|
||||
XrActionCreateInfo actionInfo = {};
|
||||
actionInfo.type = XR_TYPE_ACTION_CREATE_INFO;
|
||||
actionInfo.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
|
||||
strcpy(actionInfo.actionName, "grab_object");
|
||||
strcpy(actionInfo.localizedActionName, "Grab Object");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &grabAction));
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_POSE_INPUT, "grab_object", "Grab Object", SIDE_COUNT, handSubactionPath, &grabAction);
|
||||
|
||||
// Create an input action getting the left and right hand poses.
|
||||
actionInfo.actionType = XR_ACTION_TYPE_POSE_INPUT;
|
||||
strcpy(actionInfo.actionName, "hand_pose");
|
||||
strcpy(actionInfo.localizedActionName, "Hand Pose");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &poseAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_POSE_INPUT;
|
||||
strcpy(actionInfo.actionName, "aim_pose");
|
||||
strcpy(actionInfo.localizedActionName, "Aim Pose");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &aimAction));
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_POSE_INPUT, "hand_pose", "Hand Pose", SIDE_COUNT, handSubactionPath, &poseAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_POSE_INPUT, "aim_pose", "Aim Pose", SIDE_COUNT, handSubactionPath, &aimAction);
|
||||
|
||||
// Create output actions for vibrating the left and right controller.
|
||||
actionInfo.actionType = XR_ACTION_TYPE_VIBRATION_OUTPUT;
|
||||
strcpy(actionInfo.actionName, "vibrate_hand");
|
||||
strcpy(actionInfo.localizedActionName, "Vibrate Hand");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &vibrateAction));
|
||||
|
||||
// Create input actions for quitting the session using the left and right controller.
|
||||
// Since it doesn't matter which hand did this, we do not specify subaction paths for it.
|
||||
// We will just suggest bindings for both hands, where possible.
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "quit_session");
|
||||
strcpy(actionInfo.localizedActionName, "Quit Session");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &quitAction));
|
||||
/**********************************pico***************************************/
|
||||
// Create input actions for toucpad key using the left and right controller.
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "touchpad");
|
||||
strcpy(actionInfo.localizedActionName, "Touchpad");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &touchpadAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "axkey");
|
||||
strcpy(actionInfo.localizedActionName, "AXkey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &AXAction));
|
||||
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "homekey");
|
||||
strcpy(actionInfo.localizedActionName, "Homekey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &homeAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "bykey");
|
||||
strcpy(actionInfo.localizedActionName, "BYkey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &BYAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "backkey");
|
||||
strcpy(actionInfo.localizedActionName, "Backkey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &backAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "sidekey");
|
||||
strcpy(actionInfo.localizedActionName, "Sidekey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &sideAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
|
||||
strcpy(actionInfo.actionName, "trigger");
|
||||
strcpy(actionInfo.localizedActionName, "Trigger");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &triggerAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_VECTOR2F_INPUT;
|
||||
strcpy(actionInfo.actionName, "joystick");
|
||||
strcpy(actionInfo.localizedActionName, "Joystick");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &joystickAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
|
||||
strcpy(actionInfo.actionName, "battery");
|
||||
strcpy(actionInfo.localizedActionName, "battery");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &batteryAction));
|
||||
//------------------------add new---------------------------------
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "axtouch");
|
||||
strcpy(actionInfo.localizedActionName, "AXtouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &AXTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "bytouch");
|
||||
strcpy(actionInfo.localizedActionName, "BYtouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &BYTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "rockertouch");
|
||||
strcpy(actionInfo.localizedActionName, "Rockertouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &RockerTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "triggertouch");
|
||||
strcpy(actionInfo.localizedActionName, "Triggertouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &TriggerTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "thumbresttouch");
|
||||
strcpy(actionInfo.localizedActionName, "Thumbresttouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &ThumbrestTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_FLOAT_INPUT;
|
||||
strcpy(actionInfo.actionName, "gripvalue");
|
||||
strcpy(actionInfo.localizedActionName, "GripValue");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &GripAction));
|
||||
|
||||
//--------------add new----------zgt
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "akey");
|
||||
strcpy(actionInfo.localizedActionName, "Akey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &AAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "bkey");
|
||||
strcpy(actionInfo.localizedActionName, "Bkey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &BAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "xkey");
|
||||
strcpy(actionInfo.localizedActionName, "Xkey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &XAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "ykey");
|
||||
strcpy(actionInfo.localizedActionName, "Ykey");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &YAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "atouch");
|
||||
strcpy(actionInfo.localizedActionName, "Atouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &ATouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "btouch");
|
||||
strcpy(actionInfo.localizedActionName, "Btouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &BTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "xtouch");
|
||||
strcpy(actionInfo.localizedActionName, "Xtouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &XTouchAction));
|
||||
|
||||
actionInfo.actionType = XR_ACTION_TYPE_BOOLEAN_INPUT;
|
||||
strcpy(actionInfo.actionName, "ytouch");
|
||||
strcpy(actionInfo.localizedActionName, "Ytouch");
|
||||
actionInfo.countSubactionPaths = SIDE_COUNT;
|
||||
actionInfo.subactionPaths = handSubactionPath;
|
||||
CHECK_XRCMD(xrCreateAction(actionSet, &actionInfo, &YTouchAction));
|
||||
/**********************************pico***************************************/
|
||||
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_VIBRATION_OUTPUT, "vibrate_hand", "Vibrate Hand", SIDE_COUNT, handSubactionPath, &vibrateAction);
|
||||
|
||||
//All remaining actions (not necessarily supported by all controllers)
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "quit_session", "Quit Session", SIDE_COUNT, handSubactionPath, &quitAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "touchpad", "Touchpad", SIDE_COUNT, handSubactionPath, &touchpadAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "axkey", "AXkey", SIDE_COUNT, handSubactionPath, &AXAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "homekey", "Homekey", SIDE_COUNT, handSubactionPath, &homeAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "bykey", "BYkey", SIDE_COUNT, handSubactionPath, &BYAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "backkey", "Backkey", SIDE_COUNT, handSubactionPath, &backAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "sidekey", "Sidekey", SIDE_COUNT, handSubactionPath, &sideAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_FLOAT_INPUT, "trigger", "Trigger", SIDE_COUNT, handSubactionPath, &triggerAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_VECTOR2F_INPUT, "joystick", "Joystick", SIDE_COUNT, handSubactionPath, &joystickAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_FLOAT_INPUT, "battery", "battery", SIDE_COUNT, handSubactionPath, &batteryAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "axtouch", "AXtouch", SIDE_COUNT, handSubactionPath, &AXTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "bytouch", "BYtouch", SIDE_COUNT, handSubactionPath, &BYTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "rockertouch", "Rockertouch", SIDE_COUNT, handSubactionPath, &thumbstickTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "triggertouch", "Triggertouch", SIDE_COUNT, handSubactionPath, &TriggerTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "thumbresttouch", "Thumbresttouch", SIDE_COUNT, handSubactionPath, &ThumbrestTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_FLOAT_INPUT, "gripvalue", "GripValue", SIDE_COUNT, handSubactionPath, &GripAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "akey", "Akey", SIDE_COUNT, handSubactionPath, &AAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "bkey", "Bkey", SIDE_COUNT, handSubactionPath, &BAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "xkey", "Xkey", SIDE_COUNT, handSubactionPath, &XAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "ykey", "Ykey", SIDE_COUNT, handSubactionPath, &YAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "atouch", "Atouch", SIDE_COUNT, handSubactionPath, &ATouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "btouch", "Btouch", SIDE_COUNT, handSubactionPath, &BTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "xtouch", "Xtouch", SIDE_COUNT, handSubactionPath, &XTouchAction);
|
||||
CreateAction(actionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "ytouch", "Ytouch", SIDE_COUNT, handSubactionPath, &YTouchAction);
|
||||
}
|
||||
|
||||
XrPath selectPath[SIDE_COUNT];
|
||||
|
@ -347,7 +192,6 @@ void TBXR_InitActions( void )
|
|||
XrPath thumbstickPosPath[SIDE_COUNT];
|
||||
XrPath aimPath[SIDE_COUNT];
|
||||
|
||||
/**************************pico************************************/
|
||||
XrPath touchpadPath[SIDE_COUNT];
|
||||
XrPath AXValuePath[SIDE_COUNT];
|
||||
XrPath homeClickPath[SIDE_COUNT];
|
||||
|
@ -357,14 +201,14 @@ void TBXR_InitActions( void )
|
|||
XrPath triggerPath[SIDE_COUNT];
|
||||
XrPath joystickPath[SIDE_COUNT];
|
||||
XrPath batteryPath[SIDE_COUNT];
|
||||
//--------------add new----------
|
||||
|
||||
XrPath GripPath[SIDE_COUNT];
|
||||
XrPath AXTouchPath[SIDE_COUNT];
|
||||
XrPath BYTouchPath[SIDE_COUNT];
|
||||
XrPath RockerTouchPath[SIDE_COUNT];
|
||||
XrPath TriggerTouchPath[SIDE_COUNT];
|
||||
XrPath ThumbresetTouchPath[SIDE_COUNT];
|
||||
//--------------add new----------zgt
|
||||
|
||||
XrPath AValuePath[SIDE_COUNT];
|
||||
XrPath BValuePath[SIDE_COUNT];
|
||||
XrPath XValuePath[SIDE_COUNT];
|
||||
|
@ -373,7 +217,7 @@ void TBXR_InitActions( void )
|
|||
XrPath BTouchPath[SIDE_COUNT];
|
||||
XrPath XTouchPath[SIDE_COUNT];
|
||||
XrPath YTouchPath[SIDE_COUNT];
|
||||
/**************************pico************************************/
|
||||
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/left/input/select/click", &selectPath[SIDE_LEFT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/right/input/select/click", &selectPath[SIDE_RIGHT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/left/input/menu/click", &menuClickPath[SIDE_LEFT]));
|
||||
|
@ -408,7 +252,6 @@ void TBXR_InitActions( void )
|
|||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/left/input/thumbrest/touch", &thumbrestPath[SIDE_LEFT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/right/input/thumbrest/touch", &thumbrestPath[SIDE_RIGHT]));
|
||||
|
||||
/**************************pico************************************/
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/left/input/back/click", &backPath[SIDE_LEFT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/right/input/back/click", &backPath[SIDE_RIGHT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/left/input/battery/value", &batteryPath[SIDE_LEFT]));
|
||||
|
@ -422,22 +265,24 @@ void TBXR_InitActions( void )
|
|||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/left/input/y/touch", &YTouchPath[SIDE_LEFT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/right/input/a/touch", &ATouchPath[SIDE_RIGHT]));
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/user/hand/right/input/b/touch", &BTouchPath[SIDE_RIGHT]));
|
||||
/**************************pico************************************/
|
||||
XrActionSuggestedBinding bindings[128];
|
||||
int currBinding = 0;
|
||||
|
||||
// Suggest bindings for the Pico Neo 3 controller
|
||||
|
||||
XrResult result;
|
||||
|
||||
//First try Pico Devices
|
||||
{
|
||||
XrPath picoMixedRealityInteractionProfilePath;
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/interaction_profiles/pico/neo3_controller",
|
||||
&picoMixedRealityInteractionProfilePath));
|
||||
|
||||
XrActionSuggestedBinding bindings[128];
|
||||
int currBinding = 0;
|
||||
bindings[currBinding++] = ActionSuggestedBinding(touchpadAction, thumbstickClickPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(touchpadAction, thumbstickClickPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(joystickAction, thumbstickPosPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(joystickAction, thumbstickPosPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(RockerTouchAction, thumbstickTouchPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(RockerTouchAction, thumbstickTouchPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(thumbstickTouchAction, thumbstickTouchPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(thumbstickTouchAction, thumbstickTouchPath[SIDE_RIGHT]);
|
||||
|
||||
bindings[currBinding++] = ActionSuggestedBinding(triggerAction, triggerValuePath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(triggerAction, triggerValuePath[SIDE_RIGHT]);
|
||||
|
@ -479,7 +324,58 @@ void TBXR_InitActions( void )
|
|||
suggestedBindings.interactionProfile = picoMixedRealityInteractionProfilePath;
|
||||
suggestedBindings.suggestedBindings = bindings;
|
||||
suggestedBindings.countSuggestedBindings = currBinding;
|
||||
CHECK_XRCMD(xrSuggestInteractionProfileBindings(gAppState.Instance, &suggestedBindings));
|
||||
result = xrSuggestInteractionProfileBindings(gAppState.Instance, &suggestedBindings);
|
||||
}
|
||||
|
||||
if (result != XR_SUCCESS)
|
||||
{
|
||||
XrPath touchControllerInteractionProfilePath;
|
||||
CHECK_XRCMD(xrStringToPath(gAppState.Instance, "/interaction_profiles/oculus/touch_controller",
|
||||
&touchControllerInteractionProfilePath));
|
||||
|
||||
XrActionSuggestedBinding bindings[128];
|
||||
int currBinding = 0;
|
||||
bindings[currBinding++] = ActionSuggestedBinding(touchpadAction, thumbstickClickPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(touchpadAction, thumbstickClickPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(joystickAction, thumbstickPosPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(joystickAction, thumbstickPosPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(thumbstickTouchAction, thumbstickTouchPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(thumbstickTouchAction, thumbstickTouchPath[SIDE_RIGHT]);
|
||||
|
||||
bindings[currBinding++] = ActionSuggestedBinding(triggerAction, triggerValuePath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(triggerAction, triggerValuePath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(TriggerTouchAction, triggerTouchPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(TriggerTouchAction, triggerTouchPath[SIDE_RIGHT]);
|
||||
|
||||
bindings[currBinding++] = ActionSuggestedBinding(GripAction, squeezeValuePath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(GripAction, squeezeValuePath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(poseAction, posePath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(poseAction, posePath[SIDE_RIGHT]);
|
||||
|
||||
bindings[currBinding++] = ActionSuggestedBinding(backAction, menuClickPath[SIDE_LEFT]);
|
||||
|
||||
bindings[currBinding++] = ActionSuggestedBinding(ThumbrestTouchAction, thumbrestPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(ThumbrestTouchAction, thumbrestPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(vibrateAction, hapticPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(vibrateAction, hapticPath[SIDE_RIGHT]);
|
||||
|
||||
bindings[currBinding++] = ActionSuggestedBinding(XTouchAction, XTouchPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(YTouchAction, YTouchPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(ATouchAction, ATouchPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(BTouchAction, BTouchPath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(XAction, XValuePath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(YAction, YValuePath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(AAction, AValuePath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(BAction, BValuePath[SIDE_RIGHT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(aimAction, aimPath[SIDE_LEFT]);
|
||||
bindings[currBinding++] = ActionSuggestedBinding(aimAction, aimPath[SIDE_RIGHT]);
|
||||
|
||||
XrInteractionProfileSuggestedBinding suggestedBindings = {};
|
||||
suggestedBindings.type = XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING;
|
||||
suggestedBindings.interactionProfile = touchControllerInteractionProfilePath;
|
||||
suggestedBindings.suggestedBindings = bindings;
|
||||
suggestedBindings.countSuggestedBindings = currBinding;
|
||||
result = xrSuggestInteractionProfileBindings(gAppState.Instance, &suggestedBindings);
|
||||
}
|
||||
|
||||
XrActionSpaceCreateInfo actionSpaceInfo = {};
|
||||
|
@ -529,7 +425,7 @@ void TBXR_UpdateControllers( )
|
|||
loc.next = &vel;
|
||||
XrResult res = xrLocateSpace(aimSpace[i], gAppState.CurrentSpace, gAppState.FrameState.predictedDisplayTime, &loc);
|
||||
if (res != XR_SUCCESS) {
|
||||
dpsnprintf("xrLocateSpace error: %d", (int)res);
|
||||
ALOGE("xrLocateSpace error: %d", (int)res);
|
||||
}
|
||||
|
||||
gAppState.TrackedController[i].Active = (loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) != 0;
|
||||
|
@ -541,23 +437,36 @@ void TBXR_UpdateControllers( )
|
|||
rightRemoteTracking_new = gAppState.TrackedController[1];
|
||||
|
||||
|
||||
|
||||
//button mapping
|
||||
leftTrackedRemoteState_new.Buttons = 0;
|
||||
if (GetActionStateBoolean(backAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Enter;
|
||||
if (GetActionStateBoolean(XAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_X;
|
||||
if (GetActionStateBoolean(XTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_X;
|
||||
if (GetActionStateBoolean(YAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Y;
|
||||
if (GetActionStateBoolean(sideAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_GripTrigger;
|
||||
if (GetActionStateBoolean(YTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_Y;
|
||||
leftTrackedRemoteState_new.GripTrigger = GetActionStateFloat(GripAction, SIDE_LEFT).currentState;
|
||||
if (leftTrackedRemoteState_new.GripTrigger > 0.5f) leftTrackedRemoteState_new.Buttons |= xrButton_GripTrigger;
|
||||
if (GetActionStateBoolean(touchpadAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_LThumb;
|
||||
if (GetActionStateFloat(triggerAction, SIDE_LEFT).currentState > 0.5f) leftTrackedRemoteState_new.Buttons |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(thumbstickTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_LThumb;
|
||||
leftTrackedRemoteState_new.IndexTrigger = GetActionStateFloat(triggerAction, SIDE_LEFT).currentState;
|
||||
if (leftTrackedRemoteState_new.IndexTrigger > 0.5f) leftTrackedRemoteState_new.Buttons |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(TriggerTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(ThumbrestTouchAction, SIDE_LEFT).currentState) leftTrackedRemoteState_new.Touches |= xrButton_ThumbRest;
|
||||
|
||||
rightTrackedRemoteState_new.Buttons = 0;
|
||||
if (GetActionStateBoolean(backAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_Enter;
|
||||
if (GetActionStateBoolean(AAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_A;
|
||||
if (GetActionStateBoolean(ATouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_A;
|
||||
if (GetActionStateBoolean(BAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_B;
|
||||
if (GetActionStateBoolean(sideAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_GripTrigger;
|
||||
if (GetActionStateBoolean(BTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_B;
|
||||
rightTrackedRemoteState_new.GripTrigger = GetActionStateFloat(GripAction, SIDE_RIGHT).currentState;
|
||||
if (rightTrackedRemoteState_new.GripTrigger > 0.5f) rightTrackedRemoteState_new.Buttons |= xrButton_GripTrigger;
|
||||
if (GetActionStateBoolean(touchpadAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_RThumb;
|
||||
if (GetActionStateFloat(triggerAction, SIDE_RIGHT).currentState > 0.5f) rightTrackedRemoteState_new.Buttons |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(thumbstickTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_LThumb;
|
||||
rightTrackedRemoteState_new.IndexTrigger = GetActionStateFloat(triggerAction, SIDE_RIGHT).currentState;
|
||||
if (rightTrackedRemoteState_new.IndexTrigger > 0.5f) rightTrackedRemoteState_new.Buttons |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(TriggerTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(ThumbrestTouchAction, SIDE_RIGHT).currentState) rightTrackedRemoteState_new.Touches |= xrButton_ThumbRest;
|
||||
|
||||
//thumbstick
|
||||
XrActionStateVector2f moveJoystickState;
|
||||
|
@ -570,6 +479,7 @@ void TBXR_UpdateControllers( )
|
|||
rightTrackedRemoteState_new.Joystick.y = moveJoystickState.currentState.y;
|
||||
}
|
||||
|
||||
|
||||
//0 = left, 1 = right
|
||||
float vibration_channel_duration[2] = {0.0f, 0.0f};
|
||||
float vibration_channel_intensity[2] = {0.0f, 0.0f};
|
||||
|
@ -578,16 +488,17 @@ void TBXR_Vibrate( int duration, int chan, float intensity )
|
|||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
int channel = 1-i;
|
||||
if ((i + 1) & chan)
|
||||
{
|
||||
if (vibration_channel_duration[i] > 0.0f)
|
||||
if (vibration_channel_duration[channel] > 0.0f)
|
||||
return;
|
||||
|
||||
if (vibration_channel_duration[i] == -1.0f && duration != 0.0f)
|
||||
if (vibration_channel_duration[channel] == -1.0f && duration != 0.0f)
|
||||
return;
|
||||
|
||||
vibration_channel_duration[i] = duration;
|
||||
vibration_channel_intensity[i] = intensity;
|
||||
vibration_channel_duration[channel] = duration;
|
||||
vibration_channel_intensity[channel] = intensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -635,4 +546,3 @@ void TBXR_ProcessHaptics() {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif //PICO_XR
|
|
@ -1,502 +0,0 @@
|
|||
|
||||
#ifdef META_QUEST
|
||||
|
||||
#include "VrCommon.h"
|
||||
|
||||
extern ovrApp gAppState;
|
||||
|
||||
XrSpace CreateActionSpace(XrAction poseAction, XrPath subactionPath) {
|
||||
XrActionSpaceCreateInfo asci = {};
|
||||
asci.type = XR_TYPE_ACTION_SPACE_CREATE_INFO;
|
||||
asci.action = poseAction;
|
||||
asci.poseInActionSpace.orientation.w = 1.0f;
|
||||
asci.subactionPath = subactionPath;
|
||||
XrSpace actionSpace = XR_NULL_HANDLE;
|
||||
OXR(xrCreateActionSpace(gAppState.Session, &asci, &actionSpace));
|
||||
return actionSpace;
|
||||
}
|
||||
|
||||
XrActionSuggestedBinding ActionSuggestedBinding(XrAction action, const char* bindingString) {
|
||||
XrActionSuggestedBinding asb;
|
||||
asb.action = action;
|
||||
XrPath bindingPath;
|
||||
OXR(xrStringToPath(gAppState.Instance, bindingString, &bindingPath));
|
||||
asb.binding = bindingPath;
|
||||
return asb;
|
||||
}
|
||||
|
||||
XrActionSet CreateActionSet(int priority, const char* name, const char* localizedName) {
|
||||
XrActionSetCreateInfo asci = {};
|
||||
asci.type = XR_TYPE_ACTION_SET_CREATE_INFO;
|
||||
asci.next = NULL;
|
||||
asci.priority = priority;
|
||||
strcpy(asci.actionSetName, name);
|
||||
strcpy(asci.localizedActionSetName, localizedName);
|
||||
XrActionSet actionSet = XR_NULL_HANDLE;
|
||||
OXR(xrCreateActionSet(gAppState.Instance, &asci, &actionSet));
|
||||
return actionSet;
|
||||
}
|
||||
|
||||
XrAction CreateAction(
|
||||
XrActionSet actionSet,
|
||||
XrActionType type,
|
||||
const char* actionName,
|
||||
const char* localizedName,
|
||||
int countSubactionPaths,
|
||||
XrPath* subactionPaths) {
|
||||
ALOGV("CreateAction %s, %" PRIi32, actionName, countSubactionPaths);
|
||||
|
||||
XrActionCreateInfo aci = {};
|
||||
aci.type = XR_TYPE_ACTION_CREATE_INFO;
|
||||
aci.next = NULL;
|
||||
aci.actionType = type;
|
||||
if (countSubactionPaths > 0) {
|
||||
aci.countSubactionPaths = countSubactionPaths;
|
||||
aci.subactionPaths = subactionPaths;
|
||||
}
|
||||
strcpy(aci.actionName, actionName);
|
||||
strcpy(aci.localizedActionName, localizedName ? localizedName : actionName);
|
||||
XrAction action = XR_NULL_HANDLE;
|
||||
OXR(xrCreateAction(actionSet, &aci, &action));
|
||||
return action;
|
||||
}
|
||||
|
||||
bool ActionPoseIsActive(XrAction action, XrPath subactionPath) {
|
||||
XrActionStateGetInfo getInfo = {};
|
||||
getInfo.type = XR_TYPE_ACTION_STATE_GET_INFO;
|
||||
getInfo.action = action;
|
||||
getInfo.subactionPath = subactionPath;
|
||||
|
||||
XrActionStatePose state = {};
|
||||
state.type = XR_TYPE_ACTION_STATE_POSE;
|
||||
OXR(xrGetActionStatePose(gAppState.Session, &getInfo, &state));
|
||||
return state.isActive != XR_FALSE;
|
||||
}
|
||||
|
||||
XrActionStateFloat GetActionStateFloat(XrAction action) {
|
||||
XrActionStateGetInfo getInfo = {};
|
||||
getInfo.type = XR_TYPE_ACTION_STATE_GET_INFO;
|
||||
getInfo.action = action;
|
||||
|
||||
XrActionStateFloat state = {};
|
||||
state.type = XR_TYPE_ACTION_STATE_FLOAT;
|
||||
|
||||
OXR(xrGetActionStateFloat(gAppState.Session, &getInfo, &state));
|
||||
return state;
|
||||
}
|
||||
|
||||
XrActionStateBoolean GetActionStateBoolean(XrAction action) {
|
||||
XrActionStateGetInfo getInfo = {};
|
||||
getInfo.type = XR_TYPE_ACTION_STATE_GET_INFO;
|
||||
getInfo.action = action;
|
||||
|
||||
XrActionStateBoolean state = {};
|
||||
state.type = XR_TYPE_ACTION_STATE_BOOLEAN;
|
||||
|
||||
OXR(xrGetActionStateBoolean(gAppState.Session, &getInfo, &state));
|
||||
return state;
|
||||
}
|
||||
|
||||
XrActionStateVector2f GetActionStateVector2(XrAction action) {
|
||||
XrActionStateGetInfo getInfo = {};
|
||||
getInfo.type = XR_TYPE_ACTION_STATE_GET_INFO;
|
||||
getInfo.action = action;
|
||||
|
||||
XrActionStateVector2f state = {};
|
||||
state.type = XR_TYPE_ACTION_STATE_VECTOR2F;
|
||||
|
||||
OXR(xrGetActionStateVector2f(gAppState.Session, &getInfo, &state));
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
//OpenXR
|
||||
XrPath leftHandPath;
|
||||
XrPath rightHandPath;
|
||||
XrAction handPoseLeftAction;
|
||||
XrAction handPoseRightAction;
|
||||
XrAction indexLeftAction;
|
||||
XrAction indexRightAction;
|
||||
XrAction menuAction;
|
||||
XrAction buttonAAction;
|
||||
XrAction buttonBAction;
|
||||
XrAction buttonXAction;
|
||||
XrAction buttonYAction;
|
||||
XrAction gripLeftAction;
|
||||
XrAction gripRightAction;
|
||||
XrAction moveOnLeftJoystickAction;
|
||||
XrAction moveOnRightJoystickAction;
|
||||
XrAction thumbstickLeftClickAction;
|
||||
XrAction thumbstickRightClickAction;
|
||||
XrAction vibrateLeftFeedback;
|
||||
XrAction vibrateRightFeedback;
|
||||
XrActionSet runningActionSet;
|
||||
XrSpace leftControllerAimSpace = XR_NULL_HANDLE;
|
||||
XrSpace rightControllerAimSpace = XR_NULL_HANDLE;
|
||||
bool inputInitialized = false;
|
||||
bool useSimpleProfile = false;
|
||||
|
||||
|
||||
void TBXR_InitActions( void )
|
||||
{
|
||||
// Actions
|
||||
runningActionSet = CreateActionSet(1, "running_action_set", "Action Set used on main loop");
|
||||
indexLeftAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "index_left", "Index left", 0, NULL);
|
||||
indexRightAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "index_right", "Index right", 0, NULL);
|
||||
menuAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "menu_action", "Menu", 0, NULL);
|
||||
buttonAAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "button_a", "Button A", 0, NULL);
|
||||
buttonBAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "button_b", "Button B", 0, NULL);
|
||||
buttonXAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "button_x", "Button X", 0, NULL);
|
||||
buttonYAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "button_y", "Button Y", 0, NULL);
|
||||
gripLeftAction = CreateAction(runningActionSet, XR_ACTION_TYPE_FLOAT_INPUT, "grip_left", "Grip left", 0, NULL);
|
||||
gripRightAction = CreateAction(runningActionSet, XR_ACTION_TYPE_FLOAT_INPUT, "grip_right", "Grip right", 0, NULL);
|
||||
moveOnLeftJoystickAction = CreateAction(runningActionSet, XR_ACTION_TYPE_VECTOR2F_INPUT, "move_on_left_joy", "Move on left Joy", 0, NULL);
|
||||
moveOnRightJoystickAction = CreateAction(runningActionSet, XR_ACTION_TYPE_VECTOR2F_INPUT, "move_on_right_joy", "Move on right Joy", 0, NULL);
|
||||
thumbstickLeftClickAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "thumbstick_left", "Thumbstick left", 0, NULL);
|
||||
thumbstickRightClickAction = CreateAction(runningActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "thumbstick_right", "Thumbstick right", 0, NULL);
|
||||
vibrateLeftFeedback = CreateAction(runningActionSet, XR_ACTION_TYPE_VIBRATION_OUTPUT, "vibrate_left_feedback", "Vibrate Left Controller Feedback", 0, NULL);
|
||||
vibrateRightFeedback = CreateAction(runningActionSet, XR_ACTION_TYPE_VIBRATION_OUTPUT, "vibrate_right_feedback", "Vibrate Right Controller Feedback", 0, NULL);
|
||||
|
||||
OXR(xrStringToPath(gAppState.Instance, "/user/hand/left", &leftHandPath));
|
||||
OXR(xrStringToPath(gAppState.Instance, "/user/hand/right", &rightHandPath));
|
||||
handPoseLeftAction = CreateAction(runningActionSet, XR_ACTION_TYPE_POSE_INPUT, "hand_pose_left", NULL, 1, &leftHandPath);
|
||||
handPoseRightAction = CreateAction(runningActionSet, XR_ACTION_TYPE_POSE_INPUT, "hand_pose_right", NULL, 1, &rightHandPath);
|
||||
|
||||
if (leftControllerAimSpace == XR_NULL_HANDLE) {
|
||||
leftControllerAimSpace = CreateActionSpace(handPoseLeftAction, leftHandPath);
|
||||
}
|
||||
if (rightControllerAimSpace == XR_NULL_HANDLE) {
|
||||
rightControllerAimSpace = CreateActionSpace(handPoseRightAction, rightHandPath);
|
||||
}
|
||||
|
||||
XrPath interactionProfilePath = XR_NULL_PATH;
|
||||
XrPath interactionProfilePathTouch = XR_NULL_PATH;
|
||||
XrPath interactionProfilePathKHRSimple = XR_NULL_PATH;
|
||||
|
||||
OXR(xrStringToPath(gAppState.Instance, "/interaction_profiles/oculus/touch_controller", &interactionProfilePathTouch));
|
||||
OXR(xrStringToPath(gAppState.Instance, "/interaction_profiles/khr/simple_controller", &interactionProfilePathKHRSimple));
|
||||
|
||||
// Toggle this to force simple as a first choice, otherwise use it as a last resort
|
||||
if (useSimpleProfile) {
|
||||
ALOGV("xrSuggestInteractionProfileBindings found bindings for Khronos SIMPLE controller");
|
||||
interactionProfilePath = interactionProfilePathKHRSimple;
|
||||
} else {
|
||||
// Query Set
|
||||
XrActionSet queryActionSet = CreateActionSet(1, "query_action_set", "Action Set used to query device caps");
|
||||
XrAction dummyAction = CreateAction(queryActionSet, XR_ACTION_TYPE_BOOLEAN_INPUT, "dummy_action", "Dummy Action", 0, NULL);
|
||||
|
||||
// Map bindings
|
||||
XrActionSuggestedBinding bindings[1];
|
||||
int currBinding = 0;
|
||||
bindings[currBinding++] = ActionSuggestedBinding(dummyAction, "/user/hand/right/input/system/click");
|
||||
|
||||
XrInteractionProfileSuggestedBinding suggestedBindings = {};
|
||||
suggestedBindings.type = XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING;
|
||||
suggestedBindings.next = NULL;
|
||||
suggestedBindings.suggestedBindings = bindings;
|
||||
suggestedBindings.countSuggestedBindings = currBinding;
|
||||
|
||||
// Try all
|
||||
suggestedBindings.interactionProfile = interactionProfilePathTouch;
|
||||
XrResult suggestTouchResult = xrSuggestInteractionProfileBindings(gAppState.Instance, &suggestedBindings);
|
||||
OXR(suggestTouchResult);
|
||||
|
||||
if (XR_SUCCESS == suggestTouchResult) {
|
||||
ALOGV("xrSuggestInteractionProfileBindings found bindings for QUEST controller");
|
||||
interactionProfilePath = interactionProfilePathTouch;
|
||||
}
|
||||
|
||||
if (interactionProfilePath == XR_NULL_PATH) {
|
||||
// Simple as a fallback
|
||||
bindings[0] = ActionSuggestedBinding(dummyAction, "/user/hand/right/input/select/click");
|
||||
suggestedBindings.interactionProfile = interactionProfilePathKHRSimple;
|
||||
XrResult suggestKHRSimpleResult = xrSuggestInteractionProfileBindings(gAppState.Instance, &suggestedBindings);
|
||||
OXR(suggestKHRSimpleResult);
|
||||
if (XR_SUCCESS == suggestKHRSimpleResult) {
|
||||
ALOGV("xrSuggestInteractionProfileBindings found bindings for Khronos SIMPLE controller");
|
||||
interactionProfilePath = interactionProfilePathKHRSimple;
|
||||
} else {
|
||||
ALOGE("xrSuggestInteractionProfileBindings did NOT find any bindings.");
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Action creation
|
||||
{
|
||||
// Map bindings
|
||||
XrActionSuggestedBinding bindings[32]; // large enough for all profiles
|
||||
int currBinding = 0;
|
||||
|
||||
{
|
||||
if (interactionProfilePath == interactionProfilePathTouch) {
|
||||
bindings[currBinding++] = ActionSuggestedBinding(indexLeftAction, "/user/hand/left/input/trigger");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(indexRightAction, "/user/hand/right/input/trigger");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(menuAction, "/user/hand/left/input/menu/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(buttonXAction, "/user/hand/left/input/x/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(buttonYAction, "/user/hand/left/input/y/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(buttonAAction, "/user/hand/right/input/a/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(buttonBAction, "/user/hand/right/input/b/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(gripLeftAction, "/user/hand/left/input/squeeze/value");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(gripRightAction, "/user/hand/right/input/squeeze/value");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(moveOnLeftJoystickAction, "/user/hand/left/input/thumbstick");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(moveOnRightJoystickAction, "/user/hand/right/input/thumbstick");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(thumbstickLeftClickAction, "/user/hand/left/input/thumbstick/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(thumbstickRightClickAction, "/user/hand/right/input/thumbstick/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(vibrateLeftFeedback, "/user/hand/left/output/haptic");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(vibrateRightFeedback, "/user/hand/right/output/haptic");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(handPoseLeftAction, "/user/hand/left/input/aim/pose");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(handPoseRightAction, "/user/hand/right/input/aim/pose");
|
||||
}
|
||||
|
||||
if (interactionProfilePath == interactionProfilePathKHRSimple) {
|
||||
bindings[currBinding++] = ActionSuggestedBinding(indexLeftAction, "/user/hand/left/input/select/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(indexRightAction, "/user/hand/right/input/select/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(buttonAAction, "/user/hand/left/input/menu/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(buttonXAction, "/user/hand/right/input/menu/click");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(vibrateLeftFeedback, "/user/hand/left/output/haptic");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(vibrateRightFeedback, "/user/hand/right/output/haptic");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(handPoseLeftAction, "/user/hand/left/input/aim/pose");
|
||||
bindings[currBinding++] = ActionSuggestedBinding(handPoseRightAction, "/user/hand/right/input/aim/pose");
|
||||
}
|
||||
}
|
||||
|
||||
XrInteractionProfileSuggestedBinding suggestedBindings = {};
|
||||
suggestedBindings.type = XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING;
|
||||
suggestedBindings.next = NULL;
|
||||
suggestedBindings.interactionProfile = interactionProfilePath;
|
||||
suggestedBindings.suggestedBindings = bindings;
|
||||
suggestedBindings.countSuggestedBindings = currBinding;
|
||||
OXR(xrSuggestInteractionProfileBindings(gAppState.Instance, &suggestedBindings));
|
||||
|
||||
// Enumerate actions
|
||||
XrPath actionPathsBuffer[32];
|
||||
char stringBuffer[256];
|
||||
XrAction actionsToEnumerate[] = {
|
||||
indexLeftAction,
|
||||
indexRightAction,
|
||||
menuAction,
|
||||
buttonAAction,
|
||||
buttonBAction,
|
||||
buttonXAction,
|
||||
buttonYAction,
|
||||
gripLeftAction,
|
||||
gripRightAction,
|
||||
moveOnLeftJoystickAction,
|
||||
moveOnRightJoystickAction,
|
||||
thumbstickLeftClickAction,
|
||||
thumbstickRightClickAction,
|
||||
vibrateLeftFeedback,
|
||||
vibrateRightFeedback,
|
||||
handPoseLeftAction,
|
||||
handPoseRightAction
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(actionsToEnumerate) / sizeof(actionsToEnumerate[0]); ++i) {
|
||||
XrBoundSourcesForActionEnumerateInfo enumerateInfo = {};
|
||||
enumerateInfo.type = XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO;
|
||||
enumerateInfo.next = NULL;
|
||||
enumerateInfo.action = actionsToEnumerate[i];
|
||||
|
||||
// Get Count
|
||||
uint32_t countOutput = 0;
|
||||
OXR(xrEnumerateBoundSourcesForAction(
|
||||
gAppState.Session, &enumerateInfo, 0 /* request size */, &countOutput, NULL));
|
||||
ALOGV(
|
||||
"xrEnumerateBoundSourcesForAction action=%lld count=%u",
|
||||
(long long)enumerateInfo.action,
|
||||
countOutput);
|
||||
|
||||
if (countOutput < 32) {
|
||||
OXR(xrEnumerateBoundSourcesForAction(
|
||||
gAppState.Session, &enumerateInfo, 32, &countOutput, actionPathsBuffer));
|
||||
for (uint32_t a = 0; a < countOutput; ++a) {
|
||||
XrInputSourceLocalizedNameGetInfo nameGetInfo = {};
|
||||
nameGetInfo.type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO;
|
||||
nameGetInfo.next = NULL;
|
||||
nameGetInfo.sourcePath = actionPathsBuffer[a];
|
||||
nameGetInfo.whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT |
|
||||
XR_INPUT_SOURCE_LOCALIZED_NAME_INTERACTION_PROFILE_BIT |
|
||||
XR_INPUT_SOURCE_LOCALIZED_NAME_COMPONENT_BIT;
|
||||
|
||||
uint32_t stringCount = 0u;
|
||||
OXR(xrGetInputSourceLocalizedName(
|
||||
gAppState.Session, &nameGetInfo, 0, &stringCount, NULL));
|
||||
if (stringCount < 256) {
|
||||
OXR(xrGetInputSourceLocalizedName(
|
||||
gAppState.Session, &nameGetInfo, 256, &stringCount, stringBuffer));
|
||||
char pathStr[256];
|
||||
uint32_t strLen = 0;
|
||||
OXR(xrPathToString(
|
||||
gAppState.Instance,
|
||||
actionPathsBuffer[a],
|
||||
(uint32_t)sizeof(pathStr),
|
||||
&strLen,
|
||||
pathStr));
|
||||
ALOGV(
|
||||
" -> path = %lld `%s` -> `%s`",
|
||||
(long long)actionPathsBuffer[a],
|
||||
pathStr,
|
||||
stringBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attach to session
|
||||
XrSessionActionSetsAttachInfo attachInfo = {};
|
||||
attachInfo.type = XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO;
|
||||
attachInfo.next = NULL;
|
||||
attachInfo.countActionSets = 1;
|
||||
attachInfo.actionSets = &runningActionSet;
|
||||
OXR(xrAttachSessionActionSets(gAppState.Session, &attachInfo));
|
||||
|
||||
inputInitialized = true;
|
||||
}
|
||||
|
||||
void TBXR_SyncActions( void )
|
||||
{
|
||||
// sync action data
|
||||
XrActiveActionSet activeActionSet = {};
|
||||
activeActionSet.actionSet = runningActionSet;
|
||||
activeActionSet.subactionPath = XR_NULL_PATH;
|
||||
|
||||
XrActionsSyncInfo syncInfo = {};
|
||||
syncInfo.type = XR_TYPE_ACTIONS_SYNC_INFO;
|
||||
syncInfo.next = NULL;
|
||||
syncInfo.countActiveActionSets = 1;
|
||||
syncInfo.activeActionSets = &activeActionSet;
|
||||
OXR(xrSyncActions(gAppState.Session, &syncInfo));
|
||||
|
||||
// query input action states
|
||||
XrActionStateGetInfo getInfo = {};
|
||||
getInfo.type = XR_TYPE_ACTION_STATE_GET_INFO;
|
||||
getInfo.next = NULL;
|
||||
getInfo.subactionPath = XR_NULL_PATH;
|
||||
}
|
||||
|
||||
void TBXR_UpdateControllers( )
|
||||
{
|
||||
TBXR_SyncActions();
|
||||
|
||||
//get controller poses
|
||||
XrAction controller[] = {handPoseLeftAction, handPoseRightAction};
|
||||
XrPath subactionPath[] = {leftHandPath, rightHandPath};
|
||||
XrSpace controllerSpace[] = {leftControllerAimSpace, rightControllerAimSpace};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (ActionPoseIsActive(controller[i], subactionPath[i])) {
|
||||
XrSpaceVelocity vel = {};
|
||||
vel.type = XR_TYPE_SPACE_VELOCITY;
|
||||
XrSpaceLocation loc = {};
|
||||
loc.type = XR_TYPE_SPACE_LOCATION;
|
||||
loc.next = &vel;
|
||||
OXR(xrLocateSpace(controllerSpace[i], gAppState.CurrentSpace, gAppState.FrameState.predictedDisplayTime, &loc));
|
||||
|
||||
gAppState.TrackedController[i].Active = (loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) != 0;
|
||||
gAppState.TrackedController[i].Pose = loc.pose;
|
||||
gAppState.TrackedController[i].Velocity = vel;
|
||||
} else {
|
||||
ovrTrackedController_Clear(&gAppState.TrackedController[i]);
|
||||
}
|
||||
}
|
||||
|
||||
leftRemoteTracking_new = gAppState.TrackedController[0];
|
||||
rightRemoteTracking_new = gAppState.TrackedController[1];
|
||||
|
||||
|
||||
memset(&leftTrackedRemoteState_new, 0, sizeof leftTrackedRemoteState_new);
|
||||
memset(&rightTrackedRemoteState_new, 0, sizeof rightTrackedRemoteState_new);
|
||||
|
||||
//button mapping
|
||||
if (GetActionStateBoolean(menuAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Enter;
|
||||
if (GetActionStateBoolean(buttonXAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_X;
|
||||
if (GetActionStateBoolean(buttonYAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Y;
|
||||
leftTrackedRemoteState_new.GripTrigger = GetActionStateFloat(gripLeftAction).currentState;
|
||||
if (leftTrackedRemoteState_new.GripTrigger > 0.5f) leftTrackedRemoteState_new.Buttons |= xrButton_GripTrigger;
|
||||
if (GetActionStateBoolean(thumbstickLeftClickAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_LThumb;
|
||||
|
||||
if (GetActionStateBoolean(buttonAAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_A;
|
||||
if (GetActionStateBoolean(buttonBAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_B;
|
||||
rightTrackedRemoteState_new.GripTrigger = GetActionStateFloat(gripRightAction).currentState;
|
||||
if (rightTrackedRemoteState_new.GripTrigger > 0.5f) rightTrackedRemoteState_new.Buttons |= xrButton_GripTrigger;
|
||||
if (GetActionStateBoolean(thumbstickRightClickAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_RThumb;
|
||||
|
||||
//index finger click
|
||||
if (GetActionStateBoolean(indexLeftAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Trigger;
|
||||
if (GetActionStateBoolean(indexRightAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_Trigger;
|
||||
|
||||
//thumbstick
|
||||
XrActionStateVector2f moveJoystickState;
|
||||
moveJoystickState = GetActionStateVector2(moveOnLeftJoystickAction);
|
||||
leftTrackedRemoteState_new.Joystick.x = moveJoystickState.currentState.x;
|
||||
leftTrackedRemoteState_new.Joystick.y = moveJoystickState.currentState.y;
|
||||
|
||||
moveJoystickState = GetActionStateVector2(moveOnRightJoystickAction);
|
||||
rightTrackedRemoteState_new.Joystick.x = moveJoystickState.currentState.x;
|
||||
rightTrackedRemoteState_new.Joystick.y = moveJoystickState.currentState.y;
|
||||
}
|
||||
|
||||
//0 = left, 1 = right
|
||||
float vibration_channel_duration[2] = {0.0f, 0.0f};
|
||||
float vibration_channel_intensity[2] = {0.0f, 0.0f};
|
||||
|
||||
void TBXR_Vibrate( int duration, int chan, float intensity )
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if ((i + 1) & chan)
|
||||
{
|
||||
if (vibration_channel_duration[i] > 0.0f)
|
||||
return;
|
||||
|
||||
if (vibration_channel_duration[i] == -1.0f && duration != 0.0f)
|
||||
return;
|
||||
|
||||
vibration_channel_duration[i] = duration;
|
||||
vibration_channel_intensity[i] = intensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TBXR_ProcessHaptics() {
|
||||
static float lastFrameTime = 0.0f;
|
||||
float timestamp = (float)(TBXR_GetTimeInMilliSeconds());
|
||||
float frametime = timestamp - lastFrameTime;
|
||||
lastFrameTime = timestamp;
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (vibration_channel_duration[i] > 0.0f ||
|
||||
vibration_channel_duration[i] == -1.0f) {
|
||||
|
||||
// fire haptics using output action
|
||||
XrHapticVibration vibration = {};
|
||||
vibration.type = XR_TYPE_HAPTIC_VIBRATION;
|
||||
vibration.next = NULL;
|
||||
vibration.amplitude = vibration_channel_intensity[i];
|
||||
vibration.duration = ToXrTime(vibration_channel_duration[i]);
|
||||
vibration.frequency = 3000;
|
||||
XrHapticActionInfo hapticActionInfo = {};
|
||||
hapticActionInfo.type = XR_TYPE_HAPTIC_ACTION_INFO;
|
||||
hapticActionInfo.next = NULL;
|
||||
hapticActionInfo.action = i == 0 ? vibrateLeftFeedback : vibrateRightFeedback;
|
||||
OXR(xrApplyHapticFeedback(gAppState.Session, &hapticActionInfo, (const XrHapticBaseHeader*)&vibration));
|
||||
|
||||
if (vibration_channel_duration[i] != -1.0f) {
|
||||
vibration_channel_duration[i] -= frametime;
|
||||
|
||||
if (vibration_channel_duration[i] < 0.0f) {
|
||||
vibration_channel_duration[i] = 0.0f;
|
||||
vibration_channel_intensity[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Stop haptics
|
||||
XrHapticActionInfo hapticActionInfo = {};
|
||||
hapticActionInfo.type = XR_TYPE_HAPTIC_ACTION_INFO;
|
||||
hapticActionInfo.next = NULL;
|
||||
hapticActionInfo.action = i == 0 ? vibrateLeftFeedback : vibrateRightFeedback;
|
||||
OXR(xrStopHapticFeedback(gAppState.Session, &hapticActionInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -55,11 +55,16 @@ typedef enum xrButton_ {
|
|||
xrButton_GripTrigger = 0x04000000,
|
||||
xrButton_Trigger = 0x20000000,
|
||||
xrButton_Joystick = 0x80000000,
|
||||
|
||||
//Define additional controller touch points (not button presses)
|
||||
xrButton_ThumbRest = 0x00000010,
|
||||
|
||||
xrButton_EnumSize = 0x7fffffff
|
||||
} xrButton;
|
||||
|
||||
typedef struct {
|
||||
uint32_t Buttons;
|
||||
uint32_t Touches;
|
||||
float IndexTrigger;
|
||||
float GripTrigger;
|
||||
XrVector2f Joystick;
|
||||
|
|
Loading…
Reference in a new issue