284 lines
8.4 KiB
C++
284 lines
8.4 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 <memory>
|
|
#include <vector>
|
|
|
|
#include "Containers/UnrealString.h"
|
|
#include "Math/Quat.h"
|
|
#include "Math/Vector.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
#include "Templates/SharedPointer.h"
|
|
#include "Templates/UniquePtr.h"
|
|
|
|
#include "SGBuildHacks/SGPlatform.h"
|
|
#include "SGCoreImpl/SGHapticGloveImpl.h"
|
|
|
|
namespace SGCore
|
|
{
|
|
namespace Nova
|
|
{
|
|
class Nova2Glove;
|
|
}
|
|
}
|
|
|
|
class FSGBasicHandModelImpl;
|
|
class FSGHandInterpolatorImpl;
|
|
class FSGHandPoseImpl;
|
|
class FSGNova2GloveHandProfileImpl;
|
|
class FSGNova2GloveSensorDataImpl;
|
|
class FSGNovaGloveInfoImpl;
|
|
class FSGSensorNormalizationImpl;
|
|
|
|
class SENSEGLOVECOREIMPL_API FSGNova2GloveImpl final : public FSGHapticGloveImpl
|
|
{
|
|
#if ENGINE_MAJOR_VERSION >= 5
|
|
friend class SharedPointerInternals::TIntrusiveReferenceController<FSGNova2GloveImpl, ESPMode::ThreadSafe>;
|
|
#else
|
|
friend class SharedPointerInternals::TIntrusiveReferenceController<FSGNova2GloveImpl>;
|
|
#endif /* ENGINE_MAJOR_VERSION >= 5 */
|
|
|
|
public:
|
|
typedef SGCore::Nova::Nova2Glove FNova2GloveType;
|
|
|
|
typedef std::vector<FNova2GloveType> FNova2GloveVectorType;
|
|
|
|
typedef std::shared_ptr<FNova2GloveType> FNova2GlovePtrType;
|
|
typedef std::vector<FNova2GlovePtrType> FNova2GlovePtrVectorType;
|
|
|
|
public:
|
|
static TSharedRef<FSGDeviceImpl> Parse(const FString& ConstantsString);
|
|
|
|
static TArray<FSGNova2GloveImpl> GetNova2Gloves();
|
|
|
|
static bool GetNova2Glove(FSGNova2GloveImpl& OutGlove);
|
|
|
|
static bool GetNova2Glove(bool bRightHanded, FSGNova2GloveImpl& OutGlove);
|
|
|
|
public:
|
|
static void CalculateGloveLocation(
|
|
const FVector& ReferencePosition, const FQuat& ReferenceRotation,
|
|
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded, const FString& HardwareVersion,
|
|
FVector& OutGlovePosition, FQuat& OutGloveRotation);
|
|
|
|
static void CalculateWristLocation(
|
|
const FVector& ReferencePosition, const FQuat& ReferenceRotation,
|
|
ESGPositionalTrackingHardware TrackingHardware, bool bRightHanded, const FString& HardwareVersion,
|
|
FVector& OutWristPosition, FQuat& OutWristRotation);
|
|
|
|
public:
|
|
static ANSICHAR GetStreamByte();
|
|
|
|
static const TArray<float>& GetNova2SensorRanges();
|
|
|
|
public:
|
|
static TArray<float> ToNormalizedValues(const FSGNova2GloveSensorDataImpl& SensorData);
|
|
|
|
static TArray<float> ToNormalizedValues(
|
|
const FSGNova2GloveSensorDataImpl& SensorData, FSGSensorNormalizationImpl& OutSensorNormalizer);
|
|
|
|
public:
|
|
static TArray<TArray<FVector>> CalculateHandAngles(
|
|
const TArray<float>& NormalizedValues, const FSGHandInterpolatorImpl& Interpolator, bool bInfluenceIndex);
|
|
|
|
static TArray<TArray<FVector>> ToNormalizedAngles(
|
|
const TArray<float>& NormalizedData, const FSGNovaGloveInfoImpl& GloveInfo);
|
|
|
|
private:
|
|
struct FImpl;
|
|
|
|
struct FImplDeleter
|
|
{
|
|
void operator()(const FImpl* P) const;
|
|
};
|
|
|
|
TUniquePtr<FImpl, FImplDeleter> Pimpl;
|
|
FImplDeleter PimplDeleter;
|
|
|
|
public:
|
|
FSGNova2GloveImpl();
|
|
|
|
explicit FSGNova2GloveImpl(const FSGNovaGloveInfoImpl& DeviceInfo);
|
|
|
|
public:
|
|
/**
|
|
* The cast from underlying type constructor.
|
|
*/
|
|
explicit FSGNova2GloveImpl(const FNova2GloveType Nova2Glove);
|
|
|
|
/**
|
|
* The cast from underlying pointer type constructor.
|
|
*/
|
|
explicit FSGNova2GloveImpl(const FNova2GlovePtrType Nova2Glove);
|
|
|
|
public:
|
|
/**
|
|
* The copy constructor.
|
|
*/
|
|
FSGNova2GloveImpl(const FSGNova2GloveImpl& Rhs);
|
|
|
|
/**
|
|
* The move constructor.
|
|
*/
|
|
FSGNova2GloveImpl(FSGNova2GloveImpl&& Rhs) SG_NOEXCEPT;
|
|
|
|
public:
|
|
/**
|
|
* The destructor.
|
|
*/
|
|
virtual ~FSGNova2GloveImpl() override;
|
|
|
|
public:
|
|
/**
|
|
* The copy assignment operator.
|
|
*/
|
|
FSGNova2GloveImpl& operator=(const FSGNova2GloveImpl& Rhs);
|
|
|
|
/**
|
|
* The move assignment operator.
|
|
*/
|
|
FSGNova2GloveImpl& operator=(FSGNova2GloveImpl&& Rhs) SG_NOEXCEPT;
|
|
|
|
public:
|
|
/**
|
|
* The cast to underlying type method.
|
|
*/
|
|
const FNova2GloveType& ToNova2Glove() const;
|
|
|
|
/**
|
|
* The cast to underlying pointer type method.
|
|
*/
|
|
FNova2GlovePtrType ToNova2GlovePtr() const;
|
|
|
|
/**
|
|
* The checked cast to underlying pointer type method.
|
|
*/
|
|
FNova2GlovePtrType ToNova2GlovePtrChecked() const;
|
|
|
|
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:
|
|
virtual bool IsRight() const override;
|
|
|
|
virtual bool GetImuRotation(FQuat& OutImu) override;
|
|
|
|
virtual bool GetHandPose(const FSGBasicHandModelImpl& HandGeometry, FSGHandPoseImpl& OutHandPose) const override;
|
|
|
|
virtual bool GetHandAngles(TArray<TArray<FVector>>& OutHandAngles) const override;
|
|
|
|
public:
|
|
virtual ESGHapticGloveCalibrationState GetCalibrationState() const override;
|
|
|
|
virtual void EndCalibration() override;
|
|
|
|
virtual void ResetCalibration() override;
|
|
|
|
public:
|
|
virtual void StopHaptics() override;
|
|
|
|
virtual void StopVibrations() override;
|
|
|
|
virtual bool SendHaptics() override;
|
|
|
|
public:
|
|
virtual bool SupportsCustomWaveform(ESGHapticLocation AtLocation) const override;
|
|
|
|
virtual bool SendCustomWaveform(FSGCustomWaveformImpl& OutWaveform, ESGHapticLocation Location) override;
|
|
|
|
public:
|
|
virtual bool QueueForceFeedbackLevels(const TArray<float>& Levels01) override;
|
|
|
|
virtual bool QueueForceFeedbackLevel(int32 Finger, float Level01) override;
|
|
|
|
virtual bool QueueSqueezeLevel(float SqueezeLevel01);
|
|
|
|
public:
|
|
virtual void GetGloveLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
|
|
ESGPositionalTrackingHardware TrackingHardware,
|
|
FVector& OutGlovePosition, FQuat& OutGloveRotation) const override;
|
|
|
|
virtual void GetWristLocation(const FVector& ReferencePosition, const FQuat& ReferenceRotation,
|
|
ESGPositionalTrackingHardware TrackingHardware,
|
|
FVector& OutWristPosition, FQuat& OutWristRotation) const override;
|
|
|
|
public:
|
|
FSGNovaGloveInfoImpl GetGloveInfo() const;
|
|
|
|
bool DoesIndexInfluenceOthers() const;
|
|
|
|
void SetIndexInfluencesOthers(bool bInfluenceOthers);
|
|
|
|
bool SupportsOnBoardNormalization() const;
|
|
|
|
public:
|
|
bool GetSensorData(FSGNova2GloveSensorDataImpl& OutSensorData) const;
|
|
|
|
bool GetNormalizedInput(TArray<float>& OutNormalizedValues) const;
|
|
|
|
virtual bool SendRawData();
|
|
|
|
virtual bool SendNormalizedData();
|
|
|
|
public:
|
|
virtual ESGNova2VibroMotor ToNovaMotor(ESGHapticLocation Location) const;
|
|
|
|
virtual int32 ChannelIndex(ESGNova2VibroMotor Motor) const;
|
|
|
|
virtual void ValidateWaveform(FSGCustomWaveformImpl& OutWaveform, ESGNova2VibroMotor Motor) const;
|
|
|
|
virtual bool SendCustomWaveform_Nova2(FSGCustomWaveformImpl& OutWaveform, ESGNova2VibroMotor Motor,
|
|
bool bValidateWaveform = true);
|
|
|
|
public:
|
|
virtual FString ToString() const override;
|
|
}; |