Files
Plugin/Source/SenseGloveTracking/Public/SGTracking/SGXRTracker.h
T

186 lines
7.2 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2024 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#pragma once
#include "HeadMountedDisplayTypes.h"
#include "IHandTracker.h"
#include "IInputDevice.h"
#include "IOpenXRExtensionPlugin.h"
#include "Math/MathFwd.h"
#include "Runtime/Launch/Resources/Version.h"
#include "Templates/UniquePtr.h"
#include "UObject/NameTypes.h"
#include "XRMotionControllerBase.h"
#include "SGBuildHacks/SGPlatform.h"
struct SENSEGLOVETRACKING_API FSGXRHandState;
class SENSEGLOVETRACKING_API FSGXRTracker final : public IOpenXRExtensionPlugin,
public IInputDevice,
public FXRMotionControllerBase,
public IHandTracker
{
public:
UE_DEPRECATED(5.5, "Deprecated by UE 5.5 in favor of GetMotionControllerState and GetHandTrackingState")
static bool GetMotionControllerData(
UObject* WorldContextObject,
EControllerHand Hand,
FXRMotionControllerData& OutMotionControllerData);
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
static bool GetMotionControllerState(
UObject* WorldContextObject,
EXRSpaceType XRSpaceType, EControllerHand Hand, EXRControllerPoseType XRControllerPoseType,
FXRMotionControllerState& OutMotionControllerState);
static bool GetHandTrackingState(
UObject* WorldContextObject,
EXRSpaceType XRSpaceType, EControllerHand Hand,
FXRHandTrackingState& OutHandTrackingState);
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
private:
FSGXRTracker() = delete;
public:
FSGXRTracker(const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler);
public:
/**
* The copy constructor.
*/
FSGXRTracker(const FSGXRTracker& Rhs) = delete;
/**
* The move constructor.
*/
FSGXRTracker(FSGXRTracker&& Rhs) SG_NOEXCEPT;
public:
/**
* The destructor.
*/
virtual ~FSGXRTracker() override;
public:
/**
* The copy assignment operator.
*/
FSGXRTracker& operator=(const FSGXRTracker& Rhs) = delete;
/**
* The move assignment operator.
*/
FSGXRTracker& operator=(FSGXRTracker&& Rhs) SG_NOEXCEPT;
public:
bool IsHandTrackingSupportedByDevice() const;
const FSGXRHandState& GetLeftHandState() const;
const FSGXRHandState& GetRightHandState() const;
public:
// The IOpenXRExtensionPlugin interface.
virtual FString GetDisplayName() override;
virtual bool GetRequiredExtensions(TArray<const ANSICHAR*>& OutExtensions) override;
virtual const void* OnGetSystem(XrInstance InInstance, const void* InNext) override;
virtual const void* OnCreateSession(XrInstance InInstance, XrSystemId InSystem, const void* InNext) override;
virtual const void* OnBeginSession(XrSession InSession, const void* InNext) override;
virtual void UpdateDeviceLocations(XrSession InSession, XrTime DisplayTime, XrSpace TrackingSpace) override;
public:
// The IMotionController interface.
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 3
virtual bool GetControllerOrientationAndPosition(const int32 ControllerIndex, const FName MotionSource,
FRotator& OutOrientation, FVector& OutPosition,
float WorldToMetersScale) const override;
virtual ETrackingStatus GetControllerTrackingStatus(const int32 ControllerIndex,
const FName MotionSource) const override;
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 3 */
virtual bool GetControllerOrientationAndPosition(const int32 ControllerIndex, const EControllerHand DeviceHand,
FRotator& OutOrientation, FVector& OutPosition,
float WorldToMetersScale) const override;
virtual ETrackingStatus GetControllerTrackingStatus(const int32 ControllerIndex,
const EControllerHand DeviceHand) const override;
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 3 */
virtual FName GetMotionControllerDeviceTypeName() const override;
virtual void EnumerateSources(TArray<FMotionControllerSource>& SourcesOut) const override;
public:
// The IInputDevice interface.
virtual void Tick(float DeltaTime) override;
virtual void SendControllerEvents() override;
virtual void SetMessageHandler(const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler) override;
virtual bool Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar) override;
virtual void SetChannelValue(int32 ControllerId, FForceFeedbackChannelType ChannelType, float Value) override;
virtual void SetChannelValues(int32 ControllerId, const FForceFeedbackValues& Values) override;
virtual bool SupportsForceFeedback(int32 ControllerId) override;
virtual bool IsGamepadAttached() const override;
public:
// The IHandTracker interface.
virtual FName GetHandTrackerDeviceTypeName() const override;
virtual bool IsHandTrackingStateValid() const override;
virtual bool GetKeypointState(
EControllerHand Hand,
EHandKeypoint Keypoint, FTransform& OutTransform, float& OutRadius) const override;
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5
virtual bool GetAllKeypointStates(
EControllerHand Hand,
TArray<FVector>& OutPositions, TArray<FQuat>& OutRotations, TArray<float>& OutRadii,
bool& OutIsTracked) const override;
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
virtual bool GetAllKeypointStates(
EControllerHand Hand,
TArray<FVector>& OutPositions, TArray<FQuat>& OutRotations, TArray<float>& OutRadii) const override;
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 5 */
};