From b683aa22af4dc5829e3fe7ec12b8d3c6654ebc5a Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Wed, 16 Nov 2022 18:49:33 +0100 Subject: [PATCH] translate senseglove/unreal angles/directions --- .../Private/SGCoreImpl/SGAnatomyImpl.cpp | 31 ++--- .../SGCoreImpl/SGHandInterpolatorImpl.cpp | 62 ++++++---- .../Private/SGCoreImpl/SGHandPoseImpl.cpp | 16 +-- .../SGHapticGloveCalibrationCheckImpl.cpp | 9 +- .../SGCoreImpl/SGJointKinematicsImpl.cpp | 6 +- .../SGCoreImpl/SGNovaGloveCalibrationImpl.cpp | 6 +- .../Private/SGCoreImpl/SGNovaGloveImpl.cpp | 2 +- .../Private/SGCoreImpl/SGSenseGloveImpl.cpp | 3 +- .../SGCoreImpl/SGSenseGloveInfoImpl.cpp | 8 +- .../SGCoreImpl/SGSenseGlovePoseImpl.cpp | 61 +++++---- .../Public/SGCoreImpl/SGNovaGloveImpl.h | 2 +- .../Private/SGUtils/SGCoordinates.cpp | 0 .../Public/SGUtils/SGArrayUtils.h | 55 ++++++++ .../Public/SGUtils/SGCoordinates.h | 117 ++++++++++++++++++ .../SenseGloveUtils/SenseGloveUtils.Build.cs | 3 +- 15 files changed, 283 insertions(+), 98 deletions(-) create mode 100644 Source/SenseGloveUtils/Private/SGUtils/SGCoordinates.cpp create mode 100644 Source/SenseGloveUtils/Public/SGUtils/SGCoordinates.h diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGAnatomyImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGAnatomyImpl.cpp index 05007dfb..5a00a2f0 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGAnatomyImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGAnatomyImpl.cpp @@ -39,6 +39,7 @@ #include "SGBuildHacks/SGInclude_Core_Vect3D.h" #include "SGCoreImpl/SGVect3DImpl.h" #include "SGUtils/SGArrayUtils.h" +#include "SGUtils/SGCoordinates.h" float FSGAnatomyImpl::GetTotalFingerFlexion() { @@ -63,13 +64,15 @@ float FSGAnatomyImpl::GetTotalThumbExtension() float FSGAnatomyImpl::GetFingerJointLimit( const bool bRightHanded, const int32 Joint, const int32 Movement, const bool bMax) { - return FAnatomyType::GetFingerJointLimit(bRightHanded, Joint, Movement, bMax); + return FSGCoordinates::TransformToUnreal( + Movement, FAnatomyType::GetFingerJointLimit(bRightHanded, Joint, Movement, bMax)); } float FSGAnatomyImpl::GetThumbJointLimit( const bool bRightHanded, const int32 Joint, const int32 Movement, const bool bMax) { - return FAnatomyType::GetThumbJointLimit(bRightHanded, Joint, Movement, bMax); + return FSGCoordinates::TransformToUnreal( + Movement, FAnatomyType::GetThumbJointLimit(bRightHanded, Joint, Movement, bMax)); } float FSGAnatomyImpl::NormalizeFingerFlexion(const float FlexionInRadians) @@ -85,35 +88,35 @@ float FSGAnatomyImpl::NormalizeThumbFlexion(const float FlexionInRadians) TArray> FSGAnatomyImpl::GetDefaultHandAngles(const bool bRightHanded) { TArray> DefaultHandAngles{ - FSGArrayUtils::FromStdVector( - FAnatomyType::GetDefaultHandAngles(bRightHanded)) + FSGArrayUtils::FromSenseGloveAngles( + FAnatomyType::GetDefaultHandAngles(bRightHanded)) }; - return DefaultHandAngles; + return MoveTemp(DefaultHandAngles); } TArray> FSGAnatomyImpl::GetFlatHandAngles(const bool bRightHanded) { TArray> FlatHandAngles{ - FSGArrayUtils::FromStdVector( - FAnatomyType::GetFlatHandAngles(bRightHanded)) + FSGArrayUtils::FromSenseGloveAngles( + FAnatomyType::GetFlatHandAngles(bRightHanded)) }; - return FlatHandAngles; + return MoveTemp(FlatHandAngles); } TArray> FSGAnatomyImpl::GetThumbsUpHandAngles(const bool bRightHanded) { TArray> ThumbsUpHandAngles{ - FSGArrayUtils::FromStdVector( - FAnatomyType::GetThumbsUpHandAngles(bRightHanded)) + FSGArrayUtils::FromSenseGloveAngles( + FAnatomyType::GetThumbsUpHandAngles(bRightHanded)) }; - return ThumbsUpHandAngles; + return MoveTemp(ThumbsUpHandAngles); } TArray> FSGAnatomyImpl::GetFistHandAngles(const bool bRightHanded) { TArray> FistHandAngles{ - FSGArrayUtils::FromStdVector( - FAnatomyType::GetFistHandAngles(bRightHanded)) + FSGArrayUtils::FromSenseGloveAngles( + FAnatomyType::GetFistHandAngles(bRightHanded)) }; - return FistHandAngles; + return MoveTemp(FistHandAngles); } \ No newline at end of file diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandInterpolatorImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandInterpolatorImpl.cpp index 9875abc0..7714ba73 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandInterpolatorImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandInterpolatorImpl.cpp @@ -49,6 +49,7 @@ #include "SGCoreImpl/SGQuatImpl.h" #include "SGCoreImpl/SGVect3DImpl.h" #include "SGUtils/SGArrayUtils.h" +#include "SGUtils/SGCoordinates.h" struct FSGHandInterpolatorImpl::FImpl { @@ -81,53 +82,53 @@ struct FSGHandInterpolatorImpl::FImpl FSGHandInterpolatorImpl FSGHandInterpolatorImpl::Default(const bool bRightHanded) { - const FSGHandInterpolatorImpl HandInterpolatorImpl(FHandInterpolatorType::Default(bRightHanded)); - return HandInterpolatorImpl; + FSGHandInterpolatorImpl HandInterpolatorImpl(FHandInterpolatorType::Default(bRightHanded)); + return MoveTemp(HandInterpolatorImpl); } FSGHandInterpolatorImpl FSGHandInterpolatorImpl::Deserialize(const FString& SerializedString) { std::string Serialized(TCHAR_TO_UTF8(*SerializedString)); - const FSGHandInterpolatorImpl GlovePose(FHandInterpolatorType::Deserialize(MoveTemp(Serialized))); - return GlovePose; + FSGHandInterpolatorImpl GlovePose(FHandInterpolatorType::Deserialize(MoveTemp(Serialized))); + return MoveTemp(GlovePose); } TArray FSGHandInterpolatorImpl::InterpolateFingerAngles( - ESGFinger Finger, const FSGHandInterpolatorImpl& Interpolator, const FVector& TotalGloveAngles) + const ESGFinger Finger, const FSGHandInterpolatorImpl& Interpolator, const FVector& TotalGloveAngles) { - const TArray Angles{ - FSGArrayUtils::FromStdVector( + TArray Angles{ + FSGArrayUtils::FromSenseGloveAngles( FHandInterpolatorType::InterpolateFingerAngles( FSGCoreEnumCast::ToEFinger(Finger), Interpolator.ToHandInterpolator(), - FSGVect3DImpl(TotalGloveAngles).ToVect3D())) + FSGCoordinates::TransformToSenseGlove(TotalGloveAngles))) }; - return Angles; + return MoveTemp(Angles); } TArray FSGHandInterpolatorImpl::InterpolateThumbAngles(const FSGHandInterpolatorImpl& Interpolator, const FVector& TotalGloveAngles) { - const TArray Angles{ - FSGArrayUtils::FromStdVector( + TArray Angles{ + FSGArrayUtils::FromSenseGloveAngles( FHandInterpolatorType::InterpolateThumbAngles( - Interpolator.ToHandInterpolator(), FSGVect3DImpl(TotalGloveAngles).ToVect3D())) + Interpolator.ToHandInterpolator(), + FSGCoordinates::TransformToSenseGlove(TotalGloveAngles))) }; - return Angles; + return MoveTemp(Angles); } TArray> FSGHandInterpolatorImpl::InterpolateHandAngles(const FSGHandInterpolatorImpl& Interpolator, const TArray& TotalAngles) { std::vector TotalAnglesVector{ - FSGArrayUtils::ToStdVector( - TotalAngles) + FSGArrayUtils::ToSenseGloveAngles(TotalAngles) }; - const TArray> Angles{ - FSGArrayUtils::FromStdVector( + TArray> Angles{ + FSGArrayUtils::FromSenseGloveAngles( FHandInterpolatorType::InterpolateHandAngles( Interpolator.ToHandInterpolator(), MoveTemp(TotalAnglesVector))) }; - return Angles; + return MoveTemp(Angles); } FSGHandInterpolatorImpl::FSGHandInterpolatorImpl() @@ -242,28 +243,33 @@ void FSGHandInterpolatorImpl::SetCmcStartRotation(const FQuat& CmcStartRotation) float FSGHandInterpolatorImpl::CalculateAngle(const ESGFinger Finger, const int32 Movement, const float Value) const { - return Pimpl->HandInterpolator.CalculateAngle(FSGCoreEnumCast::ToEFinger(Finger), Movement, Value); + return FSGCoordinates::TransformToUnreal( + Movement, Pimpl->HandInterpolator.CalculateAngle(FSGCoreEnumCast::ToEFinger(Finger), Movement, Value)); } float FSGHandInterpolatorImpl::CalculateAngle(const ESGFinger Finger, const ESGFingerMovement Movement, const float Value) const { - return Pimpl->HandInterpolator.CalculateAngle( - FSGCoreEnumCast::ToEFinger(Finger), FSGCoreEnumCast::ToEFingerMovement(Movement), Value); + return FSGCoordinates::TransformToUnreal( + Movement, Pimpl->HandInterpolator.CalculateAngle(FSGCoreEnumCast::ToEFinger(Finger), + FSGCoreEnumCast::ToEFingerMovement(Movement), Value)); } float FSGHandInterpolatorImpl::CalculateAngle(const ESGFinger Finger, const ESGThumbMovement Movement, const float Value) const { - return Pimpl->HandInterpolator.CalculateAngle( - FSGCoreEnumCast::ToEFinger(Finger), FSGCoreEnumCast::ToEThumbMovement(Movement), Value); + return FSGCoordinates::TransformToUnreal( + Movement, Pimpl->HandInterpolator.CalculateAngle(FSGCoreEnumCast::ToEFinger(Finger), + FSGCoreEnumCast::ToEThumbMovement(Movement), Value)); } void FSGHandInterpolatorImpl::SetInterpolation( const int32 Finger, const int32 Movement, const float InputAt0, const float InputAt1, const float AngleAt0, const float AngleAt1) { - Pimpl->HandInterpolator.SetInterpolation(Finger, Movement, InputAt0, InputAt1, AngleAt0, AngleAt1); + Pimpl->HandInterpolator.SetInterpolation(Finger, Movement, InputAt0, InputAt1, + FSGCoordinates::TransformToUnreal(Movement, AngleAt0), + FSGCoordinates::TransformToUnreal(Movement, AngleAt1)); } void FSGHandInterpolatorImpl::SetInterpolation( @@ -272,7 +278,9 @@ void FSGHandInterpolatorImpl::SetInterpolation( { Pimpl->HandInterpolator.SetInterpolation( FSGCoreEnumCast::ToEFinger(Finger), FSGCoreEnumCast::ToEFingerMovement(Movement), - InputAt0, InputAt1, AngleAt0, AngleAt1); + InputAt0, InputAt1, + FSGCoordinates::TransformToUnreal(Movement, AngleAt0), + FSGCoordinates::TransformToUnreal(Movement, AngleAt1)); } void FSGHandInterpolatorImpl::SetInterpolation( @@ -280,7 +288,9 @@ void FSGHandInterpolatorImpl::SetInterpolation( const float InputAt0, const float InputAt1, const float AngleAt0, const float AngleAt1) { Pimpl->HandInterpolator.SetInterpolation(FSGCoreEnumCast::ToEThumbMovement(Movement), - InputAt0, InputAt1, AngleAt0, AngleAt1); + InputAt0, InputAt1, + FSGCoordinates::TransformToUnreal(Movement, AngleAt0), + FSGCoordinates::TransformToUnreal(Movement, AngleAt1)); } FSGInterpolationSetImpl FSGHandInterpolatorImpl::GetInterpolation(const int32 Finger, const int32 Movement) const diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandPoseImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandPoseImpl.cpp index c2e8491e..f41f3d10 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandPoseImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHandPoseImpl.cpp @@ -48,6 +48,7 @@ #include "SGCoreImpl/SGQuatImpl.h" #include "SGCoreImpl/SGVect3DImpl.h" #include "SGUtils/SGArrayUtils.h" +#include "SGUtils/SGCoordinates.h" struct FSGHandPoseImpl::FImpl { @@ -89,8 +90,7 @@ FSGHandPoseImpl FSGHandPoseImpl::FromHandAngles(const TArray>& H const FSGBasicHandModelImpl& HandDimensions) { std::vector> HandAnglesVector{ - FSGArrayUtils::ToStdVector( - HandAngles) + FSGArrayUtils::ToSenseGloveAngles(HandAngles) }; return FSGHandPoseImpl(FHandPoseType::FromHandAngles( MoveTemp(HandAnglesVector), bRightHanded, HandDimensions.ToBasicHandModel())); @@ -99,8 +99,7 @@ FSGHandPoseImpl FSGHandPoseImpl::FromHandAngles(const TArray>& H FSGHandPoseImpl FSGHandPoseImpl::FromHandAngles(const TArray>& HandAngles, const bool bRightHanded) { std::vector> HandAnglesVector{ - FSGArrayUtils::ToStdVector( - HandAngles) + FSGArrayUtils::ToSenseGloveAngles(HandAngles) }; return FSGHandPoseImpl(FHandPoseType::FromHandAngles(MoveTemp(HandAnglesVector), bRightHanded)); } @@ -173,8 +172,7 @@ FSGHandPoseImpl::FSGHandPoseImpl(const bool bRightHanded, const TArray> HandAnglesVector{ - FSGArrayUtils::ToStdVector( - HandAngles) + FSGArrayUtils::ToSenseGloveAngles(HandAngles) }; Pimpl->HandPose = FHandPoseType( @@ -271,8 +269,7 @@ void FSGHandPoseImpl::SetJointRotations(const TArray>& JointRotati TArray> FSGHandPoseImpl::GetHandAngles() const { TArray> HandAngles{ - FSGArrayUtils::FromStdVector( - Pimpl->HandPose.GetHandAngles()) + FSGArrayUtils::FromSenseGloveAngles(Pimpl->HandPose.GetHandAngles()) }; return MoveTemp(HandAngles); } @@ -280,8 +277,7 @@ TArray> FSGHandPoseImpl::GetHandAngles() const void FSGHandPoseImpl::SetHandAngles(const TArray>& HandAngles) const { std::vector> HandAnglesVector{ - FSGArrayUtils::ToStdVector( - HandAngles) + FSGArrayUtils::ToSenseGloveAngles(HandAngles) }; Pimpl->HandPose.SetHandAngles(MoveTemp(HandAnglesVector)); } diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHapticGloveCalibrationCheckImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHapticGloveCalibrationCheckImpl.cpp index 770d63cd..f7feffde 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHapticGloveCalibrationCheckImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGHapticGloveCalibrationCheckImpl.cpp @@ -46,6 +46,7 @@ #include "SGCoreImpl/SGSensorRangeImpl.h" #include "SGCoreImpl/SGVect3DImpl.h" #include "SGUtils/SGArrayUtils.h" +#include "SGUtils/SGCoordinates.h" struct FSGHapticGloveCalibrationCheckImpl::FImpl { @@ -88,6 +89,8 @@ float FSGHapticGloveCalibrationCheckImpl::GetNovaGloveThreshold() float FSGHapticGloveCalibrationCheckImpl::GetSenseGloveMinFlexion() { + /// TODO + /// Though flexion should not be translated, should we still call the translation function? return FHapticGloveCalibrationCheckType::GetSenseGloveMinFlexion(); } @@ -98,11 +101,15 @@ float FSGHapticGloveCalibrationCheckImpl::GetNovaGloveMinFlexion() float FSGHapticGloveCalibrationCheckImpl::GetSenseGloveMinAbduction() { - return FHapticGloveCalibrationCheckType::GetSenseGloveMinAbduction(); + /// TODO + /// Maybe use enums? + return FSGCoordinates::TransformToUnreal(2, FHapticGloveCalibrationCheckType::GetSenseGloveMinAbduction()); } float FSGHapticGloveCalibrationCheckImpl::GetNovaGloveMinAbduction() { + /// NOTE + /// Nova abduction translation is redundant. return FHapticGloveCalibrationCheckType::GetNovaGloveMinAbduction(); } diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGJointKinematicsImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGJointKinematicsImpl.cpp index a2b677fa..1fbd954b 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGJointKinematicsImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGJointKinematicsImpl.cpp @@ -57,8 +57,7 @@ bool FSGJointKinematicsImpl::ForwardKinematics(const FVector& StartPosition, con }; std::vector JointAnglesVector{ - FSGArrayUtils::ToStdVector( - JointAngles) + FSGArrayUtils::ToSenseGloveAngles(JointAngles) }; std::vector NewPositions; @@ -81,8 +80,7 @@ bool FSGJointKinematicsImpl::ForwardKinematics(const FSGBasicHandModelImpl& Prof TArray& OutNewPositions, TArray& OutNewRotations) { std::vector JointAnglesVector{ - FSGArrayUtils::ToStdVector( - JointAngles) + FSGArrayUtils::ToSenseGloveAngles(JointAngles) }; std::vector NewPositions; diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveCalibrationImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveCalibrationImpl.cpp index 12db49cb..5d0c1f2e 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveCalibrationImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveCalibrationImpl.cpp @@ -77,13 +77,11 @@ void FSGNovaGloveCalibrationImpl::ApplyInterpolationValues(const TArray }; std::vector> RetractedAnglesVector{ - FSGArrayUtils::ToStdVector( - RetractedAngles) + FSGArrayUtils::ToSenseGloveAngles(RetractedAngles) }; std::vector> ExtendedAnglesVector{ - FSGArrayUtils::ToStdVector( - ExtendedAngles) + FSGArrayUtils::ToSenseGloveAngles(ExtendedAngles) }; FNovaGloveCalibrationType::ApplyInterpolationValues( diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveImpl.cpp index df5e5865..6bfdb32d 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGNovaGloveImpl.cpp @@ -246,7 +246,7 @@ FSGNovaGloveImpl::FSGNovaGloveImpl() { } -FSGNovaGloveImpl::FSGNovaGloveImpl(const FSGNovaGloveInfoImpl DeviceInfo) +FSGNovaGloveImpl::FSGNovaGloveImpl(const FSGNovaGloveInfoImpl& DeviceInfo) : FSGHapticGloveImpl(FSGNovaGloveImpl(std::make_shared((DeviceInfo.ToNovaGloveInfo())))), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveImpl.cpp index a7d3d275..04ccdc5c 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveImpl.cpp @@ -119,8 +119,7 @@ FSGSenseGlovePoseImpl FSGSenseGloveImpl::CalculateGlovePose(const TArray> GloveAnglesVector{ - FSGArrayUtils::ToStdVector( - GloveAngles) + FSGArrayUtils::ToSenseGloveAngles(GloveAngles) }; FSGSenseGlovePoseImpl Pose{ FSenseGloveType::CalculateGlovePose(MoveTemp(GloveAnglesVector), GloveModel.ToSenseGloveInfo()) diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveInfoImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveInfoImpl.cpp index b0d29a63..ae094527 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveInfoImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveInfoImpl.cpp @@ -352,9 +352,13 @@ TArray FSGSenseGloveInfoImpl::GetGloveLengths(const ESGFinger Finger) c TArray> FSGSenseGloveInfoImpl::ToGloveAngles(const TArray>& SensorAngles) const { - std::vector> SensorAnglesVector{FSGArrayUtils::ToStdVector(SensorAngles)}; + /// TODO + /// Does the nested float TArray requires translation? If so, how to do that without a Movement value? + std::vector> SensorAnglesVector{ + FSGArrayUtils::ToStdVector(SensorAngles) + }; TArray> GloveAngles{ - FSGArrayUtils::FromStdVector( + FSGArrayUtils::FromSenseGloveAngles( Pimpl->SenseGloveInfo.ToGloveAngles(MoveTemp((SensorAnglesVector)))) }; return MoveTemp(GloveAngles); diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGlovePoseImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGlovePoseImpl.cpp index 9f1e9f50..f2151dae 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGlovePoseImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGlovePoseImpl.cpp @@ -81,15 +81,15 @@ struct FSGSenseGlovePoseImpl::FImpl FSGSenseGlovePoseImpl FSGSenseGlovePoseImpl::IdlePose(const FSGSenseGloveInfoImpl& GloveInfo) { - const FSGSenseGlovePoseImpl GlovePoseImpl(FSenseGlovePoseType::IdlePose(GloveInfo.ToSenseGloveInfo())); - return GlovePoseImpl; + FSGSenseGlovePoseImpl GlovePoseImpl(FSenseGlovePoseType::IdlePose(GloveInfo.ToSenseGloveInfo())); + return MoveTemp(GlovePoseImpl); } FSGSenseGlovePoseImpl FSGSenseGlovePoseImpl::Deserialize(const FString& SerializedString) { std::string Serialized(TCHAR_TO_UTF8(*SerializedString)); - const FSGSenseGlovePoseImpl GlovePose(FSenseGlovePoseType::Deserialize(MoveTemp(Serialized))); - return GlovePose; + FSGSenseGlovePoseImpl GlovePose(FSenseGlovePoseType::Deserialize(MoveTemp(Serialized))); + return MoveTemp(GlovePose); } FSGSenseGlovePoseImpl::FSGSenseGlovePoseImpl() @@ -102,7 +102,7 @@ FSGSenseGlovePoseImpl::FSGSenseGlovePoseImpl() { } -FSGSenseGlovePoseImpl::FSGSenseGlovePoseImpl(bool bRightHanded, const TArray>& JointPositions, +FSGSenseGlovePoseImpl::FSGSenseGlovePoseImpl(const bool bRightHanded, const TArray>& JointPositions, const TArray>& JointRotations, const TArray>& GloveAngles) : @@ -116,12 +116,10 @@ FSGSenseGlovePoseImpl::FSGSenseGlovePoseImpl(bool bRightHanded, const TArray(JointPositions) }; std::vector> JointRotationsVector{ - FSGArrayUtils::ToStdVector( - JointRotations) + FSGArrayUtils::ToStdVector(JointRotations) }; std::vector> GloveAnglesVector{ - FSGArrayUtils::ToStdVector( - GloveAngles) + FSGArrayUtils::ToSenseGloveAngles(GloveAngles) }; Pimpl->SenseGlovePose = FSenseGlovePoseType(bRightHanded, @@ -182,11 +180,11 @@ void FSGSenseGlovePoseImpl::SetIsRight(const bool bRightHanded) const TArray> FSGSenseGlovePoseImpl::GetJointPositions() const { - const TArray> JointPositions{ + TArray> JointPositions{ FSGArrayUtils::FromMillimeters( Pimpl->SenseGlovePose.GetJointPositions()) }; - return JointPositions; + return MoveTemp(JointPositions); } void FSGSenseGlovePoseImpl::SetJointPositions(const TArray>& JointPositions) const @@ -199,11 +197,11 @@ void FSGSenseGlovePoseImpl::SetJointPositions(const TArray>& Joi TArray> FSGSenseGlovePoseImpl::GetJointRotations() const { - const TArray> JointRotations{ + TArray> JointRotations{ FSGArrayUtils::FromStdVector( Pimpl->SenseGlovePose.GetJointRotations()) }; - return JointRotations; + return MoveTemp(JointRotations); } void FSGSenseGlovePoseImpl::SetJointRotations(const TArray>& JointRotations) const @@ -217,17 +215,17 @@ void FSGSenseGlovePoseImpl::SetJointRotations(const TArray>& Joint TArray> FSGSenseGlovePoseImpl::GetGloveAngles() const { - const TArray> GloveAngles{ - FSGArrayUtils::FromStdVector( + TArray> GloveAngles{ + FSGArrayUtils::FromSenseGloveAngles( Pimpl->SenseGlovePose.GetGloveAngles()) }; - return GloveAngles; + return MoveTemp(GloveAngles); } void FSGSenseGlovePoseImpl::SetGloveAngles(const TArray>& GloveAngles) const { std::vector> HandAnglesVector{ - FSGArrayUtils::ToStdVector( + FSGArrayUtils::ToSenseGloveAngles( GloveAngles) }; Pimpl->SenseGlovePose.SetGloveAngles(MoveTemp(HandAnglesVector)); @@ -235,39 +233,38 @@ void FSGSenseGlovePoseImpl::SetGloveAngles(const TArray>& GloveA TArray FSGSenseGlovePoseImpl::GetThimblePositions() const { - const TArray ThimblePositions{ + TArray ThimblePositions{ FSGArrayUtils::FromMillimeters( Pimpl->SenseGlovePose.GetThimblePositions()) }; - return ThimblePositions; + return MoveTemp(ThimblePositions); } TArray FSGSenseGlovePoseImpl::GetThimbleRotations() const { - const TArray ThimbleRotations{ + TArray ThimbleRotations{ FSGArrayUtils::FromStdVector( Pimpl->SenseGlovePose.GetThimbleRotations()) }; - return ThimbleRotations; + return MoveTemp(ThimbleRotations); } TArray FSGSenseGlovePoseImpl::GetTotalGloveAngles() const { - const TArray TotalGloveAngles{ - FSGArrayUtils::FromStdVector( - Pimpl->SenseGlovePose.GetTotalGloveAngles()) + TArray TotalGloveAngles{ + FSGArrayUtils::FromSenseGloveAngles(Pimpl->SenseGlovePose.GetTotalGloveAngles()) }; - return TotalGloveAngles; + return MoveTemp(TotalGloveAngles); } TArray FSGSenseGlovePoseImpl::CalculateFingerTips( const FSGSenseGloveHandProfileImpl& SenseGloveHandProfileImpl) const { - const TArray FingerTips{ + TArray FingerTips{ FSGArrayUtils::FromMillimeters( Pimpl->SenseGlovePose.CalculateFingerTips(SenseGloveHandProfileImpl.ToSenseGloveHandProfile())) }; - return FingerTips; + return MoveTemp(FingerTips); } TArray FSGSenseGlovePoseImpl::CalculateFingerTips(const TArray& FingerOffsets) const @@ -279,7 +276,7 @@ TArray FSGSenseGlovePoseImpl::CalculateFingerTips(const TArray FSGArrayUtils::FromMillimeters( Pimpl->SenseGlovePose.CalculateFingerTips(MoveTemp(FingerOffsetsVector))) }; - return FingerTips; + return MoveTemp(FingerTips); } bool FSGSenseGlovePoseImpl::Equals(const FSGSenseGlovePoseImpl& SenseGlovePoseImpl) const @@ -289,14 +286,14 @@ bool FSGSenseGlovePoseImpl::Equals(const FSGSenseGlovePoseImpl& SenseGlovePoseIm FString FSGSenseGlovePoseImpl::ToString(bool bShortFormat) const { - const FString String(UTF8_TO_TCHAR(Pimpl->SenseGlovePose.ToString(bShortFormat).c_str())); - return String; + FString String(UTF8_TO_TCHAR(Pimpl->SenseGlovePose.ToString(bShortFormat).c_str())); + return MoveTemp(String); } FString FSGSenseGlovePoseImpl::Serialize() const { - const FString Serialized(UTF8_TO_TCHAR(Pimpl->SenseGlovePose.Serialize().c_str())); - return Serialized; + FString Serialized(UTF8_TO_TCHAR(Pimpl->SenseGlovePose.Serialize().c_str())); + return MoveTemp(Serialized); } FSGSenseGlovePoseImpl::FImpl::FImpl(FSGSenseGlovePoseImpl* InOwner) diff --git a/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGNovaGloveImpl.h b/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGNovaGloveImpl.h index 9f2640d2..bd5f7c21 100644 --- a/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGNovaGloveImpl.h +++ b/Source/SenseGloveCoreImpl/Public/SGCoreImpl/SGNovaGloveImpl.h @@ -135,7 +135,7 @@ private: public: FSGNovaGloveImpl(); - explicit FSGNovaGloveImpl(const FSGNovaGloveInfoImpl DeviceInfo); + explicit FSGNovaGloveImpl(const FSGNovaGloveInfoImpl& DeviceInfo); public: /** diff --git a/Source/SenseGloveUtils/Private/SGUtils/SGCoordinates.cpp b/Source/SenseGloveUtils/Private/SGUtils/SGCoordinates.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h b/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h index 5fffd135..1facbe4a 100644 --- a/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h +++ b/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h @@ -37,6 +37,7 @@ #include +#include "SGCoordinates.h" #include "Containers/Array.h" #include "Templates/UnrealTemplate.h" @@ -609,6 +610,60 @@ public: return MoveTemp(NestedVector); } + template + static std::vector ToSenseGloveAngles(const TArray& Array) + { + std::vector Vector; + + for (const FVector& Value: Array) + { + Vector.emplace_back(FSGCoordinates::TransformToSenseGlove(Value)); + } + + return MoveTemp(Vector); + } + + template + static std::vector> ToSenseGloveAngles(const TArray>& NestedArray) + { + std::vector> NestedVector; + + for (const TArray& InnerArray: NestedArray) + { + std::vector InnerVector{ToSenseGloveAngles(InnerArray)}; + NestedVector.emplace_back(MoveTemp(InnerVector)); + } + + return MoveTemp(NestedVector); + } + + template + static TArray FromSenseGloveAngles(const std::vector& Vector) + { + TArray Array; + + for (const V3D& Value: Vector) + { + Array.Add(FSGCoordinates::TransformToUnreal(Value)); + } + + return MoveTemp(Array); + } + + template + static TArray> FromSenseGloveAngles(const std::vector>& NestedVector) + { + TArray> NestedArray; + + for (const std::vector& InnerVector: NestedVector) + { + TArray InnerArray{FromSenseGloveAngles(InnerVector)}; + NestedArray.Add(MoveTemp(InnerArray)); + } + + return MoveTemp(NestedArray); + } + public: FSGArrayUtils() = delete; virtual ~FSGArrayUtils() = delete; diff --git a/Source/SenseGloveUtils/Public/SGUtils/SGCoordinates.h b/Source/SenseGloveUtils/Public/SGUtils/SGCoordinates.h new file mode 100644 index 00000000..65bc23da --- /dev/null +++ b/Source/SenseGloveUtils/Public/SGUtils/SGCoordinates.h @@ -0,0 +1,117 @@ +/** + * @file + * + * @author Mamadou Babaei + * + * @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 "Math/Vector.h" + +#include "SGTypes/SGCoreTypes.h" + +class SENSEGLOVEUTILS_API FSGCoordinates final +{ +public: + static FORCEINLINE constexpr float TransformToSenseGlove(const int32 Movement, const float Direction) + { + // 0 = twist, 1 = flexion/extension, 2 = abduction + return Movement != 1 ? Direction * -1.0f : Direction; + } + + static FORCEINLINE FVector TransformToSenseGlove(const FVector& Vector) + { + return FVector(Vector.X * -1.0f, Vector.Y, Vector.Z * -1.0f); + } + + template + static FORCEINLINE V TransformToSenseGlove(const FVector& Vector) + { + return V(Vector.X * -1.0f, Vector.Y, Vector.Z * -1.0f); + } + + static FORCEINLINE constexpr float TransformToUnreal(const int32 Movement, const float Direction) + { + /// TODO + /// values require validation. + + // 0 = twist, 1 = flexion/extension, 2 = abduction + return Movement != 1 ? Direction * -1.0f : Direction; + } + + static FORCEINLINE constexpr float TransformToUnreal(const ESGFingerMovement Movement, const float Direction) + { + ensureAlwaysMsgf(Movement != ESGFingerMovement::None, TEXT("none is not a valid value!")); + + /// TODO + /// values require validation. + + // 0 = twist, 1 = flexion/extension, 2 = abduction + /// TODO + /// Which flexions should be ignored? + return (Movement != ESGFingerMovement::McpFlexion && Movement != ESGFingerMovement::PipFlexion && Movement != + ESGFingerMovement::PipFlexion) + ? Direction * -1.0f + : Direction; + } + + static FORCEINLINE constexpr float TransformToUnreal(const ESGThumbMovement Movement, const float Direction) + { + ensureAlwaysMsgf(Movement != ESGThumbMovement::None, TEXT("none is not a valid value!")); + + /// TODO + /// values require validation. + + // 0 = twist, 1 = flexion/extension, 2 = abduction + /// TODO + /// Which flexions should be ignored? + return (Movement != ESGThumbMovement::CmcFlexion && Movement != ESGThumbMovement::McpFlexion && Movement != + ESGThumbMovement::IpFlexion) + ? Direction * -1.0f + : Direction; + } + + static FORCEINLINE FVector TransformToUnreal(const FVector& Vector) + { + return FVector(Vector.X * -1.0f, Vector.Y, Vector.Z * -1.0f); + } + + template + static FORCEINLINE FVector TransformToUnreal(const V& Vector) + { + return FVector(Vector.GetX() * -1.0f, Vector.GetY(), Vector.GetZ() * -1.0f); + } + +public: + FSGCoordinates() = delete; + virtual ~FSGCoordinates() = delete; +}; \ No newline at end of file diff --git a/Source/SenseGloveUtils/SenseGloveUtils.Build.cs b/Source/SenseGloveUtils/SenseGloveUtils.Build.cs index acf260e4..654a81f7 100644 --- a/Source/SenseGloveUtils/SenseGloveUtils.Build.cs +++ b/Source/SenseGloveUtils/SenseGloveUtils.Build.cs @@ -54,7 +54,8 @@ public class SenseGloveUtils : ModuleRules { "CoreUObject", "SenseGloveLog", + "SenseGloveTypes", } ); } -} +} \ No newline at end of file