Files
Plugin/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGSenseGloveImpl.h
T

288 lines
10 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 <memory>
#include <vector>
#include "Math/Quat.h"
#include "Math/Vector.h"
#include "Runtime/Launch/Resources/Version.h"
#include "Templates/SharedPointer.h"
#include "Templates/UniquePtr.h"
#include "SGCoreImpl/SGHapticGloveImpl.h"
#include "SGTypes/SGCoreTypes.h"
namespace SGCore
{
namespace SG
{
class SenseGlove;
}
}
class FSGBasicHandModelImpl;
class FSGBuzzCommandImpl;
class FSGForceFeedbackCommandImpl;
class FSGHandPoseImpl;
class FSGHandProfileImpl;
class FSGSenseGloveHandProfileImpl;
class FSGSenseGloveInfoImpl;
class FSGSenseGlovePoseImpl;
class FSGSenseGloveSensorDataImpl;
class FSGThumperCommandImpl;
class SENSEGLOVECOREIMPL_API FSGSenseGloveImpl final : public FSGHapticGloveImpl
{
#if ENGINE_MAJOR_VERSION >= 5
friend class SharedPointerInternals::TIntrusiveReferenceController<FSGSenseGloveImpl, ESPMode::ThreadSafe>;
#else
friend class SharedPointerInternals::TIntrusiveReferenceController<FSGSenseGloveImpl>;
#endif /* ENGINE_MAJOR_VERSION >= 5 */
public:
typedef SGCore::SG::SenseGlove FSenseGloveType;
typedef std::vector<FSenseGloveType> FSenseGloveVectorType;
typedef std::shared_ptr<FSenseGloveType> FSenseGlovePtrType;
typedef std::vector<FSenseGlovePtrType> FSenseGlovePtrVectorType;
public:
static ANSICHAR GetHapticsByte();
static ANSICHAR GetThumperByte();
public:
static FSGSenseGlovePoseImpl CalculateGlovePose(const FSGSenseGloveSensorDataImpl& SensorData,
const FSGSenseGloveInfoImpl& GloveModel);
static FSGSenseGlovePoseImpl CalculateGlovePose(const TArray<TArray<FVector>>& GloveAngles,
const FSGSenseGloveInfoImpl& GloveModel);
static FSGHandPoseImpl CalculateHandPose(const FSGSenseGlovePoseImpl& GlovePose,
const FSGBasicHandModelImpl& HandModel,
const FSGSenseGloveHandProfileImpl& Profile);
public:
static TSharedRef<FSGDeviceImpl> Parse(const FString& ConstantsString);
static TArray<FSGSenseGloveImpl> GetSenseGloves();
static bool GetSenseGlove(FSGSenseGloveImpl& OutGlove);
static bool GetSenseGlove(bool bRightHanded, FSGSenseGloveImpl& OutGlove);
public:
static TArray<FVector> GetCalibrationValues(const FSGSenseGlovePoseImpl& GlovePose);
static void CalibrateInterpolation(const TArray<FVector>& MinValues, const TArray<FVector>& MaxValues,
bool bRightHanded, FSGSenseGloveHandProfileImpl& OutProfile);
public:
static void CalculateGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
bool bRightHanded, ESGFinger MountedOn,
FVector& OutGlovePosition, FQuat& OutGloveRotation);
static void CalculateWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
bool bRightHanded, ESGFinger MountedOn,
const FVector& GloveWristPositionOffset,
const FQuat& GloveWristRotationOffset,
FVector& OutWristPosition, FQuat& OutWristRotation);
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
public:
FSGSenseGloveImpl();
explicit FSGSenseGloveImpl(const FSGSenseGloveInfoImpl& Model);
public:
/**
* The cast from underlying type constructor.
*/
explicit FSGSenseGloveImpl(const FSenseGloveType SenseGlove);
/**
* The cast from underlying pointer type constructor.
*/
explicit FSGSenseGloveImpl(const FSenseGlovePtrType SenseGlove);
public:
/**
* The copy constructor.
*/
FSGSenseGloveImpl(const FSGSenseGloveImpl& Rhs);
/**
* The move constructor.
*/
FSGSenseGloveImpl(FSGSenseGloveImpl&& Rhs) noexcept;
public:
/**
* The destructor.
*/
virtual ~FSGSenseGloveImpl() override;
public:
/**
* The copy assignment operator.
*/
FSGSenseGloveImpl& operator=(const FSGSenseGloveImpl& Rhs);
/**
* The move assignment operator.
*/
FSGSenseGloveImpl& operator=(FSGSenseGloveImpl&& Rhs) noexcept;
public:
/**
* The cast to underlying type method.
*/
const FSenseGloveType& ToSenseGlove() const;
/**
* The cast to underlying pointer type method.
*/
FSenseGlovePtrType ToSenseGlovePtr() const;
/**
* The checked cast to underlying pointer type method.
*/
FSenseGlovePtrType ToSenseGlovePtrChecked() const;
public:
FSGSenseGloveInfoImpl GetGloveModel() const;
virtual bool IsRight() const 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:
bool GetSensorData(FSGSenseGloveSensorDataImpl& OutSensorData) const;
virtual bool GetImuRotation(FQuat& OutImu) override;
bool GetGlovePose(FSGSenseGlovePoseImpl& OutGlovePose);
bool GetGlovePose(const FSGSenseGloveSensorDataImpl& SensorData, FSGSenseGlovePoseImpl& OutGlovePose);
/// HACK
/// 'FSGSenseGloveImpl::GetHandPose' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
/// tell the compiler we want both the GetHandPose from FSGHapticGloveImpl and FSGSenseGloveImpl
using FSGHapticGloveImpl::GetHandPose;
bool GetHandPose(const FSGBasicHandModelImpl& HandModel, const FSGSenseGloveHandProfileImpl& Profile,
FSGHandPoseImpl& OutHandPose);
virtual bool GetHandPose(const FSGBasicHandModelImpl& HandGeometry, const FSGHandProfileImpl& HandProfile,
FSGHandPoseImpl& OutHandPose) override;
virtual bool GetHandPose(const FSGHandProfileImpl& HandProfile, FSGHandPoseImpl& OutHandPose) override;
public:
/// HACK
/// 'FSGSenseGloveImpl::SendHaptics' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
/// tell the compiler we want both the SendHaptics from FSGHapticGloveImpl and FSGSenseGloveImpl
using FSGHapticGloveImpl::SendHaptics;
bool SendHaptics(const FSGForceFeedbackCommandImpl& ForceFeedbackCommand,
const FSGBuzzCommandImpl& BuzzCommand,
ESGSenseGloveThumperCommand ThumperCommand = ESGSenseGloveThumperCommand::None);
bool SendHaptics(ESGSenseGloveThumperCommand ThumperCommand);
virtual void SendHaptics(const FSGForceFeedbackCommandImpl& ForceFeedbackCommand) override;
virtual void SendHaptics(const FSGBuzzCommandImpl& BuzzCommand) override;
virtual void SendHaptics(const FSGForceFeedbackCommandImpl& ForceFeedbackCommand,
const FSGBuzzCommandImpl& BuzzCommand,
const FSGThumperCommandImpl& ThumperCommand) override;
public:
virtual bool GetCalibrationValues(TArray<FVector>& OutValues) override;
virtual void ResetCalibrationRange() override;
virtual void ApplyCalibration(FSGHandProfileImpl& OutProfile) const override;
void ApplyCalibration(FSGSenseGloveHandProfileImpl& OutProfile) const;
public:
virtual void GetGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutGlovePosition, FQuat& OutGloveRotation) const override;
void GetGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware, ESGFinger MountedOn,
FVector& OutGlovePosition, FQuat& OutGloveRotation) const;
virtual void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition, FQuat& OutWristRotation) const override;
void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
ESGPositionalTrackingHardware TrackingHardware,
const FVector& GloveWristPositionOffset,
const FQuat& GloveWristRotationOffset,
FVector& OutWristPosition, FQuat& OutWristRotation) const;
public:
virtual FString ToString() const override;
};