Created
November 22, 2020 18:19
-
-
Save Rectus/9cc3ae996df5b4549a287a37af260674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SteamVRUtils.h" | |
#define INPUT_PATH_CONTROLLER_LEFT "/user/hand/left" | |
#define INPUT_PATH_CONTROLLER_RIGHT "/user/hand/right" | |
#define INPUT_PATH_HMD "/user/head" | |
using namespace vr; | |
FName USteamVRUtils::GetSteamVR_OriginTrackedDeviceMotionSource(FSteamVRAction SteamVRAction) | |
{ | |
if (VRSystem() && VRInput()) | |
{ | |
InputOriginInfo_t OriginInfo = {}; | |
EVRInputError Err = VRInput()->GetOriginTrackedDeviceInfo(SteamVRAction.ActiveOrigin, &OriginInfo, sizeof(OriginInfo)); | |
if (Err == VRInputError_None && OriginInfo.trackedDeviceIndex != k_unTrackedDeviceIndexInvalid) | |
{ | |
if (leftHandle == k_ulInvalidInputValueHandle) | |
{ | |
VRInput()->GetInputSourceHandle(INPUT_PATH_CONTROLLER_LEFT, &leftHandle); | |
} | |
if (rightHandle == k_ulInvalidInputValueHandle) | |
{ | |
VRInput()->GetInputSourceHandle(INPUT_PATH_CONTROLLER_RIGHT, &rightHandle); | |
} | |
if (hmdHandle == k_ulInvalidInputValueHandle) | |
{ | |
VRInput()->GetInputSourceHandle(INPUT_PATH_HMD, &hmdHandle); | |
} | |
if(OriginInfo.devicePath == k_ulInvalidInputValueHandle) | |
{ | |
UE_LOG(LogTemp, Warning, TEXT("Invalid device path received for Tracked Device Origin [%s]"), *SteamVRAction.Path); | |
} | |
else if (OriginInfo.devicePath == leftHandle) | |
{ | |
return FXRMotionControllerBase::LeftHandSourceId; | |
} | |
else if (OriginInfo.devicePath == rightHandle) | |
{ | |
return FXRMotionControllerBase::RightHandSourceId; | |
} | |
else if (OriginInfo.devicePath == hmdHandle) | |
{ | |
return FXRMotionControllerBase::HMDSourceId; | |
} | |
else | |
{ | |
UE_LOG(LogTemp, Warning, TEXT("No Motion Source found for action [%s]"), *SteamVRAction.Path); | |
} | |
} | |
else | |
{ | |
UE_LOG(LogTemp, Warning, TEXT("Error [%i] trying to retrieve Tracked Device Info or an invalid device was returned for Action [%s]"), (int)Err, *SteamVRAction.Path); | |
} | |
} | |
return ""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "openvr.h" | |
#include "Kismet/BlueprintFunctionLibrary.h" | |
#include "SteamVRInputDeviceFunctionLibrary.h" | |
#include "Object.h" | |
#include "XRMotionControllerBase.h" | |
#include "SteamVRUtils.generated.h" | |
UCLASS() | |
class PROJECT_API USteamVRUtils : public UBlueprintFunctionLibrary | |
{ | |
GENERATED_BODY() | |
public: | |
/** | |
* Returns the motion source of the device that caused the action. | |
* The returned format is compatible with the motion source in the MotionControllerComponent. | |
* @param SteamVRAction - The action that's the source of the input | |
* @return MotionSource - The hand or head that caused the action | |
*/ | |
UFUNCTION(BlueprintCallable, Category = "SteamVR Input") | |
UPARAM(DisplayName = "MotionSource") FName GetSteamVR_OriginTrackedDeviceMotionSource(FSteamVRAction SteamVRAction); | |
private: | |
VRInputValueHandle_t leftHandle = vr::k_ulInvalidInputValueHandle; | |
VRInputValueHandle_t rightHandle = vr::k_ulInvalidInputValueHandle; | |
VRInputValueHandle_t hmdHandle = vr::k_ulInvalidInputValueHandle; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment