Files
Plugin/Source/SenseGloveCore/Public/SGCore/SGNovaGlove.h
T

270 lines
9.6 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 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 "SGHapticGlove.h"
#include "Containers/Array.h"
#include "HAL/Platform.h"
#include "Math/Quat.h"
#include "Math/Vector.h"
#include "SGCore/SGBasicHandModel.h"
#include "SGCore/SGHandPose.h"
#include "SGCore/SGHandProfile.h"
#include "SGCore/SGHapticGlove.h"
#include "SGCore/SGNovaGloveSensorData.h"
#include "SGTypes/SGCoreTypes.h"
#include "SGNovaGlove.generated.h"
class FSGNovaGloveImpl;
class USGBuzzCommand;
class USGForceFeedbackCommand;
class USGThumperCommand;
UCLASS(BlueprintType)
class SENSEGLOVECORE_API USGNovaGlove final : public USGHapticGlove
{
GENERATED_BODY()
public:
static USGNovaGlove* NewNovaGlove(UObject* Outer, const FSGNovaGloveImpl& NovaGloveImpl);
static USGNovaGlove* NewNovaGlove(UObject* Outer, TSharedRef<FSGNovaGloveImpl> NovaGloveImpl);
public:
static USGNovaGlove* NewNovaGlove(UObject* Outer);
static USGNovaGlove* NewNovaGlove(UObject* Outer, const USGNovaGloveInfo& DeviceInfo);
public:
static ANSICHAR GetHapticsByte();
static FVector GetMinCalibrationRange();
public:
static USGHandPose* CalculateHandPose(UObject* Outer,
const USGBasicHandModel* HandModel,
const USGNovaGloveSensorData* NovaData,
const USGNovaGloveHandProfile* Profile);
public:
static USGDevice* Parse(UObject* Outer, const FString& ConstantsString);
static TArray<USGNovaGlove*> GetNovaGloves(UObject* Outer);
static bool GetNovaGlove(UObject* Outer, USGNovaGlove*& OutGlove);
static bool GetNovaGlove(UObject* Outer, bool bRightHanded, USGNovaGlove*& OutGlove);
public:
static TArray<FVector> GetCalibrationValues(const USGNovaGloveSensorData* SensorData);
static void CalibrateInterpolation(UObject* Outer,
const TArray<FVector>& MinValues, const TArray<FVector>& MaxValues,
USGNovaGloveHandProfile*& OutProfile);
public:
static void CalculateGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutGlovePosition, FQuat& OutGloveRotation);
static void CalculateGloveLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutGlovePosition, FRotator& OutGloveRotation);
static void CalculateWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutWristPosition, FQuat& OutWristRotation);
static void CalculateWristLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded,
FVector& OutWristPosition, FRotator& OutWristRotation);
public:
static FString ToBytes(const USGThumperCommand* ThumperCommand);
static FString ToBytes(const USGForceFeedbackCommand* ForceFeedbackCommand);
static FString ToBytes(const USGBuzzCommand* BuzzCommand);
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
protected:
USGNovaGlove();
explicit USGNovaGlove(const USGNovaGloveInfo& DeviceInfo);
public:
/**
* The cast from underlying parent type constructor.
*/
explicit USGNovaGlove(const FSGDeviceImpl& SGDeviceImpl);
/**
* The cast from underlying parent type constructor.
*/
explicit USGNovaGlove(const FSGHapticGloveImpl& HapticGloveImpl);
/**
* The cast from underlying type constructor.
*/
explicit USGNovaGlove(const FSGNovaGloveImpl& NovaGloveImpl);
protected:
/**
* The cast from underlying parent pointer type constructor.
*/
explicit USGNovaGlove(TSharedRef<FSGDeviceImpl> SGDeviceImpl);
/**
* The cast from underlying parent pointer type constructor.
*/
explicit USGNovaGlove(TSharedRef<FSGHapticGloveImpl> HapticGloveImpl);
/**
* The cast from underlying pointer type constructor.
*/
explicit USGNovaGlove(TSharedRef<FSGNovaGloveImpl> NovaGloveImpl);
public:
/**
* The destructor.
*/
virtual ~USGNovaGlove() override;
public:
/**
* The cast to underlying type method.
*/
TSharedRef<FSGNovaGloveImpl> ToNovaGloveImpl() const;
protected:
/**
* Allows the child classes to synchronize the parent's underlying object at any time.
*/
virtual void SyncImplObject() const override;
/**
* Allows the child classes to synchronize the parent's uproperties at any time.
*/
virtual void SyncUProperties() override;
public:
virtual ESGDeviceType GetDeviceType() const override;
virtual FString GetDeviceId() const override;
virtual FString GetHardwareVersion() const override;
virtual int32 GetFirmwareVersion() const override;
virtual int32 GetSubFirmwareVersion() const override;
public:
virtual bool HasBattery() const override;
virtual bool IsCharging() override;
virtual bool GetBatteryLevel(float& OutBatteryLevel) override;
public:
bool GetSensorData(UObject* Outer, USGNovaGloveSensorData*& OutSensorData);
virtual bool GetImuRotation(FQuat& OutImu) override;
virtual bool GetImuRotation(FRotator& OutImu) override;
/// HACK
/// 'FSGNovaGlove::GetHandPose' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
/// tell the compiler we want both the GetHandPose from FSGHapticGlove and FSGNovaGlove
using USGHapticGlove::GetHandPose;
bool GetHandPose(UObject* Outer, const USGBasicHandModel* HandModel, const USGNovaGloveHandProfile* Profile,
USGHandPose*& OutHandPose);
virtual bool GetHandPose(UObject* Outer, const USGBasicHandModel* HandGeometry, const USGHandProfile* HandProfile,
USGHandPose*& OutHandPose) override;
virtual bool GetHandPose(UObject* Outer, const USGHandProfile* HandProfile, USGHandPose*& OutHandPose) override;
public:
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand,
const USGBuzzCommand* BuzzCommand,
const USGThumperCommand* ThumperCommand) override;
virtual void SendHaptics(const USGForceFeedbackCommand* ForceFeedbackCommand) override;
virtual void SendHaptics(const USGBuzzCommand* BuzzCommand) override;
virtual void SendHaptics(const USGThumperCommand* ThumperCommand) override;
public:
virtual bool GetCalibrationValues(TArray<FVector>& OutValues) override;
virtual void ApplyCalibration(UObject* Outer, USGHandProfile*& OutProfile) const override;
void ApplyCalibration(UObject* Outer, USGNovaGloveHandProfile*& OutProfile) const;
public:
virtual void GetGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FQuat& OutGloveRotation) const override;
virtual void GetGloveLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FRotator& OutGloveRotation) const override;
virtual void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FQuat& OutWristRotation) const override;
virtual void GetWristLocation(const FVector& ReferencePosition, const FRotator& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FRotator& OutWristRotation) const override;
public:
virtual FString ToString() const override;
};