FOSVRInputDevice::~FOSVRInputDevice() { FScopeLock lock(contextMutex); IModularFeatures::Get().UnregisterModularFeature(GetModularFeatureName(), this); if (context) { if (leftHand) { osvrClientFreeInterface(context, leftHand); } if (rightHand) { osvrClientFreeInterface(context, rightHand); } for (auto iface : interfaces) { if (iface.Value) { osvrClientFreeInterface(context, iface.Value); } } } }
FOculusInput::FOculusInput( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler ) : MessageHandler( InMessageHandler ) , ControllerPairs() , TriggerThreshold(0.8f) { // Initializes LibOVR. ovrInitParams initParams; FMemory::Memset(initParams, 0); initParams.Flags = ovrInit_RequestVersion; initParams.RequestedMinorVersion = OVR_MINOR_VERSION; #if !UE_BUILD_SHIPPING // initParams.LogCallback = OvrLogCallback; #endif ovrResult initStatus = ovr_Initialize(&initParams); if (!OVR_SUCCESS(initStatus) && initStatus == ovrError_LibLoad) { // fatal errors: can't load library UE_LOG(LogOcInput, Log, TEXT("Can't find Oculus library %s: is proper Runtime installed? Version: %s"), TEXT(OVR_FILE_DESCRIPTION_STRING), TEXT(OVR_VERSION_STRING)); return; } FOculusTouchControllerPair& ControllerPair = *new(ControllerPairs) FOculusTouchControllerPair(); // @todo: Unreal controller index should be assigned to us by the engine to ensure we don't contest with other devices ControllerPair.UnrealControllerIndex = 0; //???? NextUnrealControllerIndex++; // Load the config, even if we failed to initialize a controller LoadConfig(); IModularFeatures::Get().RegisterModularFeature( GetModularFeatureName(), this ); GEngine->MotionControllerDevices.AddUnique(this); // Register the FKeys EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_Thumbstick, LOCTEXT("OculusTouch_Left_Thumbstick", "Oculus Touch (L) Thumbstick CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_FaceButton1, LOCTEXT("OculusTouch_Left_FaceButton1", "Oculus Touch (L) X Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_Trigger, LOCTEXT("OculusTouch_Left_Trigger", "Oculus Touch (L) Trigger CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_FaceButton2, LOCTEXT("OculusTouch_Left_FaceButton2", "Oculus Touch (L) Y Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_IndexPointing, LOCTEXT("OculusTouch_Left_IndexPointing", "Oculus Touch (L) Pointing CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Left_ThumbUp, LOCTEXT("OculusTouch_Left_ThumbUp", "Oculus Touch (L) Thumb Up CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_Thumbstick, LOCTEXT("OculusTouch_Right_Thumbstick", "Oculus Touch (R) Thumbstick CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_FaceButton1, LOCTEXT("OculusTouch_Right_FaceButton1", "Oculus Touch (R) A Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_Trigger, LOCTEXT("OculusTouch_Right_Trigger", "Oculus Touch (R) Trigger CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_FaceButton2, LOCTEXT("OculusTouch_Right_FaceButton2", "Oculus Touch (R) B Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_IndexPointing, LOCTEXT("OculusTouch_Right_IndexPointing", "Oculus Touch (R) Pointing CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(FOculusTouchCapacitiveKey::OculusTouch_Right_ThumbUp, LOCTEXT("OculusTouch_Right_ThumbUp", "Oculus Touch (R) Thumb Up CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis)); UE_LOG(LogOcInput, Log, TEXT("OculusInput is initialized. Init status %d. Runtime version: %s"), int(initStatus), *FString(ANSI_TO_TCHAR(ovr_GetVersionString()))); }
FOculusInput::FOculusInput( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler ) : MessageHandler( InMessageHandler ) , ControllerPairs() { PreInit(); // @TODO: call it sooner to avoid 'Warning InputKey Event specifies invalid' when loading a map using the custom keys // take care of backward compatibility of Remote with Gamepad if (bRemoteKeysMappedToGamepad) { Remote.ReinitButtonsForGamepadCompat(); } // Only initialize plug-in when not running a dedicated server, and Oculus service is running if(!IsRunningDedicatedServer() && ovr_Detect(0).IsOculusServiceRunning) { // Initializes LibOVR. ovrInitParams initParams; FMemory::Memset(initParams, 0); initParams.Flags = ovrInit_RequestVersion; initParams.RequestedMinorVersion = OVR_MINOR_VERSION; #if !UE_BUILD_SHIPPING // initParams.LogCallback = OvrLogCallback; #endif ovrResult initStatus = ovr_Initialize(&initParams); if (!OVR_SUCCESS(initStatus) && initStatus == ovrError_LibLoad) { // fatal errors: can't load library UE_LOG(LogOcInput, Log, TEXT("Can't find Oculus library %s: is proper Runtime installed? Version: %s"), TEXT(OVR_FILE_DESCRIPTION_STRING), TEXT(OVR_VERSION_STRING)); return; } FOculusTouchControllerPair& ControllerPair = *new(ControllerPairs) FOculusTouchControllerPair(); // @todo: Unreal controller index should be assigned to us by the engine to ensure we don't contest with other devices ControllerPair.UnrealControllerIndex = 0; //???? NextUnrealControllerIndex++; IModularFeatures::Get().RegisterModularFeature( GetModularFeatureName(), this ); GEngine->MotionControllerDevices.AddUnique(this); UE_LOG(LogOcInput, Log, TEXT("OculusInput is initialized. Init status %d. Runtime version: %s"), int(initStatus), *FString(ANSI_TO_TCHAR(ovr_GetVersionString()))); } }
FOSVRInputDevice::FOSVRInputDevice( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler, TSharedPtr<OSVREntryPoint, ESPMode::ThreadSafe> osvrEntryPoint, TSharedPtr<FOSVRHMD, ESPMode::ThreadSafe> osvrHMD) : mOSVREntryPoint(osvrEntryPoint), mOSVRHMD(osvrHMD), MessageHandler(InMessageHandler) { // make sure OSVR module is loaded. contextMutex = mOSVREntryPoint->GetClientContextMutex(); FScopeLock lock(contextMutex); context = mOSVREntryPoint->GetClientContext(); bContextValid = context && osvrClientCheckStatus(context) == OSVR_RETURN_SUCCESS; if (bContextValid) { const float defaultThreshold = 0.25f; TSharedPtr<OSVRButton> buttons[] = { // left hand MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::SpecialLeft, "/controller/left/middle")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_Shoulder, "/controller/left/bumper")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_Thumbstick, "/controller/left/joystick/button")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton1, "/controller/left/1")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton2, "/controller/left/2")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton3, "/controller/left/3")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton4, "/controller/left/4")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Left_Thumbstick_X, "/controller/left/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Right, "/controller/left/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Left, "/controller/left/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Left_Thumbstick_Y, "/controller/left/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Up, "/controller/left/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Down, "/controller/left/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Left_TriggerAxis, "/controller/left/trigger")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::MotionController_Left_Trigger, "/controller/left/trigger")), // right hand MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::SpecialRight, "/controller/right/middle")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_Shoulder, "/controller/right/bumper")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_Thumbstick, "/controller/right/joystick/button")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton1, "/controller/right/1")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton2, "/controller/right/2")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton3, "/controller/right/3")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton4, "/controller/right/4")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Right_Thumbstick_X, "/controller/right/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Right, "/controller/right/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Left, "/controller/right/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Right_Thumbstick_Y, "/controller/right/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Up, "/controller/right/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Down, "/controller/right/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Right_TriggerAxis, "/controller/right/trigger")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::MotionController_Right_Trigger, "/controller/right/trigger")), // "controller" (like xbox360) MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::RightShoulder, "/controller/right/bumper")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::RightThumb, "/controller/right/joystick/button")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonBottom, "/controller/right/1")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonRight, "/controller/right/2")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonLeft, "/controller/right/3")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonTop, "/controller/right/4")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::LeftShoulder, "/controller/left/bumper")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::LeftThumb, "/controller/left/joystick/button")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadDown, "/controller/left/1")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadRight, "/controller/left/2")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadLeft, "/controller/left/3")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadUp, "/controller/left/4")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::LeftAnalogX, "/controller/left/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::LeftStickRight, "/controller/left/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::LeftStickLeft, "/controller/left/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::LeftAnalogY, "/controller/left/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::LeftStickUp, "/controller/left/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::LeftStickDown, "/controller/left/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::RightAnalogX, "/controller/right/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::RightStickRight, "/controller/right/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::RightStickLeft, "/controller/right/joystick/x")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::RightAnalogY, "/controller/right/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::RightStickUp, "/controller/right/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::RightStickDown, "/controller/right/joystick/y")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::LeftTriggerAnalog, "/controller/left/trigger")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::RightTriggerAnalog, "/controller/right/trigger")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::LeftTriggerThreshold, "/controller/left/trigger")), MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::RightTriggerThreshold, "/controller/right/trigger")), }; osvrButtons.Append(buttons, ARRAY_COUNT(buttons)); for (auto& button : osvrButtons) { auto ifaceItr = interfaces.Find(button->ifacePath); OSVR_ClientInterface iface = nullptr; if (!ifaceItr) { if (osvrClientGetInterface(context, TCHAR_TO_ANSI(*(button->ifacePath)), &iface) != OSVR_RETURN_SUCCESS) { button->bIsValid = false; } else { interfaces.Add(button->ifacePath, iface); } } else { iface = *ifaceItr; } if (button->bIsValid) { if (button->type == OSVR_BUTTON_TYPE_DIGITAL) { if (osvrRegisterButtonCallback(iface, buttonCallback, button.Get()) == OSVR_RETURN_FAILURE) { button->bIsValid = false; } } if (button->type == OSVR_BUTTON_TYPE_ANALOG || button->type == OSVR_BUTTON_TYPE_THRESHOLD) { if (osvrRegisterAnalogCallback(iface, analogCallback, button.Get()) == OSVR_RETURN_FAILURE) { button->bIsValid = false; } } } } bLeftHandValid = osvrClientGetInterface(context, "/me/hands/left", &leftHand) == OSVR_RETURN_SUCCESS; bRightHandValid = osvrClientGetInterface(context, "/me/hands/right", &rightHand) == OSVR_RETURN_SUCCESS; IModularFeatures::Get().RegisterModularFeature(GetModularFeatureName(), this); #if !OSVR_UNREAL_4_12 // This may need to be removed in a future version of the engine. // From the SteamVR plugin: "construction of the controller happens after InitializeMotionControllers(), so we manually add this to the array here" GEngine->MotionControllerDevices.AddUnique(this); #endif } }
/* * We override this so we can init the keys before the blueprints are compiled on editor startup * if we do not do this here we will get warnings in blueprints. */ virtual void StartupModule() override { IModularFeatures::Get().RegisterModularFeature(GetModularFeatureName(), this); UE_LOG(LogVRPNInputDevice, Log, TEXT("Locating VRPN config file.")); FString ConfigFile; if(!FParse::Value(FCommandLine::Get(), TEXT("VRPNConfigFile="), ConfigFile)) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Could not find VRPN configuration file: %s."), *ConfigFile); return; } if(!FPaths::FileExists(ConfigFile)) { return; UE_LOG(LogVRPNInputDevice, Warning, TEXT("Could not find VRPN configuration file: %s."), *ConfigFile); } FString EnabledDevices; TArray<FString> EnabledDevicesArray; FParse::Value(FCommandLine::Get(), TEXT("VRPNEnabledDevices="), EnabledDevices); EnabledDevices.ParseIntoArray(EnabledDevicesArray, TEXT(","), false); TArray<FString> SectionNames; GConfig->GetSectionNames(ConfigFile,SectionNames); for(FString &SectionNameString : SectionNames) { // Tracker name is the section name itself FConfigSection* TrackerConfig = GConfig->GetSectionPrivate(*SectionNameString, false, true, ConfigFile); FString *TrackerTypeString = TrackerConfig->Find(FName(TEXT("Type"))); if(TrackerTypeString == nullptr) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Tracker config file %s: expected to find Type of type String in section [%s]. Skipping this section."), *ConfigFile, *SectionNameString); continue; } FString *TrackerAdressString = TrackerConfig->Find(FName(TEXT("Address"))); if(TrackerAdressString == nullptr) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Tracker config file %s: expected to find Address of type String in section [%s]. Skipping this section."), *ConfigFile, *SectionNameString); continue; } IVRPNInputDevice *InputDevice = nullptr; bool bEnabled = EnabledDevicesArray.Num() == 0 ||EnabledDevicesArray.Contains(SectionNameString); if(TrackerTypeString->Compare("Tracker") == 0) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Creating VRPNTrackerInputDevice %s on adress %s."), *SectionNameString, *(*TrackerAdressString)); InputDevice = new VRPNTrackerInputDevice(*TrackerAdressString, bEnabled); } else if(TrackerTypeString->Compare("Button") == 0) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Creating VRPNButtonInputDevice %s on adress %s."), *SectionNameString, *(*TrackerAdressString)); InputDevice = new VRPNButtonInputDevice(*TrackerAdressString, bEnabled); } else { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Tracker config file %s: Type should be Tracker or Button but found %s in section %s. Skipping this section."), *ConfigFile, *(*TrackerTypeString), *SectionNameString); continue; } if(!InputDevice->ParseConfig(TrackerConfig)) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Tracker config file %s: Could not parse config %s.."), *ConfigFile, *SectionNameString); continue; } if(!DeviceManager.IsValid()) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Create VRPN Input Manager.")); DeviceManager = TSharedPtr< FVRPNInputDeviceManager >(new FVRPNInputDeviceManager()); } DeviceManager->AddInputDevice(InputDevice); } }
bool VRPNTrackerInputDevice::ParseConfig(FConfigSection *InConfigSection) { const FString* RotationOffsetString = InConfigSection->Find(FName(TEXT("RotationOffset"))); FVector RotationOffsetVector; float RotationOffsetAngleDegrees; if(RotationOffsetString == nullptr || !RotationOffsetVector.InitFromString(*RotationOffsetString) || !FParse::Value(*(*RotationOffsetString), TEXT("Angle="), RotationOffsetAngleDegrees)) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Expected RotationOffsetAxis of type FVector and RotationOffsetAnlge of type Float when parsing tracker device. Rotation offset will be the indenty transform.")); RotationOffset = FQuat::Identity; } else { RotationOffsetVector.Normalize(); RotationOffset = FQuat(RotationOffsetVector, FMath::DegreesToRadians(RotationOffsetAngleDegrees)); RotationOffset.Normalize(); } const FString* PositioOffsetString = InConfigSection->Find(FName(TEXT("PositionOffset"))); if(PositioOffsetString == nullptr || !TranslationOffset.InitFromString(*PositioOffsetString)) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Expected PositionOffset of type FVector (in device coordinates). Will use default of (0,0,0).")); TranslationOffset.Set(0, 0, 0); } FString *TrackerUnitsToUE4UnitsText = InConfigSection->Find(FName(TEXT("TrackerUnitsToUE4Units"))); if(TrackerUnitsToUE4UnitsText == nullptr) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Expected to find TrackerUnitsToUE4UnitsText of type Float. Using default of 1.0f")); TrackerUnitsToUE4Units = 1.0f; } else { TrackerUnitsToUE4Units = FCString::Atof(*(*TrackerUnitsToUE4UnitsText)); } FString *FlipZAxisText = InConfigSection->Find(FName(TEXT("FlipZAxis"))); if(FlipZAxisText == nullptr) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Expected to find FlipZAxis of type Boolean. Using default of false.")); FlipZAxis = false; } else { FlipZAxis = FCString::ToBool(*(*FlipZAxisText)); } TArray<const FString*> Trackers; InConfigSection->MultiFindPointer(FName(TEXT("Tracker")), Trackers); if(Trackers.Num() == 0) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Config file for tracker device has no tracker mappings specified. Expeted field Tracker.")); return false; } bool bHasMotionControllers = false; for(const FString* TrackerString: Trackers) { int32 TrackerId; FString TrackerName; FString TrackerDescription; if(!FParse::Value(*(*TrackerString), TEXT("Id="), TrackerId) || !FParse::Value(*(*TrackerString), TEXT("Name="), TrackerName) || !FParse::Value(*(*TrackerString), TEXT("Description="), TrackerDescription)) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Config not parse tracker. Expected: Tracker = (Id=#,Name=String,Description=String).")); continue; } // see if this is a motion controller int PlayerId = -1; FParse::Value(*(*TrackerString), TEXT("PlayerId="), PlayerId); EControllerHand Hand = EControllerHand::Left; if(PlayerId >= 0) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Found motion controller.")); bHasMotionControllers = true; FString HandString; if(FParse::Value(*(*TrackerString), TEXT("Hand="), HandString)) { if(HandString.Equals("Right")) { Hand = EControllerHand::Right; } } } UE_LOG(LogVRPNInputDevice, Log, TEXT("Adding new tracker: [%i,%s,%s,%i]."), TrackerId, *TrackerName, *TrackerDescription, PlayerId); const TrackerInput &Input = TrackerMap.Add(TrackerId, {FKey(*(TrackerName + "MotionX")), FKey(*(TrackerName + "MotionY")), FKey(*(TrackerName + "MotionZ")), FKey(*(TrackerName + "RotationYaw")), FKey(*(TrackerName + "RotationPitch")), FKey(*(TrackerName + "RotationRoll")), FVector(0), FQuat(EForceInit::ForceInit), PlayerId, Hand,false}); // Translation EKeys::AddKey(FKeyDetails(Input.MotionXKey, FText::FromString(TrackerName + " X position"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.MotionYKey, FText::FromString(TrackerName + " Y position"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.MotionZKey, FText::FromString(TrackerName + " Z position"), FKeyDetails::FloatAxis)); // Rotation EKeys::AddKey(FKeyDetails(Input.RotationYawKey, FText::FromString(TrackerName + " Yaw"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.RotationPitchKey, FText::FromString(TrackerName + " Pitch"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.RotationRollKey, FText::FromString(TrackerName + " Roll"), FKeyDetails::FloatAxis)); } if(bHasMotionControllers) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Adding this to the motion controller devices.")); IModularFeatures::Get().RegisterModularFeature(GetModularFeatureName(), this); } return true; }
FOculusInput::~FOculusInput() { IModularFeatures::Get().UnregisterModularFeature( GetModularFeatureName(), this ); ovr_Shutdown(); }