You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3012064 on 2016/06/13 by Nick.Whiting
Merging Main -> DevVR
Change 3048060 on 2016/07/13 by Nick.Whiting
Integrating CL 3045721 from //depot/Partners/Google/AndroidVR-DevVR
Upgrade Android and iOS GVR SDK to the latest.
Fix the flipped vignette issue when using Unreal's post processing distortion.
Change the Daydream & Cardboard mode to use scanline racing.
Deprecate the ability to turn off individual UI elements.
Change 3235307 on 2016/12/14 by Keli.Hlodversson
Filter out excluded HMD modules during FEngineLoop:PreInitHMDDevice. The final selection still happens in UEngine::InitializeHMDDevice as all HMD plugins have not been loaded during PreInit
Change 3235308 on 2016/12/14 by Ryan.Vance
#jira UEVR-478
Monoscopic far field improvements
Shader changes are now gated behind the read only cvar vr.MonoscopicFarField. Changing this requires a shader compile.
Moved the mono rendering mode to the cvar vr.MonoscopicFarFieldMode. This is writable, so users can enable/disable mono rendering on the fly if the above cvar is enabled.
Only write to the alpha channel in the mobile base pass if the object is opaque and MONOSCOPIC_FAR_FIELD is defined.
Addressed code review comments.
Change 3235397 on 2016/12/14 by Keli.Hlodversson
[Oculus] Only enable GearVR platform on Windows if Oculus service is running
Original author: Loren.McQuade
Change 3235762 on 2016/12/14 by Keli.Hlodversson
Add explicit parentheses to placate the build bots.
Change 3242318 on 2016/12/21 by Ryan.Vance
Working around pixel density crash.
Change 3242522 on 2016/12/21 by Ryan.Vance
Missing flag clear so our adaptive test was always returning true.
Change 3243173 on 2016/12/22 by Ryan.Vance
Integrating post present callback implementation from 4.14.1
Change 3248633 on 2017/01/05 by Keli.Hlodversson
Copying //Tasks/UE4/Dev-VR-Refactoring to Dev-VR-Minimal (//UE4/Dev-VR-Minimal)
Change 3248723 on 2017/01/05 by Keli.Hlodversson
Fix after merge. EnablePositionalTracking no longer exists.
Change 3249484 on 2017/01/06 by Keli.Hlodversson
Add missing includes
Change 3249714 on 2017/01/06 by Keli.Hlodversson
Remove monolithic header include
Change 3249980 on 2017/01/06 by Keli.Hlodversson
SteamVR: Remove leftover unused WindowMirrorMode member variable
Change 3252432 on 2017/01/10 by Keli.Hlodversson
Submitting change by Loren McQuade to fix monolithic builds.
Unshelved from pending changelist '3251436':
Change 3257373 on 2017/01/13 by Keli.Hlodversson
#jira UEVR-411: Finish renaming/removing/remodelling the remaining Oculus (Rift+GearVR) commands
#jira UEVR-412: Rename and merge remaining Morpheus console commands
#jira UEVR-417: Remove Exec from IHeadMountedDisplay
Change 3269971 on 2017/01/24 by Jeff.Fisher
UEVR-498 move controller is missing world to meters
UEVR-522 PS4 motion controller worldscale support.
-Passing world to meters scale into getControllerOrientationAndPosition because the thing asking about it ought to be part of a world, and know what it should be. This also avoids making PS4 motion controllers dependent on the HMD. Note Google VR Controller doesn't do position, so doesnt' care about scale. Oculus already had internal threadsafe tracking of world scale, so I left that. Steam handles world scale below our input level.
-Also adding PlayerIndex member to FSceneView so we can figure out which view the MotionControllerComponent should get its worldscale from for the late render thread update.
#jira UEVR-498
#review-3384107
Change 3288308 on 2017/02/06 by Jeff.Fisher
UEVR-517 Detect MotionController Connectivity
-PS4 can only track 2 controllers and 1 hmd. Support for dealing with that is needed.
-Also need to support multiple motion controller components mapped to a single controller. Licencees have done that before.
-Created a new interface IMotionTrackingSystemManagement, and implements it for PS4Tracker on PS4.
-Created a MotionTrackedDeviceFunctionLibrary to expose that interface to blueprint.
-With those one can enable and disable tracking on ps4 controllers and query their state to stay within the controller tracking limit.
-PS4Tracker also keeps a blackboard of the enable/disable state so that one can enable or disable controllers that have not been connected yet, and have them enable tracking or not when they are connected.
-DS4 controller no longer jumps back to 000 if it loses tracking.
#review-3384107
#jira UEVR-517
Change 3288309 on 2017/02/06 by Keli.Hlodversson
Add file missing from CL#3257373.
Change 3288311 on 2017/02/06 by Jeff.Fisher
UEVR-517 Detect MotionController Connectivity - Test content.
-tm-motionControllers has a third mode where all playstation motion controllers for player 0 are availalbe. You can toggle them to track or not with ctrl-P,G,L,R for pad, gun, leftmove, rightmove or with alt-P,G,L,R. Ctrl tests doing so via MotionControllerComponent. Alt tests doing so by player index and controller type enum.
-ctrl-A disables tracking of all controllers
-alt-A disables tracking of all controllers for player 0
-ctrl-D toggles enabling new controllers by default
-Also fixed one button not working in one of the other test modes for the Aim (gun) controller.
-The controller 'models' have an arrow out the front. It is black if disabled. Red if enabled, but no tracker is active, yellow if tracked but inertial only, and green if fully tracked by the camera.
-This logic is in the QA_MoCoAll blueprint.
Change 3291601 on 2017/02/07 by Jeff.Fisher
UEVR-536 PSVR motion controller tracking problem with multiple controllers
-Previous code called GetRelativeTransform from the render thread, but the game thread could update it at any time. This caches that transform so that it can be safely used in the render thread.
#jira UEVR-536
#review-3384107 @Ryan.Vance
Change 3292460 on 2017/02/08 by Jeff.Fisher
PS4 sceVrTrackerGetResult() error warning logging improved, and explanatory comment added.
Change 3308771 on 2017/02/17 by Keli.Hlodversson
Rename GoogleVR console commands
#jira UEVR-412
Change 3309156 on 2017/02/17 by Keli.Hlodversson
Track changes in r.ScreenPercentage on GoogleVR and set RenderTargetSize accordingly.
Change 3311999 on 2017/02/20 by Keli.Hlodversson
Create a default implementation for RecordAnalytics.
Also create an initial stub for FHeadMountedDisplayBase for future default implementations of common HMD functionality.
Make implementing IHeadMountedDisplay::GetDeviceName mandatory instead of defaulting to "Unknown"
#jira UE-21878
#jira UEVR-213
Change 3313467 on 2017/02/20 by Ryan.Vance
#jira UE-41604
3278583
pCustomPresent->AllocateRenderTargetTexture may return false, if we blindly return true we can end up with an invalid render target since the fall back sceneviewport will be skipped.
3278536
Adding ovrError_NoHmd to our sanity check in OnStartGameFrame.
Change 3314002 on 2017/02/21 by Keli.Hlodversson
Fix compilation on PS4 and Linux
Change 3326722 on 2017/03/01 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
Integrating 4.15 from main.
Change 3327567 on 2017/03/01 by Jeff.Fisher
UEVR-588 Oculus crash on "stereo on" when the proximity sensor is not triggered.
Duplicating from Release-4.15 cl 3327481, 3327542
-Don't ovr_SubmitFrame when the layers need to be recreated. They stay dirty until rendering is unpaused.
#jira UEVR-588
#review-3384107
Change 3328098 on 2017/03/01 by Jeff.Fisher
4.15 merge fixes
-Fixed deprecated enum name function usage.
-Fixed world scale usage in GoogleVRController.
-Fixed compile break in PS4Tracker.
Change 3328271 on 2017/03/01 by Jeff.Fisher
2.15 merge
-restroging GoogleVRController::GetWorldToMetersScale... cause it is used everywhere.
Change 3328307 on 2017/03/01 by Jeff.Fisher
4.15 merge
-More googlevr worldscale fixes.
Change 3328312 on 2017/03/01 by Jeff.Fisher
4.15 merge
-removing 2 unused includes
Change 3330610 on 2017/03/02 by Jeff.Fisher
4.15 merge
-fixing linux build
Change 3333952 on 2017/03/06 by Keli.Hlodversson
Implement common stereo layer management base class and use it in SteamVR and PS4. Fixes an outstanding bug in SteamVR where texures are updated every frame regardles of whether the continous update flag is set or not.
#jira UEVR-628
#jira UE-42555
Change 3334961 on 2017/03/07 by Keli.Hlodversson
Add missing include to fix non-unity builds
Change 3336200 on 2017/03/07 by Keli.Hlodversson
Fix compilation issues. (https://ec-01.epicgames.net/commander/link/jobDetails/jobs/7568252?jobName=UE4+Dev-VR+-+CL+3334961+-+Nightly+Build&s=Jobs)
* Pre VS2015 compilers don't like mixing wide and unmarked strings in concatenation. Unfortunately LOCTEXT hides the call to the TEXT macro, completely hinding the prefix (which only gets added to the first fragment.)
* Switch apparently doesn't know how to format a size_t for analytics either.
Also: Typo in backwards compatibility command name alias
Change 3337347 on 2017/03/08 by Jeff.Fisher
UE-42631 Stereo off while prox sensor uncovered causes low framerate
-Setting maxfps appropriately on 'stereo on/off'.
#review-3384107
#jira UE-42631
Change 3338385 on 2017/03/08 by Ryan.Vance
r.DisableDistortion was only being used for the mobile renderer
Change 3342301 on 2017/03/10 by patrickr.donovan
Test updates to TM-VRSmoke.
Increased lightmap resolution on QA_MeshTypes meshes to improve readbility and reliablility of tests involving said asset.
Rebuilt lighting.
Change 3348133 on 2017/03/15 by Ryan.Vance
Moving mono cvars to scene rendering to avoid cross module references. There's not a good reason to have them in the hmd module anyway.
Change 3348836 on 2017/03/15 by Ryan.Vance
Direct multi-view support for gear vr
Monoscopic far field with multi-view (blit and direct) support for gear vr
Support for translucent objects on both sides of the mono clip plane (due to a sorting issue, objects that straddle the plane composite incorrectly)
Fixed missing discards/clears in the multi-view blit
Change 3348843 on 2017/03/15 by Ryan.Vance
Fixing color/depth target size mismatch when screen percentage scaling results in a size that isn't divisible by 16.
Change 3349276 on 2017/03/16 by Keli.Hlodversson
Fixing compile errors in GoogleVR after merge from main.
Change 3350932 on 2017/03/16 by Ryan.Vance
Re-enabling the gearvr plugin on windows.
Change 3351977 on 2017/03/17 by Jeff.Fisher
Fixing masked member variable.
Change 3352314 on 2017/03/17 by Ryan.Vance
We need to ensure that we don't select different lod levels for each eye.
Change 3352993 on 2017/03/17 by Nick.Whiting
Integrating CL 3345824 from Android-DevVR to Dev-VR. Support for device depth pass in SceneCaptureComponent2D
Change 3355185 on 2017/03/20 by Nick.Whiting
Added ability to disable the autoloading splash screen, which would prevent the hide splash screen node from ever working
Change 3355676 on 2017/03/20 by Nick.Whiting
PR #3384: [GNUX] SteamVR, OpenGL patch. (Contributed by yaakuro), with some minor modifications
Change 3357286 on 2017/03/21 by Jeff.Fisher
Fixing GenerateProjectFiles, looks like the .config. was removed from these references in main some time ago.
Change 3357435 on 2017/03/21 by Jeff.Fisher
Fixing editor build break, looks like a merge mistake.
Change 3359960 on 2017/03/23 by Keli.Hlodversson
Prevent potential crash when drawing tracking sensor location. Also only fetch HMD location once instead of once per tracking sensor.
Change 3361230 on 2017/03/23 by Jeff.Fisher
Fixing linux build opengl include problem... maybe.
Change 3361638 on 2017/03/23 by Jeff.Fisher
Another guess at fixing linux build.
Change 3364224 on 2017/03/24 by Keli.Hlodversson
Initial implementation of UEVR-576 - Base emulated layer implementation
#jira UEVR-668 - Base emulated layer implementation: Initial framework for overrideable default implementation
#jira UEVR-669 - Base emulated layer implementation: Face Locked Layers Support
#jira UEVR-670 - Base emulated layer implementation: Tracker Locked Layers Support
#jira UEVR-671 - Base emulated layer implementation: World Locked Layers Support
#jira UEVR-672 - Base emulated layer implementation: Add support for optionally rendering face locked layers into a separate layer
Change 3364242 on 2017/03/24 by Keli.Hlodversson
SteamVR layers do not support negatve Layer priorities
Change 3364263 on 2017/03/24 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
Monoscopicfarfieldrendering was just 'accept source', Ryan is going to look at fixing it up.
Change 3364472 on 2017/03/24 by Jeff.Fisher
Merge fix
Change 3364475 on 2017/03/24 by Jeff.Fisher
Fixing gearvr include.
Change 3364486 on 2017/03/24 by Jeff.Fisher
merge fix
Change 3364532 on 2017/03/24 by Ryan.Vance
pso update for mono rendering and stereo layers.
Change 3364599 on 2017/03/24 by Ryan.Vance
Oculus changes for SI1.12
Change 3365159 on 2017/03/26 by Jeff.Fisher
include fix
Change 3365182 on 2017/03/26 by Jeff.Fisher
include fix
Change 3366087 on 2017/03/27 by Ryan.Vance
Remaining files from Oculus changes for SI1.12 merge request.
Fixing a bug in OnlineSubsystem.
Temporarily changing the eye padding change to be a shader clear to work around a clear color binding issue.
Change 3366492 on 2017/03/27 by Ryan.Vance
#jira UE-43294
Moved the clear before we setup state for drawing the mirror window content. It was stomping over state after the pso changes.
Going to leave the shader clear in the rift prerender for clearing the eye padding for now.
Change 3366929 on 2017/03/27 by Ryan.Vance
Fixing compile error
Change 3368549 on 2017/03/28 by Jeff.Fisher
Merging Change: 3357998 from //UE4/Partner-Google-VR/Engine/... to Dev-VR
Upgrade Google VR Plugin to v1.3:
*Upgraded GVR NDK to 1.30.0
*Changed some BlueprintFunction to use BlueprintPure
*Add the missing bDaydream flag in UEDeployAndroid.cs
#review-3384107
Change 3368975 on 2017/03/28 by Ryan.Vance
CIS clean up
#jira UE-43428, UE-43429, UE-43426, UE-43427
Change 3369028 on 2017/03/28 by Ryan.Vance
This is not exacly 'correct', but it's at least what the code was trying to do.
Change 3370203 on 2017/03/29 by Ryan.Vance
Adding gear vr controller component support.
Change 3370918 on 2017/03/29 by Ryan.Vance
Merging 3370569 using Partner-Google-VR_to_DevVR
Change 3371030 on 2017/03/29 by Ryan.Vance
Fixing linux build errors
#jira UE-43426
Change 3371036 on 2017/03/29 by Ryan.Vance
Oculus 4.16 integration.
Not terribly happy with the use of std::string. They promised to clean this up for the next release.
Change 3373495 on 2017/03/30 by Jeff.Fisher
Merging from Dev-Main, in preparation for 4.16
Change 3373578 on 2017/03/30 by Jeff.Fisher
build break, one comma short
Change 3373870 on 2017/03/31 by Jeff.Fisher
Include order fix.
Change 3374001 on 2017/03/31 by Keli.Hlodversson
Use DefaultStereoLayers as base for Morpheus implementation.
#jira UEVR-709 #jira UE-42919
#rb: Jeff.Fisher
Change 3374004 on 2017/03/31 by Keli.Hlodversson
Fix rendering for the default Stereo Layers implementation on mobile.
Depth test was set to "Never" instead of "Always"
Destination texture on GLES is flipped on the Y axis, the coordinates are reversed in the shade when compiled on the relevant platforms.
Change 3375125 on 2017/03/31 by Jeff.Fisher
UE-43506 Ensure using VRPreview with GoogleVR
-Removed the ensure, there is code in there to handle that case, and it works.
#jira UE-43506
Change 3375294 on 2017/03/31 by nick.bullard
Resaving Plugin content to resovle "saved with empty engine version"
#jira UE-43537
Change 3375480 on 2017/03/31 by Jeff.Fisher
UEVR-9 PSVR: Social Screen Support
-Experimental social screen support for 4.16.
-This does the basics of driving output through the Aux port in the proper format for display on the mirror monitor.
-Only supports 30fps on the mirror monitor. 60fps will require the implementation of sony system dialogs to deal with incompatable system features (video streaming, remote play).
-There is a project setting in Morpheus, under experiemental bEnableSocialScreenSeparateMode. This must be set to true to use this feature. When it is false we avoid allocating the back buffers.
-MorpheusFunctionLibrary blueprints now have a node "SetSocialScreenMode" which can switch between SystemMirror (hardware supported mirroring), SeparateTest (alternates black and white), SeparateTexture (displays a texture, eg a render target, specified via blueprint), and SeparateMirror(puts the hmd render buffer on screen - which is both eyes, like a debug mode).
-Also finally updated the bEnabled flag in project settings to tell people it's only for PC.
#jira UEVR-9
#review-3384107
Change 3375540 on 2017/03/31 by Ryan.Vance
#jira UE-43504
Fixing android build break when using a 64 bit isa.
Change 3375655 on 2017/03/31 by Jeff.Fisher
Fixing missing RGBAToYUV shader problem
-This at least unblocks our process. Will revisit before zbr.
Change 3375820 on 2017/04/01 by Jeff.Fisher
Fixing linux build warning about HAS_MORPHEUS
Change 3376050 on 2017/04/02 by Jeff.Fisher
UE-43515 Step 'UE4Editor Static Analysis Win64' - Module.OnlineSubsystemOculus.cpp Warnings
-Temporary fix for static analysis annotation warnings in OnlineSubsytemOculus. Longer term plan is to eliminate the use of the headers that trigger the warnings.
-Just wrap all standard headers in static analysis disables.
#jira UE-43515
Change 3376609 on 2017/04/03 by Jeff.Fisher
Fixing rgbatoyuvshader include.
Change 3377001 on 2017/04/03 by Jeff.Fisher
UE-43547 Launch On PS4 fails during Run command - Missing global shader FRGBAToYUV420CS
- shader c++ must be compiled so that it can be cooked for ps4.
#jira UE-43547
Change 3379858 on 2017/04/04 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
pulling main this should get us ps4 sdk 4.508
Change 3379938 on 2017/04/04 by Ryan.Vance
#jira UE-43548
If stereo layers are not being used, don't setup overlay targets as we will never clear/initialize them.
The clear happens as part of the default layers PostRenderView_RenderThread call which wont be called if layers aren't being used in the scene.
Change 3381519 on 2017/04/05 by Jeff.Fisher
UEVR-733 PS4 sdk 4.500 hmd connection api changes break hmd connect.
-Handling failure of sceHmdGetDeviceInformation if the hmd is powered off. It now returns an error code about an invalid handle in that case, rather than reporting unready. We just treat the error code like an unready status.
#jira UEVR-733
#review-3384107
Change 3382019 on 2017/04/05 by Ryan.Vance
Linux: add Vulkan support from dev editor: 3381593
Change 3382021 on 2017/04/05 by Ryan.Vance
SteamVR on Linux using Vulkan
OpenVR rev to 1_0_6
PR #3412: [GNUX] Initial support for SteamVR using Vulkan on GNUX platform. (Contributed by yaakuro)
Change 3382076 on 2017/04/05 by Ryan.Vance
Fixing linux steamvr lib path. It changed to something less silly in 1.0.6
Removing the steamvr plugin from the white list for linux. It's looking for a runtime that no one will have installed.
Change 3383237 on 2017/04/06 by Ryan.Vance
#jira UE-43732
Fixing Android compile issues. We can't wrap portions of a macro with a definie. This should probably be some sort of recursive macro thing since there's so much overlap. Good enough for now.
Change 3383353 on 2017/04/06 by Ryan.Vance
Fixing include cycles.
Change 3383509 on 2017/04/06 by Jeff.Fisher
Merging //UE4/Dev-Main to Dev-VR (//UE4/Dev-VR)
merging the stuff from dev-mobile
[CL 3384106 by Ryan Vance in Main branch]
863 lines
37 KiB
C++
863 lines
37 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "OculusInput.h"
|
|
#include "Features/IModularFeatures.h"
|
|
#include "IOculusRiftPlugin.h"
|
|
#include "OculusRiftCommon.h"
|
|
#include "OculusRiftHMD.h"
|
|
#include "Misc/App.h"
|
|
#include "GenericPlatform/IInputInterface.h"
|
|
|
|
#if OCULUS_INPUT_SUPPORTED_PLATFORMS
|
|
|
|
#define OVR_TESTING 0
|
|
#define OVR_DEBUG_LOGGING 0
|
|
|
|
#define LOCTEXT_NAMESPACE "OculusInput"
|
|
|
|
const FKey FOculusKey::OculusTouch_Left_Thumbstick("OculusTouch_Left_Thumbstick");
|
|
const FKey FOculusKey::OculusTouch_Left_Trigger("OculusTouch_Left_Trigger");
|
|
const FKey FOculusKey::OculusTouch_Left_FaceButton1("OculusTouch_Left_FaceButton1");
|
|
const FKey FOculusKey::OculusTouch_Left_FaceButton2("OculusTouch_Left_FaceButton2");
|
|
const FKey FOculusKey::OculusTouch_Left_IndexPointing("OculusTouch_Left_IndexPointing");
|
|
const FKey FOculusKey::OculusTouch_Left_ThumbUp("OculusTouch_Left_ThumbUp");
|
|
|
|
const FKey FOculusKey::OculusTouch_Right_Thumbstick("OculusTouch_Right_Thumbstick");
|
|
const FKey FOculusKey::OculusTouch_Right_Trigger("OculusTouch_Right_Trigger");
|
|
const FKey FOculusKey::OculusTouch_Right_FaceButton1("OculusTouch_Right_FaceButton1");
|
|
const FKey FOculusKey::OculusTouch_Right_FaceButton2("OculusTouch_Right_FaceButton2");
|
|
const FKey FOculusKey::OculusTouch_Right_IndexPointing("OculusTouch_Right_IndexPointing");
|
|
const FKey FOculusKey::OculusTouch_Right_ThumbUp("OculusTouch_Right_ThumbUp");
|
|
|
|
const FKey FOculusKey::OculusRemote_DPad_Down("OculusRemote_DPad_Down");
|
|
const FKey FOculusKey::OculusRemote_DPad_Up("OculusRemote_DPad_Up");
|
|
const FKey FOculusKey::OculusRemote_DPad_Left("OculusRemote_DPad_Left");
|
|
const FKey FOculusKey::OculusRemote_DPad_Right("OculusRemote_DPad_Right");
|
|
const FKey FOculusKey::OculusRemote_Enter("OculusRemote_Enter");
|
|
const FKey FOculusKey::OculusRemote_Back("OculusRemote_Back");
|
|
const FKey FOculusKey::OculusRemote_VolumeUp("OculusRemote_VolumeUp");
|
|
const FKey FOculusKey::OculusRemote_VolumeDown("OculusRemote_VolumeDown");
|
|
const FKey FOculusKey::OculusRemote_Home("OculusRemote_Home");
|
|
|
|
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Left_Thumbstick("OculusTouch_Left_Thumbstick");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Left_Trigger("OculusTouch_Left_Trigger");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Left_FaceButton1("OculusTouch_Left_FaceButton1");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Left_FaceButton2("OculusTouch_Left_FaceButton2");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Left_IndexPointing("OculusTouch_Left_IndexPointing");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Left_ThumbUp("OculusTouch_Left_ThumbUp");
|
|
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Right_Thumbstick("OculusTouch_Right_Thumbstick");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Right_Trigger("OculusTouch_Right_Trigger");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Right_FaceButton1("OculusTouch_Right_FaceButton1");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Right_FaceButton2("OculusTouch_Right_FaceButton2");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Right_IndexPointing("OculusTouch_Right_IndexPointing");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusTouch_Right_ThumbUp("OculusTouch_Right_ThumbUp");
|
|
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_DPad_Down("OculusRemote_DPad_Down");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_DPad_Up("OculusRemote_DPad_Up");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_DPad_Left("OculusRemote_DPad_Left");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_DPad_Right("OculusRemote_DPad_Right");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_Enter("OculusRemote_Enter");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_Back("OculusRemote_Back");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_VolumeUp("OculusRemote_VolumeUp");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_VolumeDown("OculusRemote_VolumeDown");
|
|
const FOculusKeyNames::Type FOculusKeyNames::OculusRemote_Home("OculusRemote_Home");
|
|
|
|
/** Threshold for treating trigger pulls as button presses, from 0.0 to 1.0 */
|
|
float FOculusInput::TriggerThreshold = 0.8f;
|
|
|
|
/** Are Remote keys mapped to gamepad or not. */
|
|
bool FOculusInput::bRemoteKeysMappedToGamepad = true;
|
|
|
|
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 );
|
|
|
|
UE_LOG(LogOcInput, Log, TEXT("OculusInput is initialized. Init status %d. Runtime version: %s"), int(initStatus), *FString(ANSI_TO_TCHAR(ovr_GetVersionString())));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
FOculusInput::~FOculusInput()
|
|
{
|
|
IModularFeatures::Get().UnregisterModularFeature( GetModularFeatureName(), this );
|
|
}
|
|
|
|
void FOculusInput::PreInit()
|
|
{
|
|
// Load the config, even if we failed to initialize a controller
|
|
LoadConfig();
|
|
|
|
// Register the FKeys
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Left_Thumbstick, LOCTEXT("OculusTouch_Left_Thumbstick", "Oculus Touch (L) Thumbstick CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Left_FaceButton1, LOCTEXT("OculusTouch_Left_FaceButton1", "Oculus Touch (L) X Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Left_Trigger, LOCTEXT("OculusTouch_Left_Trigger", "Oculus Touch (L) Trigger CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Left_FaceButton2, LOCTEXT("OculusTouch_Left_FaceButton2", "Oculus Touch (L) Y Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Left_IndexPointing, LOCTEXT("OculusTouch_Left_IndexPointing", "Oculus Touch (L) Pointing CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Left_ThumbUp, LOCTEXT("OculusTouch_Left_ThumbUp", "Oculus Touch (L) Thumb Up CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Right_Thumbstick, LOCTEXT("OculusTouch_Right_Thumbstick", "Oculus Touch (R) Thumbstick CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Right_FaceButton1, LOCTEXT("OculusTouch_Right_FaceButton1", "Oculus Touch (R) A Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Right_Trigger, LOCTEXT("OculusTouch_Right_Trigger", "Oculus Touch (R) Trigger CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Right_FaceButton2, LOCTEXT("OculusTouch_Right_FaceButton2", "Oculus Touch (R) B Button CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Right_IndexPointing, LOCTEXT("OculusTouch_Right_IndexPointing", "Oculus Touch (R) Pointing CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusTouch_Right_ThumbUp, LOCTEXT("OculusTouch_Right_ThumbUp", "Oculus Touch (R) Thumb Up CapTouch"), FKeyDetails::GamepadKey | FKeyDetails::FloatAxis));
|
|
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_DPad_Up, LOCTEXT("OculusRemote_DPad_Up", "Oculus Remote D-pad Up"), FKeyDetails::GamepadKey));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_DPad_Down, LOCTEXT("OculusRemote_DPad_Down", "Oculus Remote D-pad Down"), FKeyDetails::GamepadKey));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_DPad_Left, LOCTEXT("OculusRemote_DPad_Left", "Oculus Remote D-pad Left"), FKeyDetails::GamepadKey));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_DPad_Right, LOCTEXT("OculusRemote_DPad_Right", "Oculus Remote D-pad Right"), FKeyDetails::GamepadKey));
|
|
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_Enter, LOCTEXT("OculusRemote_Enter", "Oculus Remote Enter"), FKeyDetails::GamepadKey));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_Back, LOCTEXT("OculusRemote_Back", "Oculus Remote Back"), FKeyDetails::GamepadKey));
|
|
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_VolumeUp, LOCTEXT("OculusRemote_VolumeUp", "Oculus Remote Volume Up"), FKeyDetails::GamepadKey));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_VolumeDown, LOCTEXT("OculusRemote_VolumeDown", "Oculus Remote Volume Down"), FKeyDetails::GamepadKey));
|
|
EKeys::AddKey(FKeyDetails(FOculusKey::OculusRemote_Home, LOCTEXT("OculusRemote_Home", "Oculus Remote Home"), FKeyDetails::GamepadKey));
|
|
|
|
UE_LOG(LogOcInput, Log, TEXT("OculusInput pre-init called"));
|
|
}
|
|
|
|
void FOculusInput::LoadConfig()
|
|
{
|
|
const TCHAR* OculusTouchSettings = TEXT("OculusTouch.Settings");
|
|
float ConfigThreshold = TriggerThreshold;
|
|
|
|
if (GConfig->GetFloat(OculusTouchSettings, TEXT("TriggerThreshold"), ConfigThreshold, GEngineIni))
|
|
{
|
|
TriggerThreshold = ConfigThreshold;
|
|
}
|
|
|
|
const TCHAR* OculusRemoteSettings = TEXT("OculusRemote.Settings");
|
|
bool b;
|
|
if (GConfig->GetBool(OculusRemoteSettings, TEXT("bRemoteKeysMappedToGamepad"), b, GEngineIni))
|
|
{
|
|
bRemoteKeysMappedToGamepad = b;
|
|
}
|
|
}
|
|
|
|
void FOculusInput::Tick( float DeltaTime )
|
|
{
|
|
// Nothing to do when ticking, for now. SendControllerEvents() handles everything.
|
|
}
|
|
|
|
|
|
void FOculusInput::SendControllerEvents()
|
|
{
|
|
const double CurrentTime = FPlatformTime::Seconds();
|
|
|
|
// @todo: Should be made configurable and unified with other controllers handling of repeat
|
|
const float InitialButtonRepeatDelay = 0.2f;
|
|
const float ButtonRepeatDelay = 0.1f;
|
|
const float AnalogButtonPressThreshold = TriggerThreshold;
|
|
|
|
if(IOculusRiftPlugin::IsAvailable())
|
|
{
|
|
IOculusRiftPlugin& OculusRiftPlugin = IOculusRiftPlugin::Get();
|
|
FOvrSessionShared::AutoSession OvrSession(IOculusRiftPlugin::Get().GetSession());
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: OvrSession = %p"), ovrSession(OvrSession));
|
|
if (OvrSession && MessageHandler.IsValid() && FApp::HasVRFocus())
|
|
{
|
|
ovrInputState OvrInput;
|
|
ovrTrackingState OvrTrackingState;
|
|
|
|
ovrResult OvrRes = ovr_GetInputState(OvrSession, ovrControllerType_Remote, &OvrInput);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: ovr_GetInputState(Remote) ret = %d"), int(OvrRes));
|
|
if (OVR_SUCCESS(OvrRes) && OvrInput.ControllerType == ovrControllerType_Remote)
|
|
{
|
|
for (int32 ButtonIndex = 0; ButtonIndex < (int32)EOculusRemoteControllerButton::TotalButtonCount; ++ButtonIndex)
|
|
{
|
|
FOculusButtonState& ButtonState = Remote.Buttons[ButtonIndex];
|
|
check(!ButtonState.Key.IsNone()); // is button's name initialized?
|
|
|
|
// Determine if the button is pressed down
|
|
bool bButtonPressed = false;
|
|
switch ((EOculusRemoteControllerButton)ButtonIndex)
|
|
{
|
|
case EOculusRemoteControllerButton::DPad_Up:
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Up) != 0;
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::DPad_Down:
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Down) != 0;
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::DPad_Left:
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Left) != 0;
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::DPad_Right:
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Right) != 0;
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::Enter:
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Enter) != 0;
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::Back:
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Back) != 0;
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::VolumeUp:
|
|
#ifdef SUPPORT_INTERNAL_BUTTONS
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_VolUp) != 0;
|
|
#endif
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::VolumeDown:
|
|
#ifdef SUPPORT_INTERNAL_BUTTONS
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_VolDown) != 0;
|
|
#endif
|
|
break;
|
|
|
|
case EOculusRemoteControllerButton::Home:
|
|
#ifdef SUPPORT_INTERNAL_BUTTONS
|
|
bButtonPressed = (OvrInput.Buttons & ovrButton_Home) != 0;
|
|
#endif
|
|
break;
|
|
|
|
default:
|
|
check(0); // unhandled button, shouldn't happen
|
|
break;
|
|
}
|
|
|
|
// Update button state
|
|
if (bButtonPressed != ButtonState.bIsPressed)
|
|
{
|
|
const bool bIsRepeat = false;
|
|
|
|
ButtonState.bIsPressed = bButtonPressed;
|
|
if (ButtonState.bIsPressed)
|
|
{
|
|
MessageHandler->OnControllerButtonPressed(ButtonState.Key, 0, bIsRepeat);
|
|
|
|
// Set the timer for the first repeat
|
|
ButtonState.NextRepeatTime = CurrentTime + ButtonRepeatDelay;
|
|
}
|
|
else
|
|
{
|
|
MessageHandler->OnControllerButtonReleased(ButtonState.Key, 0, bIsRepeat);
|
|
}
|
|
}
|
|
|
|
// Apply key repeat, if its time for that
|
|
if (ButtonState.bIsPressed && ButtonState.NextRepeatTime <= CurrentTime)
|
|
{
|
|
const bool bIsRepeat = true;
|
|
MessageHandler->OnControllerButtonPressed(ButtonState.Key, 0, bIsRepeat);
|
|
|
|
// Set the timer for the next repeat
|
|
ButtonState.NextRepeatTime = CurrentTime + ButtonRepeatDelay;
|
|
}
|
|
}
|
|
}
|
|
|
|
OvrRes = ovr_GetInputState(OvrSession, ovrControllerType_Touch, &OvrInput);
|
|
const bool bOvrGCTRes = OculusRiftPlugin.GetCurrentTrackingState(&OvrTrackingState);
|
|
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: ovr_GetInputState(Touch) ret = %d, GetCurrentTrackingState ret = %d"), int(OvrRes), int(bOvrGCTRes));
|
|
|
|
if (OVR_SUCCESS(OvrRes) && bOvrGCTRes)
|
|
{
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: ButtonState = 0x%X"), OvrInput.Buttons);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: Touches = 0x%X"), OvrInput.Touches);
|
|
|
|
for (FOculusTouchControllerPair& ControllerPair : ControllerPairs)
|
|
{
|
|
for( int32 HandIndex = 0; HandIndex < ARRAY_COUNT( ControllerPair.ControllerStates ); ++HandIndex )
|
|
{
|
|
FOculusTouchControllerState& State = ControllerPair.ControllerStates[ HandIndex ];
|
|
|
|
const bool bIsLeft = (HandIndex == (int32)EControllerHand::Left);
|
|
bool bIsCurrentlyTracked = (bIsLeft ? (OvrInput.ControllerType & ovrControllerType_LTouch) != 0 : (OvrInput.ControllerType & ovrControllerType_RTouch) != 0);
|
|
|
|
#if OVR_TESTING
|
|
bIsCurrentlyTracked = true;
|
|
static float _angle = 0;
|
|
OvrTrackingState.HandPoses[HandIndex].ThePose.Orientation = OVR::Quatf(OVR::Vector3f(0, 0, 1), _angle);
|
|
_angle += 0.1f;
|
|
|
|
OvrTrackingState.HandPoses[HandIndex].ThePose = OvrTrackingState.HeadPose.ThePose;
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Error, TEXT("SendControllerEvents: OVR_TESTING is enabled!"));
|
|
#endif
|
|
|
|
if (bIsCurrentlyTracked)
|
|
{
|
|
State.bIsConnected = true;
|
|
State.bIsPositionTracked = (OvrTrackingState.HandStatusFlags[HandIndex] & ovrStatus_PositionTracked) != 0;
|
|
State.bIsOrientationTracked = (OvrTrackingState.HandStatusFlags[HandIndex] & ovrStatus_OrientationTracked) != 0;
|
|
|
|
const float OvrTriggerAxis = OvrInput.IndexTrigger[HandIndex];
|
|
const float OvrGripAxis = OvrInput.HandTrigger[HandIndex];
|
|
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: IndexTrigger[%d] = %f"), int(HandIndex), OvrTriggerAxis);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: HandTrigger[%d] = %f"), int(HandIndex), OvrGripAxis);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: ThumbStick[%d] = { %f, %f }"), int(HandIndex), OvrInput.Thumbstick[HandIndex].x, OvrInput.Thumbstick[HandIndex].y );
|
|
|
|
if (OvrTriggerAxis != State.TriggerAxis)
|
|
{
|
|
State.TriggerAxis = OvrTriggerAxis;
|
|
MessageHandler->OnControllerAnalog(bIsLeft ? FGamepadKeyNames::MotionController_Left_TriggerAxis : FGamepadKeyNames::MotionController_Right_TriggerAxis, ControllerPair.UnrealControllerIndex, State.TriggerAxis);
|
|
}
|
|
|
|
if (OvrGripAxis != State.GripAxis)
|
|
{
|
|
State.GripAxis = OvrGripAxis;
|
|
MessageHandler->OnControllerAnalog(bIsLeft ? FGamepadKeyNames::MotionController_Left_Grip1Axis : FGamepadKeyNames::MotionController_Right_Grip1Axis, ControllerPair.UnrealControllerIndex, State.GripAxis);
|
|
}
|
|
|
|
if (OvrInput.Thumbstick[HandIndex].x != State.ThumbstickAxes.X)
|
|
{
|
|
State.ThumbstickAxes.X = OvrInput.Thumbstick[HandIndex].x;
|
|
MessageHandler->OnControllerAnalog(bIsLeft ? FGamepadKeyNames::MotionController_Left_Thumbstick_X : FGamepadKeyNames::MotionController_Right_Thumbstick_X, ControllerPair.UnrealControllerIndex, State.ThumbstickAxes.X);
|
|
}
|
|
|
|
if (OvrInput.Thumbstick[HandIndex].y != State.ThumbstickAxes.Y)
|
|
{
|
|
State.ThumbstickAxes.Y = OvrInput.Thumbstick[HandIndex].y;
|
|
// we need to negate Y value to match XBox controllers
|
|
MessageHandler->OnControllerAnalog(bIsLeft ? FGamepadKeyNames::MotionController_Left_Thumbstick_Y : FGamepadKeyNames::MotionController_Right_Thumbstick_Y, ControllerPair.UnrealControllerIndex, -State.ThumbstickAxes.Y);
|
|
}
|
|
|
|
for (int32 ButtonIndex = 0; ButtonIndex < (int32)EOculusTouchControllerButton::TotalButtonCount; ++ButtonIndex)
|
|
{
|
|
FOculusButtonState& ButtonState = State.Buttons[ButtonIndex];
|
|
check(!ButtonState.Key.IsNone()); // is button's name initialized?
|
|
|
|
// Determine if the button is pressed down
|
|
bool bButtonPressed = false;
|
|
switch ((EOculusTouchControllerButton)ButtonIndex)
|
|
{
|
|
case EOculusTouchControllerButton::Trigger:
|
|
bButtonPressed = State.TriggerAxis >= AnalogButtonPressThreshold;
|
|
break;
|
|
|
|
case EOculusTouchControllerButton::Grip:
|
|
bButtonPressed = State.GripAxis >= AnalogButtonPressThreshold;
|
|
break;
|
|
|
|
case EOculusTouchControllerButton::XA:
|
|
bButtonPressed = bIsLeft ? (OvrInput.Buttons & ovrButton_X) != 0 : (OvrInput.Buttons & ovrButton_A) != 0;
|
|
break;
|
|
|
|
case EOculusTouchControllerButton::YB:
|
|
bButtonPressed = bIsLeft ? (OvrInput.Buttons & ovrButton_Y) != 0 : (OvrInput.Buttons & ovrButton_B) != 0;
|
|
break;
|
|
|
|
case EOculusTouchControllerButton::Thumbstick:
|
|
bButtonPressed = bIsLeft ? (OvrInput.Buttons & ovrButton_LThumb) != 0 : (OvrInput.Buttons & ovrButton_RThumb) != 0;
|
|
break;
|
|
|
|
case EOculusTouchControllerButton::Menu:
|
|
bButtonPressed = bIsLeft && (OvrInput.Buttons & ovrButton_Enter);
|
|
break;
|
|
|
|
default:
|
|
check(0);
|
|
break;
|
|
}
|
|
|
|
// Update button state
|
|
if (bButtonPressed != ButtonState.bIsPressed)
|
|
{
|
|
const bool bIsRepeat = false;
|
|
|
|
ButtonState.bIsPressed = bButtonPressed;
|
|
if (ButtonState.bIsPressed)
|
|
{
|
|
MessageHandler->OnControllerButtonPressed(ButtonState.Key, ControllerPair.UnrealControllerIndex, bIsRepeat);
|
|
|
|
// Set the timer for the first repeat
|
|
ButtonState.NextRepeatTime = CurrentTime + ButtonRepeatDelay;
|
|
}
|
|
else
|
|
{
|
|
MessageHandler->OnControllerButtonReleased(ButtonState.Key, ControllerPair.UnrealControllerIndex, bIsRepeat);
|
|
}
|
|
}
|
|
|
|
// Apply key repeat, if its time for that
|
|
if (ButtonState.bIsPressed && ButtonState.NextRepeatTime <= CurrentTime)
|
|
{
|
|
const bool bIsRepeat = true;
|
|
MessageHandler->OnControllerButtonPressed(ButtonState.Key, ControllerPair.UnrealControllerIndex, bIsRepeat);
|
|
|
|
// Set the timer for the next repeat
|
|
ButtonState.NextRepeatTime = CurrentTime + ButtonRepeatDelay;
|
|
}
|
|
}
|
|
|
|
// Handle Capacitive States
|
|
for (int32 CapTouchIndex = 0; CapTouchIndex < (int32)EOculusTouchCapacitiveAxes::TotalAxisCount; ++CapTouchIndex)
|
|
{
|
|
FOculusTouchCapacitiveState& CapState = State.CapacitiveAxes[CapTouchIndex];
|
|
|
|
float CurrentAxisVal = 0.f;
|
|
switch ((EOculusTouchCapacitiveAxes)CapTouchIndex)
|
|
{
|
|
case EOculusTouchCapacitiveAxes::XA:
|
|
{
|
|
const uint32 mask = (bIsLeft) ? ovrTouch_X : ovrTouch_A;
|
|
CurrentAxisVal = (OvrInput.Touches & mask) != 0 ? 1.f : 0.f;
|
|
break;
|
|
}
|
|
case EOculusTouchCapacitiveAxes::YB:
|
|
{
|
|
const uint32 mask = (bIsLeft) ? ovrTouch_Y : ovrTouch_B;
|
|
CurrentAxisVal = (OvrInput.Touches & mask) != 0 ? 1.f : 0.f;
|
|
break;
|
|
}
|
|
case EOculusTouchCapacitiveAxes::Thumbstick:
|
|
{
|
|
const uint32 mask = (bIsLeft) ? ovrTouch_LThumb : ovrTouch_RThumb;
|
|
CurrentAxisVal = (OvrInput.Touches & mask) != 0 ? 1.f : 0.f;
|
|
break;
|
|
}
|
|
case EOculusTouchCapacitiveAxes::Trigger:
|
|
{
|
|
const uint32 mask = (bIsLeft) ? ovrTouch_LIndexTrigger : ovrTouch_RIndexTrigger;
|
|
CurrentAxisVal = (OvrInput.Touches & mask) != 0 ? 1.f : 0.f;
|
|
break;
|
|
}
|
|
case EOculusTouchCapacitiveAxes::IndexPointing:
|
|
{
|
|
const uint32 mask = (bIsLeft) ? ovrTouch_LIndexPointing : ovrTouch_RIndexPointing;
|
|
CurrentAxisVal = (OvrInput.Touches & mask) != 0 ? 1.f : 0.f;
|
|
break;
|
|
}
|
|
case EOculusTouchCapacitiveAxes::ThumbUp:
|
|
{
|
|
const uint32 mask = (bIsLeft) ? ovrTouch_LThumbUp : ovrTouch_RThumbUp;
|
|
CurrentAxisVal = (OvrInput.Touches & mask) != 0 ? 1.f : 0.f;
|
|
break;
|
|
}
|
|
default:
|
|
check(0);
|
|
}
|
|
|
|
if (CurrentAxisVal != CapState.State)
|
|
{
|
|
MessageHandler->OnControllerAnalog(CapState.Axis, ControllerPair.UnrealControllerIndex, CurrentAxisVal);
|
|
|
|
CapState.State = CurrentAxisVal;
|
|
}
|
|
}
|
|
|
|
const ovrPosef& OvrHandPose = OvrTrackingState.HandPoses[HandIndex].ThePose;
|
|
FVector NewLocation;
|
|
FQuat NewOrientation;
|
|
if (OculusRiftPlugin.PoseToOrientationAndPosition(OvrHandPose, /* Out */ NewOrientation, /* Out */ NewLocation))
|
|
{
|
|
// OK, we have up to date positional data!
|
|
State.Orientation = NewOrientation;
|
|
State.Location = NewLocation;
|
|
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: HandPOSE[%d]: Pos %.3f %.3f %.3f"), HandIndex, NewLocation.X, NewLocation.Y, NewLocation.Y);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: HandPOSE[%d]: Yaw %.3f Pitch %.3f Roll %.3f"), HandIndex, NewOrientation.Rotator().Yaw, NewOrientation.Rotator().Pitch, NewOrientation.Rotator().Roll);
|
|
}
|
|
else
|
|
{
|
|
// HMD wasn't ready. This can currently happen if we try to grab motion data before we've rendered at least one frame
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: PoseToOrientationAndPosition returned false"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Controller isn't available right now. Zero out input state, so that if it comes back it will send fresh event deltas
|
|
State = FOculusTouchControllerState((EControllerHand)HandIndex);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: Controller for the hand %d is not tracked"), int(HandIndex));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT(""));
|
|
}
|
|
|
|
|
|
void FOculusInput::SetMessageHandler( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler )
|
|
{
|
|
MessageHandler = InMessageHandler;
|
|
}
|
|
|
|
|
|
bool FOculusInput::Exec( UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar )
|
|
{
|
|
// No exec commands supported, for now.
|
|
return false;
|
|
}
|
|
|
|
void FOculusInput::SetChannelValue( int32 ControllerId, FForceFeedbackChannelType ChannelType, float Value )
|
|
{
|
|
const EControllerHand Hand = ( ChannelType == FForceFeedbackChannelType::LEFT_LARGE || ChannelType == FForceFeedbackChannelType::LEFT_SMALL ) ? EControllerHand::Left : EControllerHand::Right;
|
|
|
|
for( FOculusTouchControllerPair& ControllerPair : ControllerPairs )
|
|
{
|
|
if( ControllerPair.UnrealControllerIndex == ControllerId )
|
|
{
|
|
FOculusTouchControllerState& ControllerState = ControllerPair.ControllerStates[ (int32)Hand ];
|
|
|
|
if (ControllerState.bPlayingHapticEffect)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// @todo: The SMALL channel controls frequency, the LARGE channel controls amplitude. This is a bit of a weird fit.
|
|
if( ChannelType == FForceFeedbackChannelType::LEFT_SMALL || ChannelType == FForceFeedbackChannelType::RIGHT_SMALL )
|
|
{
|
|
ControllerState.HapticFrequency = Value;
|
|
}
|
|
else
|
|
{
|
|
ControllerState.HapticAmplitude = Value;
|
|
}
|
|
|
|
UpdateForceFeedback( ControllerPair, Hand );
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void FOculusInput::SetChannelValues( int32 ControllerId, const FForceFeedbackValues& Values )
|
|
{
|
|
for( FOculusTouchControllerPair& ControllerPair : ControllerPairs )
|
|
{
|
|
if( ControllerPair.UnrealControllerIndex == ControllerId )
|
|
{
|
|
// @todo: The SMALL channel controls frequency, the LARGE channel controls amplitude. This is a bit of a weird fit.
|
|
FOculusTouchControllerState& LeftControllerState = ControllerPair.ControllerStates[ (int32)EControllerHand::Left ];
|
|
if (!LeftControllerState.bPlayingHapticEffect)
|
|
{
|
|
LeftControllerState.HapticFrequency = Values.LeftSmall;
|
|
LeftControllerState.HapticAmplitude = Values.LeftLarge;
|
|
UpdateForceFeedback(ControllerPair, EControllerHand::Left);
|
|
}
|
|
|
|
FOculusTouchControllerState& RightControllerState = ControllerPair.ControllerStates[(int32)EControllerHand::Right];
|
|
if (!RightControllerState.bPlayingHapticEffect)
|
|
{
|
|
RightControllerState.HapticFrequency = Values.RightSmall;
|
|
RightControllerState.HapticAmplitude = Values.RightLarge;
|
|
UpdateForceFeedback(ControllerPair, EControllerHand::Right);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void FOculusInput::UpdateForceFeedback( const FOculusTouchControllerPair& ControllerPair, const EControllerHand Hand )
|
|
{
|
|
const FOculusTouchControllerState& ControllerState = ControllerPair.ControllerStates[ (int32)Hand ];
|
|
|
|
if(IOculusRiftPlugin::IsAvailable())
|
|
{
|
|
FOvrSessionShared::AutoSession OvrSession(IOculusRiftPlugin::Get().GetSession());
|
|
|
|
if( ControllerState.bIsConnected && !ControllerState.bPlayingHapticEffect && OvrSession && FApp::HasVRFocus())
|
|
{
|
|
// Make sure Touch is the active controller
|
|
ovrInputState OvrInput;
|
|
ovrResult OvrRes = ovr_GetInputState(OvrSession, ovrControllerType_Active, &OvrInput);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: ovr_GetInputState(Active) ret = %d"), int(OvrRes));
|
|
const ovrControllerType OvrController = (Hand == EControllerHand::Left) ? ovrControllerType_LTouch : ovrControllerType_RTouch;
|
|
if (OVR_SUCCESS(OvrRes) && ((OvrController & OvrInput.ControllerType) != 0))
|
|
{
|
|
float FreqMin, FreqMax = 0.f;
|
|
GetHapticFrequencyRange(FreqMin, FreqMax);
|
|
|
|
// Map the [0.0 - 1.0] range to a useful range of frequencies for the Oculus controllers
|
|
const float ActualFrequency = FMath::Lerp(FreqMin, FreqMax, FMath::Clamp(ControllerState.HapticFrequency, 0.0f, 1.0f));
|
|
|
|
// Oculus SDK wants amplitude values between 0.0 and 1.0
|
|
const float ActualAmplitude = ControllerState.HapticAmplitude * GetHapticAmplitudeScale();
|
|
|
|
static float LastAmplitudeSent = -1;
|
|
if (ActualAmplitude != LastAmplitudeSent)
|
|
{
|
|
ovr_SetControllerVibration(OvrSession, OvrController, ActualFrequency, ActualAmplitude);
|
|
LastAmplitudeSent = ActualAmplitude;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool FOculusInput::GetControllerOrientationAndPosition( const int32 ControllerIndex, const EControllerHand DeviceHand, FRotator& OutOrientation, FVector& OutPosition, float WorldToMetersScale) const
|
|
{
|
|
bool bHaveControllerData = false;
|
|
|
|
for( const FOculusTouchControllerPair& ControllerPair : ControllerPairs )
|
|
{
|
|
if( ControllerPair.UnrealControllerIndex == ControllerIndex )
|
|
{
|
|
if( (DeviceHand == EControllerHand::Left) || (DeviceHand == EControllerHand::Right) )
|
|
{
|
|
if (IsInGameThread())
|
|
{
|
|
const FOculusTouchControllerState& ControllerState = ControllerPair.ControllerStates[(int32)DeviceHand];
|
|
|
|
if (ControllerState.bIsConnected)
|
|
{
|
|
OutOrientation = ControllerState.Orientation.Rotator();
|
|
OutPosition = ControllerState.Location;
|
|
|
|
bHaveControllerData = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
if (GEngine->HMDDevice.IsValid() && (GEngine->HMDDevice->GetHMDDeviceType() == EHMDDeviceType::DT_OculusRift))
|
|
{
|
|
FOculusRiftHMD* OculusHMD = static_cast<FOculusRiftHMD*>(GEngine->HMDDevice.Get());
|
|
FCustomPresent* OculusCustomPresent = static_cast<FCustomPresent*>(OculusHMD->GetCustomPresent());
|
|
FViewExtension* ViewExtension = OculusCustomPresent->GetRenderContext();
|
|
if (ViewExtension)
|
|
{
|
|
FGameFrame* Frame = ViewExtension->GetRenderFrame();
|
|
if (Frame)
|
|
{
|
|
ovrTrackingState LateUpdateOvrTrackingState = Frame->RenderThreadTrackingState;
|
|
ovrPosef& InPose = LateUpdateOvrTrackingState.HandPoses[(int32)DeviceHand].ThePose;
|
|
FVector NewLocation;
|
|
FQuat NewOrientation;
|
|
|
|
NewOrientation = ToFQuat(InPose.Orientation);
|
|
float WTMS = Frame->WorldToMetersScaleWhileInFrame;
|
|
// Oculus is tracking its own WorldToMetersScale, so we won't use the passed in one.
|
|
// Debugging found that the oculus value is one frame old, but it seems unlikely a human would ever notice that.
|
|
const FVector Pos = (ToFVector_M2U(OVR::Vector3f(InPose.Position), WTMS) - (Frame->Settings->BaseOffset * WTMS)) * Frame->CameraScale3D;
|
|
OutPosition = Frame->Settings->BaseOrientation.Inverse().RotateVector(Pos);
|
|
|
|
NewOrientation = Frame->Settings->BaseOrientation.Inverse() * NewOrientation;
|
|
NewOrientation.Normalize();
|
|
OutOrientation = NewOrientation.Rotator();
|
|
|
|
bHaveControllerData = true;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return bHaveControllerData;
|
|
}
|
|
|
|
ETrackingStatus FOculusInput::GetControllerTrackingStatus(const int32 ControllerIndex, const EControllerHand DeviceHand) const
|
|
{
|
|
ETrackingStatus TrackingStatus = ETrackingStatus::NotTracked;
|
|
|
|
if (DeviceHand != EControllerHand::Left && DeviceHand != EControllerHand::Right)
|
|
{
|
|
return TrackingStatus;
|
|
}
|
|
|
|
for( const FOculusTouchControllerPair& ControllerPair : ControllerPairs )
|
|
{
|
|
if( ControllerPair.UnrealControllerIndex == ControllerIndex )
|
|
{
|
|
const FOculusTouchControllerState& ControllerState = ControllerPair.ControllerStates[ (int32)DeviceHand ];
|
|
|
|
if( ControllerState.bIsOrientationTracked )
|
|
{
|
|
TrackingStatus = ControllerState.bIsPositionTracked ? ETrackingStatus::Tracked : ETrackingStatus::InertialOnly;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return TrackingStatus;
|
|
}
|
|
|
|
void FOculusInput::SetHapticFeedbackValues(int32 ControllerId, int32 Hand, const FHapticFeedbackValues& Values)
|
|
{
|
|
for (FOculusTouchControllerPair& ControllerPair : ControllerPairs)
|
|
{
|
|
if (ControllerPair.UnrealControllerIndex == ControllerId)
|
|
{
|
|
FOculusTouchControllerState& ControllerState = ControllerPair.ControllerStates[Hand];
|
|
if (ControllerState.bIsConnected)
|
|
{
|
|
if(IOculusRiftPlugin::IsAvailable())
|
|
{
|
|
FOvrSessionShared::AutoSession OvrSession(IOculusRiftPlugin::Get().GetSession());
|
|
if (OvrSession && FApp::HasVRFocus())
|
|
{
|
|
static bool pulledHapticsDesc = false;
|
|
if (!pulledHapticsDesc)
|
|
{
|
|
HapticsDesc = ovr_GetTouchHapticsDesc(OvrSession, ovrControllerType_RTouch);
|
|
pulledHapticsDesc = true;
|
|
}
|
|
|
|
// Make sure Touch is the active controller
|
|
ovrInputState OvrInput;
|
|
ovrResult OvrRes = ovr_GetInputState(OvrSession, ovrControllerType_Active, &OvrInput);
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("SendControllerEvents: ovr_GetInputState(Active) ret = %d"), int(OvrRes));
|
|
const ovrControllerType OvrController = (EControllerHand(Hand) == EControllerHand::Left) ? ovrControllerType_LTouch : ovrControllerType_RTouch;
|
|
if (OVR_SUCCESS(OvrRes) && ((ovrControllerType_Touch == OvrInput.ControllerType) || (ovrControllerType_LTouch == OvrInput.ControllerType) || (ovrControllerType_RTouch == OvrInput.ControllerType)))
|
|
{
|
|
FHapticFeedbackBuffer* Buffer = Values.HapticBuffer;
|
|
if (Buffer && Buffer->SamplingRate == HapticsDesc.SampleRateHz)
|
|
{
|
|
|
|
ovrHapticsPlaybackState state;
|
|
memset(&state, 0, sizeof(state));
|
|
ovrResult result = ovr_GetControllerVibrationState(OvrSession, OvrController, &state);
|
|
int wanttosend = (int)ceil((float)HapticsDesc.SampleRateHz / 90.f) + 1;
|
|
wanttosend = FMath::Min(wanttosend, HapticsDesc.SubmitMaxSamples);
|
|
wanttosend = FMath::Max(wanttosend, HapticsDesc.SubmitMinSamples);
|
|
|
|
if (state.SamplesQueued < HapticsDesc.QueueMinSizeToAvoidStarvation + wanttosend) //trying to minimize latency
|
|
{
|
|
wanttosend = (HapticsDesc.QueueMinSizeToAvoidStarvation + wanttosend - state.SamplesQueued);
|
|
void *bufferToFree = NULL;
|
|
ovrHapticsBuffer obuffer;
|
|
obuffer.SubmitMode = ovrHapticsBufferSubmit_Enqueue;
|
|
obuffer.SamplesCount = FMath::Min(wanttosend, Buffer->BufferLength - Buffer->SamplesSent);
|
|
|
|
if (obuffer.SamplesCount == 0 && state.SamplesQueued == 0)
|
|
{
|
|
Buffer->bFinishedPlaying = true;
|
|
ControllerState.bPlayingHapticEffect = false;
|
|
}
|
|
else
|
|
{
|
|
if (HapticsDesc.SampleSizeInBytes == 1)
|
|
{
|
|
uint8* samples = (uint8*)FMemory::Malloc(obuffer.SamplesCount * sizeof(*samples));
|
|
for (int i = 0; i < obuffer.SamplesCount; i++)
|
|
{
|
|
samples[i] = static_cast<uint8>(Buffer->RawData[Buffer->CurrentPtr + i] * Buffer->ScaleFactor);
|
|
}
|
|
obuffer.Samples = bufferToFree = samples;
|
|
}
|
|
else if (HapticsDesc.SampleSizeInBytes == 2)
|
|
{
|
|
uint16* samples = (uint16*)FMemory::Malloc(obuffer.SamplesCount * sizeof(*samples));
|
|
for (int i = 0; i < obuffer.SamplesCount; i++)
|
|
{
|
|
const uint32 DataIndex = Buffer->CurrentPtr + (i * 2);
|
|
const uint16* const RawData = reinterpret_cast<uint16*>(&Buffer->RawData[DataIndex]);
|
|
samples[i] = static_cast<uint16>(*RawData * Buffer->ScaleFactor);
|
|
}
|
|
obuffer.Samples = bufferToFree = samples;
|
|
}
|
|
else if (HapticsDesc.SampleSizeInBytes == 4)
|
|
{
|
|
uint32* samples = (uint32*)FMemory::Malloc(obuffer.SamplesCount * sizeof(*samples));
|
|
for (int i = 0; i < obuffer.SamplesCount; i++)
|
|
{
|
|
const uint32 DataIndex = Buffer->CurrentPtr + (i * 4);
|
|
const uint32* const RawData = reinterpret_cast<uint32*>(&Buffer->RawData[DataIndex]);
|
|
samples[i] = static_cast<uint32>(*RawData * Buffer->ScaleFactor);
|
|
}
|
|
obuffer.Samples = bufferToFree = samples;
|
|
}
|
|
|
|
ovr_SubmitControllerVibration(OvrSession, OvrController, &obuffer);
|
|
|
|
if (bufferToFree)
|
|
{
|
|
FMemory::Free(bufferToFree);
|
|
}
|
|
|
|
Buffer->CurrentPtr += (obuffer.SamplesCount * HapticsDesc.SampleSizeInBytes);
|
|
Buffer->SamplesSent += obuffer.SamplesCount;
|
|
|
|
ControllerState.bPlayingHapticEffect = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Buffer)
|
|
{
|
|
UE_CLOG(OVR_DEBUG_LOGGING, LogOcInput, Log, TEXT("Haptic Buffer not sampled at the correct frequency : %d vs %d"), HapticsDesc.SampleRateHz, Buffer->SamplingRate);
|
|
}
|
|
float FreqMin, FreqMax = 0.f;
|
|
GetHapticFrequencyRange(FreqMin, FreqMax);
|
|
|
|
const float Frequency = FMath::Lerp(FreqMin, FreqMax, FMath::Clamp(Values.Frequency, 0.f, 1.f));
|
|
const float Amplitude = Values.Amplitude * GetHapticAmplitudeScale();
|
|
|
|
if (ControllerState.HapticAmplitude != Amplitude || ControllerState.HapticFrequency != Frequency)
|
|
{
|
|
ControllerState.HapticAmplitude = Amplitude;
|
|
ControllerState.HapticFrequency = Frequency;
|
|
|
|
ovr_SetControllerVibration(OvrSession, OvrController, Frequency, Amplitude);
|
|
|
|
ControllerState.bPlayingHapticEffect = (Amplitude != 0.f) && (Frequency != 0.f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void FOculusInput::GetHapticFrequencyRange(float& MinFrequency, float& MaxFrequency) const
|
|
{
|
|
MinFrequency = 0.f;
|
|
MaxFrequency = 1.f;
|
|
}
|
|
|
|
float FOculusInput::GetHapticAmplitudeScale() const
|
|
{
|
|
return 1.f;
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|
|
#endif // OCULUS_INPUT_SUPPORTED_PLATFORMS
|