123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- #pragma once
- #include "Engine.h"
- #include "HeadMountedDisplay.h"
- #include "SceneViewExtension.h"
- #include "Templates/RefCounting.h"
- #include <Runtime/Launch/Resources/Version.h>
- #include "FoveTypes.h"
- #if !defined(ENGINE_MAJOR_VERSION) || !defined(ENGINE_MINOR_VERSION)
- static_assert(false, "Unable to find Unreal version macros");
- #endif
- #if ENGINE_MAJOR_VERSION != 4 || ENGINE_MINOR_VERSION >= 18 || ENGINE_MINOR_VERSION < 12
- static_assert(false, "This version of the Fove Unreal plugin only supports Unreal 4.12 through 4.17");
- #endif
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 18
- #include "HeadMountedDisplayBase.h"
- #define FOVEHMD_BASE_CLASS FHeadMountedDisplayBase
- #else
- #define FOVEHMD_BASE_CLASS IHeadMountedDisplay
- #endif
- struct ID3D11Texture2D;
- class FoveRenderingBridge;
- class IRendererModule;
- namespace Fove
- {
- class IFVRHeadset;
- class IFVRCompositor;
- }
- class FOVEHMD_API FFoveHMD : public FOVEHMD_BASE_CLASS, public ISceneViewExtension, public TSharedFromThis<FFoveHMD, ESPMode::ThreadSafe>
- {
- public:
-
- FFoveHMD(TSharedRef<Fove::IFVRHeadset, ESPMode::ThreadSafe> headset, TUniquePtr<Fove::IFVRCompositor> compositor, Fove::SFVR_CompositorLayer layer);
- ~FFoveHMD() override;
-
-
- static FFoveHMD* Get();
- public:
-
-
-
-
- Fove::IFVRHeadset& GetHeadset() { return *FoveHeadset; }
- Fove::IFVRHeadset const& GetHeadset() const { return *FoveHeadset; }
- Fove::IFVRCompositor& GetCompositor() { return *FoveCompositor; }
- Fove::IFVRCompositor const& GetCompositor() const { return *FoveCompositor; }
-
- bool IsHardwareConnected() const;
-
- bool IsHardwareReady() const;
- public:
-
-
- bool IsEyeTrackingCalibrating() const;
-
-
-
-
-
- bool EnsureEyeTrackingCalibration();
-
-
-
-
-
-
-
- bool GetGazeConvergence(bool bRelativeToHMD, FVector* outRayOrigin, FVector* outRayDirection, float* outDistance, float* outAccuracy) const;
-
-
-
- bool GetGazeVector(bool bRelativeToHMD, FVector* outLeft, FVector* outRight) const;
-
-
-
- bool GetGazeVector2D(FVector2D* outLeft, FVector2D* outRight) const;
-
- bool ManualDriftCorrection3D(FVector Location);
-
-
- bool CheckEyesTracked(bool* outLeft, bool* outRight);
-
-
- bool CheckEyesClosed(bool* outLeft, bool* outRight);
- public:
-
- bool IsPositionReady() const;
- public:
-
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 18
- FName GetSystemName() const override;
- bool EnumerateTrackedDevices(TArray<int, FDefaultAllocator>&, EXRTrackedDeviceType) override;
- void RefreshPoses() override;
- bool GetCurrentPose(int32, FQuat&, FVector&) override;
- float GetWorldToMetersScale() const override { return WorldToMetersScale; }
- #endif
-
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 13 && ENGINE_MINOR_VERSION < 18
- FName GetDeviceName() const override;
- #endif
-
- bool IsHMDConnected() override;
- bool IsHMDEnabled() const override;
- void EnableHMD(bool allow = true) override;
- EHMDDeviceType::Type GetHMDDeviceType() const override;
- bool GetHMDMonitorInfo(MonitorInfo&) override;
- void GetFieldOfView(float& OutHFOVInDegrees, float& OutVFOVInDegrees) const override;
- bool IsChromaAbCorrectionEnabled() const override;
- void SetInterpupillaryDistance(float NewInterpupillaryDistance) override;
- float GetInterpupillaryDistance() const override;
- bool DoesSupportPositionalTracking() const override;
- bool HasValidTrackingPosition() override;
- void RebaseObjectOrientationAndPosition(FVector& Position, FQuat& Orientation) const override;
- bool IsHeadTrackingAllowed() const override;
- void ResetOrientationAndPosition(float yaw = 0.f) override;
- void ResetOrientation(float Yaw = 0.f) override;
- void ResetPosition() override;
- void SetBaseRotation(const FRotator& BaseRot) override;
- FRotator GetBaseRotation() const override;
- void SetBaseOrientation(const FQuat& BaseOrient) override;
- FQuat GetBaseOrientation() const override;
- void OnBeginPlay(FWorldContext& InWorldContext) override;
- void OnEndPlay(FWorldContext& InWorldContext) override;
- void SetTrackingOrigin(EHMDTrackingOrigin::Type NewOrigin) override;
- EHMDTrackingOrigin::Type GetTrackingOrigin() override;
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION < 18
- void GetPositionalTrackingCameraProperties(FVector& OutOrigin, FQuat& OutOrientation, float& OutHFOV, float& OutVFOV, float& OutCameraDistance, float& OutNearPlane, float& OutFarPlane) const override;
- void GetCurrentOrientationAndPosition(FQuat& CurrentOrientation, FVector& CurrentPosition) override;
- TSharedPtr<ISceneViewExtension, ESPMode::ThreadSafe> GetViewExtension() override;
- void ApplyHmdRotation(APlayerController* PC, FRotator& ViewRotation) override;
- bool UpdatePlayerCamera(FQuat& CurrentOrientation, FVector& CurrentPosition) override;
- bool IsPositionalTrackingEnabled() const override;
- #endif
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION < 16
- bool Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar) override;
- bool EnablePositionalTracking(bool enable) override;
- bool IsInLowPersistenceMode() const override;
- void EnableLowPersistenceMode(bool Enable = true) override;
- #endif
- public:
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 18
- FMatrix GetStereoProjectionMatrix(EStereoscopicPass) const override;
- #endif
-
- void SetClippingPlanes(float NCP, float FCP) override;
- void GetEyeRenderParams_RenderThread(const FRenderingCompositePassContext& Context, FVector2D& EyeToSrcUVScaleValue, FVector2D& EyeToSrcUVOffsetValue) const override;
- bool IsStereoEnabled() const override;
- bool EnableStereo(bool stereo = true) override;
- void AdjustViewRect(EStereoscopicPass StereoPass, int32& X, int32& Y, uint32& SizeX, uint32& SizeY) const override;
- void GetOrthoProjection(int32 RTWidth, int32 RTHeight, float OrthoDistance, FMatrix OrthoProjection[2]) const override;
- void InitCanvasFromView(FSceneView* InView, UCanvas* Canvas) override;
- #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION < 18
- void CalculateStereoViewOffset(EStereoscopicPass StereoPassType, const FRotator& ViewRotation, const float MetersToWorld, FVector& ViewLocation) override;
- FMatrix GetStereoProjectionMatrix(EStereoscopicPass StereoPassType, const float FOV) const override;
- void RenderTexture_RenderThread(FRHICommandListImmediate& RHICmdList, FTexture2DRHIParamRef BackBuffer, FTexture2DRHIParamRef SrcTexture) const override;
- void CalculateRenderTargetSize(const FViewport& Viewport, uint32& InOutSizeX, uint32& InOutSizeY) override;
- bool NeedReAllocateViewportRenderTarget(const FViewport& Viewport) override;
- bool ShouldUseSeparateRenderTarget() const override;
- void UpdateViewport(bool bUseSeparateRenderTarget, const FViewport& Viewport, SViewport*) override;
- #endif
- public:
- void SetupViewFamily(FSceneViewFamily& InViewFamily) override;
- void SetupView(FSceneViewFamily& InViewFamily, FSceneView& InView) override;
- void BeginRenderViewFamily(FSceneViewFamily& InViewFamily) override {}
- void PreRenderView_RenderThread(FRHICommandListImmediate& RHICmdList, FSceneView& InView) override;
- void PreRenderViewFamily_RenderThread(FRHICommandListImmediate& RHICmdList, FSceneViewFamily& InViewFamily) override;
- private:
- void PrivOrientationAndPosition(FQuat& OutOrientation, FVector& OutPosition);
- FMatrix PrivStereoProjectionMatrix(EStereoscopicPass) const;
-
- float WorldToMetersScale = 1;
-
- float ZNear = 1.0f;
- float ZFar = 1.0f;
-
- FQuat BaseOrientation = FQuat::Identity;
- FRotator AppliedHmdOrientation = FRotator(0, 0, 0);
- FRotator ControlRotation = FRotator(0, 0, 0);
- const TSharedRef<Fove::IFVRHeadset, ESPMode::ThreadSafe> FoveHeadset;
- const TSharedRef<Fove::IFVRCompositor, ESPMode::ThreadSafe> FoveCompositor;
- Fove::SFVR_CompositorLayer FoveCompositorLayer;
- IRendererModule* RendererModule = nullptr;
- bool bHmdEnabled = true;
- bool bStereoEnabled = false;
- int32 WindowMirrorMode = 2;
-
-
-
- TRefCountPtr<FoveRenderingBridge>& Bridge;
- };
|