From 4f08fe02869b8a9e2f9abec48ffd1bcd9e60624e Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Tue, 15 Nov 2022 00:28:52 +0100 Subject: [PATCH] consider millimeters/centimeters conversion, introduce units, and minor array utils refactoring --- .../Private/SGCore/SGBasicHandModel.cpp | 12 +- .../Private/SGCore/SGHandPose.cpp | 20 +- .../Private/SGCore/SGSenseGloveInfo.cpp | 8 +- .../Private/SGCore/SGSenseGlovePose.cpp | 20 +- .../Private/SGCore/SGSenseGloveSensorData.cpp | 8 +- .../Private/SGCore/SGSenseGloveVars.cpp | 2 +- .../SGCoreImpl/SGBasicHandModelImpl.cpp | 37 ++-- .../Private/SGCoreImpl/SGVect3DImpl.cpp | 60 ++++-- .../Private/SGCoreImpl/SGVect3DImpl.h | 16 +- .../SGCoreKismet/SGAnatomyKismetLibrary.cpp | 8 +- .../SGBasicHandModelKismetLibrary.cpp | 6 +- .../SGHandInterpolatorKismetLibrary.cpp | 4 +- .../SGCoreKismet/SGHandPoseKismetLibrary.cpp | 12 +- .../SGNovaGloveCalibrationKismetLibrary.cpp | 4 +- .../SGSenseGloveInfoKismetLibrary.cpp | 6 +- .../SGSenseGloveKismetLibrary.cpp | 2 +- .../SGSenseGlovePoseKismetLibrary.cpp | 8 +- .../SGSenseGloveSensorDataKismetLibrary.cpp | 2 +- .../SGSenseGloveVarsKismetLibrary.cpp | 2 +- .../Private/SGUtils/SGArrayUtils.cpp | 52 +++++ .../Private/SGUtils/SGUnits.cpp | 36 ++++ .../Public/SGUtils/SGArrayUtils.h | 194 ++++++++++-------- .../SenseGloveUtils/Public/SGUtils/SGUnits.h | 66 ++++++ 23 files changed, 400 insertions(+), 185 deletions(-) create mode 100644 Source/SenseGloveUtils/Private/SGUtils/SGUnits.cpp create mode 100644 Source/SenseGloveUtils/Public/SGUtils/SGUnits.h diff --git a/Source/SenseGloveCore/Private/SGCore/SGBasicHandModel.cpp b/Source/SenseGloveCore/Private/SGCore/SGBasicHandModel.cpp index 1ec83793..667d6b2f 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGBasicHandModel.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGBasicHandModel.cpp @@ -118,7 +118,7 @@ USGBasicHandModel* USGBasicHandModel::NewBasicHandModel(UObject* Outer, const bo { FSGIC_FSGBasicHandModelImpl OutBasicHandModelImplContainer; FSGIC_TArray_TArray_float LengthsContainer{ - FSGArrayUtils::FromBPNestedArray(Lengths) + FSGArrayUtils::FromNestedBPArray(Lengths) }; FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; SGCoreImpl_FSGBasicHandModelImpl_ctor_bRightHanded_Lengths_StartPosition( @@ -166,7 +166,7 @@ USGBasicHandModel* USGBasicHandModel::NewBasicHandModel(UObject* Outer, const bo { FSGIC_FSGBasicHandModelImpl OutBasicHandModelImplContainer; FSGIC_TArray_TArray_float LengthsContainer{ - FSGArrayUtils::FromBPNestedArray(Lengths) + FSGArrayUtils::FromNestedBPArray(Lengths) }; FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{StartRotations}; @@ -184,7 +184,7 @@ USGBasicHandModel* USGBasicHandModel::NewBasicHandModel(UObject* Outer, const bo { FSGIC_FSGBasicHandModelImpl OutBasicHandModelImplContainer; FSGIC_TArray_TArray_float LengthsContainer{ - FSGArrayUtils::FromBPNestedArray(Lengths) + FSGArrayUtils::FromNestedBPArray(Lengths) }; FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{FSGArrayUtils::RotatorsToQuats(StartRotations)}; @@ -276,7 +276,7 @@ USGBasicHandModel::USGBasicHandModel(bool bRightHanded, const TArray(Lengths) + FSGArrayUtils::FromNestedBPArray(Lengths) }; FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; SGCoreImpl_FSGBasicHandModelImpl_ctor_bRightHanded_Lengths_StartPosition( @@ -339,7 +339,7 @@ USGBasicHandModel::USGBasicHandModel(const bool bRightHanded, const TArray(Lengths) + FSGArrayUtils::FromNestedBPArray(Lengths) }; FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{StartRotations}; @@ -362,7 +362,7 @@ USGBasicHandModel::USGBasicHandModel(const bool bRightHanded, const TArray(Lengths) + FSGArrayUtils::FromNestedBPArray(Lengths) }; FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{FSGArrayUtils::RotatorsToQuats(StartRotations)}; diff --git a/Source/SenseGloveCore/Private/SGCore/SGHandPose.cpp b/Source/SenseGloveCore/Private/SGCore/SGHandPose.cpp index 028df949..c15265b7 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGHandPose.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGHandPose.cpp @@ -139,13 +139,13 @@ USGHandPose* USGHandPose::NewHandPose( { FSGIC_FSGHandPoseImpl OutHandPoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ - FSGArrayUtils::FromBPNestedArray(JointRotations) + FSGArrayUtils::FromNestedBPArray(JointRotations) }; FSGIC_TArray_TArray_FVector HandAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(HandAngles) + FSGArrayUtils::FromNestedBPArray(HandAngles) }; SGCoreImpl_FSGHandPoseImpl_ctor_bRightHanded_JointPositions_JointRotations_HandAngles( &OutHandPoseImplContainer, bRightHanded, &JointPositionsContainer, @@ -162,13 +162,13 @@ USGHandPose* USGHandPose::NewHandPose( { FSGIC_FSGHandPoseImpl OutHandPoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ FSGArrayUtils::RotatorsToQuats(JointRotations) }; FSGIC_TArray_TArray_FVector HandAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(HandAngles) + FSGArrayUtils::FromNestedBPArray(HandAngles) }; SGCoreImpl_FSGHandPoseImpl_ctor_bRightHanded_JointPositions_JointRotations_HandAngles( &OutHandPoseImplContainer, bRightHanded, &JointPositionsContainer, @@ -353,13 +353,13 @@ USGHandPose::USGHandPose(const bool bRightHanded, const { FSGIC_FSGHandPoseImpl OutHandPoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ - FSGArrayUtils::FromBPNestedArray(JointRotations) + FSGArrayUtils::FromNestedBPArray(JointRotations) }; FSGIC_TArray_TArray_FVector HandAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(HandAngles) + FSGArrayUtils::FromNestedBPArray(HandAngles) }; SGCoreImpl_FSGHandPoseImpl_ctor_bRightHanded_JointPositions_JointRotations_HandAngles( &OutHandPoseImplContainer, bRightHanded, &JointPositionsContainer, @@ -381,13 +381,13 @@ USGHandPose::USGHandPose(const bool bRightHanded, { FSGIC_FSGHandPoseImpl OutHandPoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ FSGArrayUtils::RotatorsToQuats(JointRotations) }; FSGIC_TArray_TArray_FVector HandAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(HandAngles) + FSGArrayUtils::FromNestedBPArray(HandAngles) }; SGCoreImpl_FSGHandPoseImpl_ctor_bRightHanded_JointPositions_JointRotations_HandAngles( &OutHandPoseImplContainer, bRightHanded, &JointPositionsContainer, diff --git a/Source/SenseGloveCore/Private/SGCore/SGSenseGloveInfo.cpp b/Source/SenseGloveCore/Private/SGCore/SGSenseGloveInfo.cpp index 645a8d85..cb3e2290 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGSenseGloveInfo.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGSenseGloveInfo.cpp @@ -170,7 +170,7 @@ USGSenseGloveInfo* USGSenseGloveInfo::NewSenseGloveInfo(UObject* Outer, const FS FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{StartRotations}; FSGIC_TArray_TArray_FVector GloveLengthsContainer{ - FSGArrayUtils::FromBPNestedArray(GloveLengths) + FSGArrayUtils::FromNestedBPArray(GloveLengths) }; FSGIC_TArray_bool FunctionsContainer{Functions}; SGCoreImpl_FSGSenseGloveInfoImpl_ctor_DeviceId_HardwareVersion_FirmwareVersion_SubFirmwareVersion_bRightHanded_NumberOfSensors_ImuCorrection_StartPositions_StartRotations_GloveLengths_Functions( @@ -199,7 +199,7 @@ USGSenseGloveInfo* USGSenseGloveInfo::NewSenseGloveInfo(UObject* Outer, const FS FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{FSGArrayUtils::RotatorsToQuats(StartRotations)}; FSGIC_TArray_TArray_FVector GloveLengthsContainer{ - FSGArrayUtils::FromBPNestedArray(GloveLengths) + FSGArrayUtils::FromNestedBPArray(GloveLengths) }; FSGIC_TArray_bool FunctionsContainer{Functions}; SGCoreImpl_FSGSenseGloveInfoImpl_ctor_DeviceId_HardwareVersion_FirmwareVersion_SubFirmwareVersion_bRightHanded_NumberOfSensors_ImuCorrection_StartPositions_StartRotations_GloveLengths_Functions( @@ -330,7 +330,7 @@ USGSenseGloveInfo::USGSenseGloveInfo( FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{StartRotations}; FSGIC_TArray_TArray_FVector GloveLengthsContainer{ - FSGArrayUtils::FromBPNestedArray(GloveLengths) + FSGArrayUtils::FromNestedBPArray(GloveLengths) }; FSGIC_TArray_bool FunctionsContainer{Functions}; SGCoreImpl_FSGSenseGloveInfoImpl_ctor_DeviceId_HardwareVersion_FirmwareVersion_SubFirmwareVersion_bRightHanded_NumberOfSensors_ImuCorrection_StartPositions_StartRotations_GloveLengths_Functions( @@ -358,7 +358,7 @@ USGSenseGloveInfo::USGSenseGloveInfo( FSGIC_TArray_FVector StartPositionsContainer{StartPositions}; FSGIC_TArray_FQuat StartRotationsContainer{FSGArrayUtils::RotatorsToQuats(StartRotations)}; FSGIC_TArray_TArray_FVector GloveLengthsContainer{ - FSGArrayUtils::FromBPNestedArray(GloveLengths) + FSGArrayUtils::FromNestedBPArray(GloveLengths) }; FSGIC_TArray_bool FunctionsContainer{Functions}; SGCoreImpl_FSGSenseGloveInfoImpl_ctor_DeviceId_HardwareVersion_FirmwareVersion_SubFirmwareVersion_bRightHanded_NumberOfSensors_ImuCorrection_StartPositions_StartRotations_GloveLengths_Functions( diff --git a/Source/SenseGloveCore/Private/SGCore/SGSenseGlovePose.cpp b/Source/SenseGloveCore/Private/SGCore/SGSenseGlovePose.cpp index 82b8354d..e8685d38 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGSenseGlovePose.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGSenseGlovePose.cpp @@ -138,13 +138,13 @@ USGSenseGlovePose* USGSenseGlovePose::NewSenseGlovePose(UObject* Outer, const bo { FSGIC_FSGSenseGlovePoseImpl OutSenseGlovePoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ - FSGArrayUtils::FromBPNestedArray(JointRotations) + FSGArrayUtils::FromNestedBPArray(JointRotations) }; FSGIC_TArray_TArray_FVector GloveAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(GloveAngles) + FSGArrayUtils::FromNestedBPArray(GloveAngles) }; SGCoreImpl_FSGSenseGlovePoseImpl_ctor_bRightHanded_JointPositions_JointRotations_GloveAngles( &OutSenseGlovePoseImplContainer, bRightHanded, &JointPositionsContainer, @@ -160,13 +160,13 @@ USGSenseGlovePose* USGSenseGlovePose::NewSenseGlovePose(UObject* Outer, const bo { FSGIC_FSGSenseGlovePoseImpl OutSenseGlovePoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ FSGArrayUtils::RotatorsToQuats(JointRotations) }; FSGIC_TArray_TArray_FVector GloveAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(GloveAngles) + FSGArrayUtils::FromNestedBPArray(GloveAngles) }; SGCoreImpl_FSGSenseGlovePoseImpl_ctor_bRightHanded_JointPositions_JointRotations_GloveAngles( &OutSenseGlovePoseImplContainer, bRightHanded, &JointPositionsContainer, @@ -261,13 +261,13 @@ USGSenseGlovePose::USGSenseGlovePose(const bool bRightHanded, { FSGIC_FSGSenseGlovePoseImpl OutSenseGlovePoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ - FSGArrayUtils::FromBPNestedArray(JointRotations) + FSGArrayUtils::FromNestedBPArray(JointRotations) }; FSGIC_TArray_TArray_FVector GloveAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(GloveAngles) + FSGArrayUtils::FromNestedBPArray(GloveAngles) }; SGCoreImpl_FSGSenseGlovePoseImpl_ctor_bRightHanded_JointPositions_JointRotations_GloveAngles( &OutSenseGlovePoseImplContainer, bRightHanded, &JointPositionsContainer, @@ -284,13 +284,13 @@ USGSenseGlovePose::USGSenseGlovePose(const bool bRightHanded, { FSGIC_FSGSenseGlovePoseImpl OutSenseGlovePoseImplContainer; FSGIC_TArray_TArray_FVector JointPositionsContainer{ - FSGArrayUtils::FromBPNestedArray(JointPositions) + FSGArrayUtils::FromNestedBPArray(JointPositions) }; FSGIC_TArray_TArray_FQuat JointRotationsContainer{ FSGArrayUtils::RotatorsToQuats(JointRotations) }; FSGIC_TArray_TArray_FVector GloveAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(GloveAngles) + FSGArrayUtils::FromNestedBPArray(GloveAngles) }; SGCoreImpl_FSGSenseGlovePoseImpl_ctor_bRightHanded_JointPositions_JointRotations_GloveAngles( &OutSenseGlovePoseImplContainer, bRightHanded, &JointPositionsContainer, diff --git a/Source/SenseGloveCore/Private/SGCore/SGSenseGloveSensorData.cpp b/Source/SenseGloveCore/Private/SGCore/SGSenseGloveSensorData.cpp index 21ba0748..8cb83826 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGSenseGloveSensorData.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGSenseGloveSensorData.cpp @@ -131,7 +131,7 @@ USGSenseGloveSensorData* USGSenseGloveSensorData::NewSenseGloveSensorData( { FSGIC_FSGSenseGloveSensorDataImpl OutSenseGloveSensorDataImplContainer; FSGIC_TArray_TArray_float SensorAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(SensorAngles) + FSGArrayUtils::FromNestedBPArray(SensorAngles) }; FSGIC_FQuat ImuRotationContainer{ImuRotation}; SGCoreImpl_FSGSenseGloveSensorDataImpl_ctor_SensorAngles_ImuRotation_ParsedValues_bImuParsed( @@ -146,7 +146,7 @@ USGSenseGloveSensorData* USGSenseGloveSensorData::NewSenseGloveSensorData( { FSGIC_FSGSenseGloveSensorDataImpl OutSenseGloveSensorDataImplContainer; FSGIC_TArray_TArray_float SensorAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(SensorAngles) + FSGArrayUtils::FromNestedBPArray(SensorAngles) }; FSGIC_FQuat ImuRotationContainer{ImuRotation.Quaternion()}; SGCoreImpl_FSGSenseGloveSensorDataImpl_ctor_SensorAngles_ImuRotation_ParsedValues_bImuParsed( @@ -243,7 +243,7 @@ USGSenseGloveSensorData::USGSenseGloveSensorData(const TArray& Se { FSGIC_FSGSenseGloveSensorDataImpl OutSenseGloveSensorDataImplContainer; FSGIC_TArray_TArray_float SensorAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(SensorAngles) + FSGArrayUtils::FromNestedBPArray(SensorAngles) }; FSGIC_FQuat ImuRotationContainer{ImuRotation}; SGCoreImpl_FSGSenseGloveSensorDataImpl_ctor_SensorAngles_ImuRotation_ParsedValues_bImuParsed( @@ -258,7 +258,7 @@ USGSenseGloveSensorData::USGSenseGloveSensorData(const TArray& Se { FSGIC_FSGSenseGloveSensorDataImpl OutSenseGloveSensorDataImplContainer; FSGIC_TArray_TArray_float SensorAnglesContainer{ - FSGArrayUtils::FromBPNestedArray(SensorAngles) + FSGArrayUtils::FromNestedBPArray(SensorAngles) }; FSGIC_FQuat ImuRotationContainer{ImuRotation.Quaternion()}; SGCoreImpl_FSGSenseGloveSensorDataImpl_ctor_SensorAngles_ImuRotation_ParsedValues_bImuParsed( diff --git a/Source/SenseGloveCore/Private/SGCore/SGSenseGloveVars.cpp b/Source/SenseGloveCore/Private/SGCore/SGSenseGloveVars.cpp index 18dd334c..c5a2ed08 100644 --- a/Source/SenseGloveCore/Private/SGCore/SGSenseGloveVars.cpp +++ b/Source/SenseGloveCore/Private/SGCore/SGSenseGloveVars.cpp @@ -99,7 +99,7 @@ TArray> FSGSenseGloveVars::GetGloveLengths(const FString& Hardwa /* TArray FSGSenseGloveVars::GetGloveLengths_BP(const FString& HardwareVersion) { - return FSGArrayUtils::ToBPNestedArray(GetGloveLengths(HardwareVersion)); + return FSGArrayUtils::ToNestedBPArray(GetGloveLengths(HardwareVersion)); } */ int32 FSGSenseGloveVars::GetSensors(const FString& HardwareVersion) diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGBasicHandModelImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGBasicHandModelImpl.cpp index c8fd3ad8..538203c1 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGBasicHandModelImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGBasicHandModelImpl.cpp @@ -47,6 +47,7 @@ #include "SGCoreImpl/SGQuatImpl.h" #include "SGCoreImpl/SGVect3DImpl.h" #include "SGUtils/SGArrayUtils.h" +#include "SGUtils/SGUnits.h" struct FSGBasicHandModelImpl::FImpl { @@ -223,7 +224,7 @@ void FSGBasicHandModelImpl::SetIsRight(const bool bRightHanded) TArray> FSGBasicHandModelImpl::GetFingerLengths() const { TArray> FingerLengths{ - FSGArrayUtils::FromStdVector(Pimpl->BasicHandModel.GetFingerLengths()) + FSGArrayUtils::FromMillimeters(Pimpl->BasicHandModel.GetFingerLengths()) }; return MoveTemp(FingerLengths); } @@ -231,28 +232,32 @@ TArray> FSGBasicHandModelImpl::GetFingerLengths() const void FSGBasicHandModelImpl::SetFingerLengths(const TArray>& FingerLengths) { std::vector> FingerLengthsVector{ - FSGArrayUtils::ToStdVector(FingerLengths) + FSGArrayUtils::ToMillimeters(FingerLengths) }; Pimpl->BasicHandModel.SetFingerLengths(MoveTemp(FingerLengthsVector)); } -TArray FSGBasicHandModelImpl::GetFingerLengths(ESGFinger Finger) const +TArray FSGBasicHandModelImpl::GetFingerLengths(const ESGFinger Finger) const { - TArray FingerLengths{FSGArrayUtils::FromStdVector( - Pimpl->BasicHandModel.GetFingerLengths(FSGCoreEnumCast::ToEFinger(Finger))) + TArray FingerLengths{ + FSGArrayUtils::FromMillimeters(Pimpl->BasicHandModel.GetFingerLengths(FSGCoreEnumCast::ToEFinger(Finger))) }; return MoveTemp(FingerLengths); } -void FSGBasicHandModelImpl::SetFingerLengths(ESGFinger Finger, const TArray& Lengths) +void FSGBasicHandModelImpl::SetFingerLengths(const ESGFinger Finger, const TArray& Lengths) { - std::vector LengthsVector{FSGArrayUtils::ToStdVector(Lengths)}; + std::vector LengthsVector{ + FSGArrayUtils::ToMillimeters(Lengths) + }; Pimpl->BasicHandModel.SetFingerLengths(FSGCoreEnumCast::ToEFinger(Finger), MoveTemp(LengthsVector)); } -void FSGBasicHandModelImpl::SetFingerLengths(uint8 Finger, const TArray& Lengths) +void FSGBasicHandModelImpl::SetFingerLengths(const uint8 Finger, const TArray& Lengths) { - std::vector LengthsVector{FSGArrayUtils::ToStdVector(Lengths)}; + std::vector LengthsVector{ + FSGArrayUtils::ToMillimeters(Lengths) + }; Pimpl->BasicHandModel.SetFingerLengths(Finger, MoveTemp(LengthsVector)); } @@ -264,7 +269,7 @@ TArray> FSGBasicHandModelImpl::GetFingerRatios() const return MoveTemp(FingerRatios); } -TArray FSGBasicHandModelImpl::GetFingerRatios(ESGFinger Finger) const +TArray FSGBasicHandModelImpl::GetFingerRatios(const ESGFinger Finger) const { TArray FingerRatios{ FSGArrayUtils::FromStdVector(Pimpl->BasicHandModel.GetFingerRatios(FSGCoreEnumCast::ToEFinger(Finger))) @@ -345,21 +350,23 @@ void FSGBasicHandModelImpl::SetJointRotation(const FQuat& NewRotation, const ESG TArray FSGBasicHandModelImpl::GetTotalLengths() const { const TArray TotalLengths{ - FSGArrayUtils::FromStdVector(Pimpl->BasicHandModel.GetTotalLengths()) + FSGArrayUtils::FromMillimeters(Pimpl->BasicHandModel.GetTotalLengths()) }; return TotalLengths; } float FSGBasicHandModelImpl::GetTotalLength(const ESGFinger Finger) const { - return Pimpl->BasicHandModel.GetTotalLength(FSGCoreEnumCast::ToEFinger(Finger)); + return FSGUnits::MillimetersToCentimeters( + Pimpl->BasicHandModel.GetTotalLength(FSGCoreEnumCast::ToEFinger(Finger))); } TArray FSGBasicHandModelImpl::Get3DLengths(const ESGFinger Finger) const { - const TArray Lengths(FSGArrayUtils::FromStdVector< - FSGVect3DImpl::FVect3DType, FVector, FSGVect3DImpl, &FSGVect3DImpl::ToFVector>( - Pimpl->BasicHandModel.Get3DLengths(FSGCoreEnumCast::ToEFinger(Finger)))); + const TArray Lengths{ + FSGArrayUtils::FromStdVector( + Pimpl->BasicHandModel.Get3DLengths(FSGCoreEnumCast::ToEFinger(Finger))) + }; return Lengths; } diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.cpp b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.cpp index 4f200474..33d2294a 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.cpp +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.cpp @@ -39,6 +39,7 @@ #include "Runtime/Launch/Resources/Version.h" #include "SGBuildHacks/SGInclude_Core_Vect3D.h" +#include "SGUtils/SGUnits.h" struct FSGVect3DImpl::FImpl { @@ -101,7 +102,12 @@ FSGVect3DImpl::FSGVect3DImpl(const float X, const float Y, const float Z) Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { - Pimpl->Vect3D = FVect3DType(X, Y, Z); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + Pimpl->Vect3D = FVect3DType(FSGUnits::CentimetersToMillimeters(X), + FSGUnits::CentimetersToMillimeters(Y), + FSGUnits::CentimetersToMillimeters(Z)); } FSGVect3DImpl::FSGVect3DImpl(const FVect3DType& Vect3D) @@ -132,12 +138,14 @@ FSGVect3DImpl::FSGVect3DImpl(const FVector& Vector) /// Forward X /// Right Y /// Up Z - FVect3DType Vect3D(Vector.X, -Vector.Y, Vector.Z); /// NOTE /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; /// while SenseGlove uses millimeters. - Vect3D.Scale(10.0f); + + FVect3DType Vect3D(FSGUnits::CentimetersToMillimeters(Vector.X), + FSGUnits::CentimetersToMillimeters(-Vector.Y), + FSGUnits::CentimetersToMillimeters(Vector.Z)); Pimpl->Vect3D = MoveTemp(Vect3D); } @@ -182,12 +190,14 @@ FVector FSGVect3DImpl::ToFVector() const /// Forward X /// Right Y /// Up Z - FVector Vector(Pimpl->Vect3D.GetX(), -Pimpl->Vect3D.GetY(), Pimpl->Vect3D.GetZ()); /// NOTE /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; /// while SenseGlove uses millimeters. - Vector *= 0.1f; + + FVector Vector(FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.GetX()), + FSGUnits::MillimetersToCentimeters(-Pimpl->Vect3D.GetY()), + FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.GetZ())); return MoveTemp(Vector); } @@ -209,37 +219,58 @@ FSGVect3DImpl FSGVect3DImpl::operator*(const float& ScaleFactor) const float FSGVect3DImpl::GetX() const { - return Pimpl->Vect3D.GetX(); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + return FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.GetX()); } void FSGVect3DImpl::SetX(const float X) { - Pimpl->Vect3D.SetX(X); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + Pimpl->Vect3D.SetX(FSGUnits::CentimetersToMillimeters(X)); } float FSGVect3DImpl::GetY() const { - return Pimpl->Vect3D.GetY(); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + return FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.GetY()); } void FSGVect3DImpl::SetY(const float Y) { - Pimpl->Vect3D.SetY(Y); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + Pimpl->Vect3D.SetY(FSGUnits::CentimetersToMillimeters(Y)); } float FSGVect3DImpl::GetZ() const { - return Pimpl->Vect3D.GetZ(); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + return FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.GetZ()); } void FSGVect3DImpl::SetZ(const float Z) { - Pimpl->Vect3D.SetZ(Z); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + Pimpl->Vect3D.SetZ(FSGUnits::CentimetersToMillimeters(Z)); } float FSGVect3DImpl::Magnitude() const { - return Pimpl->Vect3D.Magnitude(); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + return FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.Magnitude()); } void FSGVect3DImpl::Normalize() @@ -254,7 +285,10 @@ void FSGVect3DImpl::Scale(const float Factor) float FSGVect3DImpl::DistTo(const FSGVect3DImpl& Vect3DImpl) const { - return Pimpl->Vect3D.DistTo(Vect3DImpl.ToVect3D()); + /// NOTE + /// Unreal Engine uses the Metric System and centimeters as its default unit for measuring distance/length; + /// while SenseGlove uses millimeters. + return FSGUnits::MillimetersToCentimeters(Pimpl->Vect3D.DistTo(Vect3DImpl.ToVect3D())); } bool FSGVect3DImpl::Equals(const FSGVect3DImpl& Vect3DImpl) const diff --git a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.h b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.h index 2e3ebd6c..f3e2068c 100644 --- a/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.h +++ b/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGVect3DImpl.h @@ -153,38 +153,38 @@ public: public: /** - * Get the x-component of the 3D vector. + * Get the x-component of the 3D vector in cm. */ float GetX() const; /** - * Set the x-component of the 3D vector. + * Set the x-component of the 3D vector in cm. */ void SetX(float X); /** - * Get the y-component of the 3D vector. + * Get the y-component of the 3D vector in cm. */ float GetY() const; /** - * Set the y-component of the 3D vector. + * Set the y-component of the 3D vector in cm. */ void SetY(float Y); /** - * Get the z-component of the 3D vector. + * Get the z-component of the 3D vector in cm. */ float GetZ() const; /** - * Set the z-component of the 3D vector. + * Set the z-component of the 3D vector in cm. */ void SetZ(float Z); public: /** - * Calculate the magnitude or 'length' of this Vector. + * Calculate the magnitude or 'length' of this Vector in cm. */ float Magnitude() const; @@ -199,7 +199,7 @@ public: void Scale(float Factor); /** - * Calculate the distance between this Vector and another one. + * Calculate the distance between this Vector and another one in cm. */ float DistTo(const FSGVect3DImpl& Vect3DImpl) const; diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGAnatomyKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGAnatomyKismetLibrary.cpp index e44a54b9..a7442bfc 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGAnatomyKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGAnatomyKismetLibrary.cpp @@ -82,20 +82,20 @@ float USGAnatomyKismetLibrary::NormalizeThumbFlex(const float FlexionInRadians) TArray USGAnatomyKismetLibrary::GetDefaultHandAngles(const bool bRightHanded) { - return FSGArrayUtils::ToBPNestedArray(FSGAnatomy::GetDefaultHandAngles(bRightHanded)); + return FSGArrayUtils::ToNestedBPArray(FSGAnatomy::GetDefaultHandAngles(bRightHanded)); } TArray USGAnatomyKismetLibrary::GetFlatHandAngles(const bool bRightHanded) { - return FSGArrayUtils::ToBPNestedArray(FSGAnatomy::GetFlatHandAngles(bRightHanded)); + return FSGArrayUtils::ToNestedBPArray(FSGAnatomy::GetFlatHandAngles(bRightHanded)); } TArray USGAnatomyKismetLibrary::GetThumbsUpHandAngles(const bool bRightHanded) { - return FSGArrayUtils::ToBPNestedArray(FSGAnatomy::GetThumbsUpHandAngles(bRightHanded)); + return FSGArrayUtils::ToNestedBPArray(FSGAnatomy::GetThumbsUpHandAngles(bRightHanded)); } TArray USGAnatomyKismetLibrary::GetFistHandAngles(const bool bRightHanded) { - return FSGArrayUtils::ToBPNestedArray(FSGAnatomy::GetFistHandAngles(bRightHanded)); + return FSGArrayUtils::ToNestedBPArray(FSGAnatomy::GetFistHandAngles(bRightHanded)); } \ No newline at end of file diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGBasicHandModelKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGBasicHandModelKismetLibrary.cpp index 3b60c806..d2aa2c1f 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGBasicHandModelKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGBasicHandModelKismetLibrary.cpp @@ -81,7 +81,7 @@ USGBasicHandModel* USGBasicHandModelKismetLibrary::Deserialize(UObject* WorldCon TArray USGBasicHandModelKismetLibrary::GetBaseFingerLengths() { - return FSGArrayUtils::ToBPNestedArray(USGBasicHandModel::GetBaseFingerLengths()); + return FSGArrayUtils::ToNestedBPArray(USGBasicHandModel::GetBaseFingerLengths()); } TArray USGBasicHandModelKismetLibrary::GetBaseJointPositions() @@ -101,7 +101,7 @@ bool USGBasicHandModelKismetLibrary::IsRight(const USGBasicHandModel* BasicHandM TArray USGBasicHandModelKismetLibrary::GetFingerLengths(const USGBasicHandModel* BasicHandModel) { - return FSGArrayUtils::ToBPNestedArray(BasicHandModel->GetFingerLengths()); + return FSGArrayUtils::ToNestedBPArray(BasicHandModel->GetFingerLengths()); } TArray USGBasicHandModelKismetLibrary::GetFingerLengths_F(const USGBasicHandModel* BasicHandModel, @@ -125,7 +125,7 @@ void USGBasicHandModelKismetLibrary::SetFingerLengths_uint8_F_L(USGBasicHandMode TArray USGBasicHandModelKismetLibrary::GetFingerRatios(const USGBasicHandModel* BasicHandModel) const { - return FSGArrayUtils::ToBPNestedArray(BasicHandModel->GetFingerRatios()); + return FSGArrayUtils::ToNestedBPArray(BasicHandModel->GetFingerRatios()); } TArray USGBasicHandModelKismetLibrary::GetFingerRatios_F(const USGBasicHandModel* BasicHandModel, diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandInterpolatorKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandInterpolatorKismetLibrary.cpp index 2b7bad64..c33e828c 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandInterpolatorKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandInterpolatorKismetLibrary.cpp @@ -89,14 +89,14 @@ TArray USGHandInterpolatorKismetLibrary::InterpolateThumbAngles( TArray USGHandInterpolatorKismetLibrary::InterpolateHandAngles( const USGHandInterpolator* Interpolator, const TArray& TotalAngles) { - return FSGArrayUtils::ToBPNestedArray( + return FSGArrayUtils::ToNestedBPArray( USGHandInterpolator::InterpolateHandAngles(Interpolator, TotalAngles)); } TArray USGHandInterpolatorKismetLibrary::GetJointInterpolations( UObject* WorldContextObject, const USGHandInterpolator* HandInterpolator) const { - return FSGArrayUtils::ToBPNestedArray( + return FSGArrayUtils::ToNestedBPArray( HandInterpolator->GetJointInterpolations(WorldContextObject)); } diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandPoseKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandPoseKismetLibrary.cpp index 15095bf8..9e87dceb 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandPoseKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGHandPoseKismetLibrary.cpp @@ -71,7 +71,7 @@ USGHandPose* USGHandPoseKismetLibrary::FromHandAngles_HA_bRH_HD( const TArray& HandAngles, const bool bRightHanded, const USGBasicHandModel* HandDimensions) { TArray> HandAnglesNestedArray{ - FSGArrayUtils::FromBPNestedArray(HandAngles) + FSGArrayUtils::FromNestedBPArray(HandAngles) }; return USGHandPose::FromHandAngles(WorldContextObject, MoveTemp(HandAnglesNestedArray), bRightHanded, HandDimensions); @@ -81,7 +81,7 @@ USGHandPose* USGHandPoseKismetLibrary::FromHandAngles_HA_bRH( UObject* WorldContextObject, const TArray& HandAngles, const bool bRightHanded) { TArray> HandAnglesNestedArray{ - FSGArrayUtils::FromBPNestedArray(HandAngles) + FSGArrayUtils::FromNestedBPArray(HandAngles) }; return USGHandPose::FromHandAngles(WorldContextObject, MoveTemp(HandAnglesNestedArray), bRightHanded); } @@ -137,22 +137,22 @@ bool USGHandPoseKismetLibrary::IsRight(const USGHandPose* HandPose) TArray USGHandPoseKismetLibrary::GetJointPositions(const USGHandPose* HandPose) { - return FSGArrayUtils::ToBPNestedArray(HandPose->GetJointPositions()); + return FSGArrayUtils::ToNestedBPArray(HandPose->GetJointPositions()); } TArray USGHandPoseKismetLibrary::GetJointRotationsQ(const USGHandPose* HandPose) { - return FSGArrayUtils::ToBPNestedArray(HandPose->GetJointRotationsQ()); + return FSGArrayUtils::ToNestedBPArray(HandPose->GetJointRotationsQ()); } TArray USGHandPoseKismetLibrary::GetJointRotations(const USGHandPose* HandPose) { - return FSGArrayUtils::ToBPNestedArray(HandPose->GetJointRotations()); + return FSGArrayUtils::ToNestedBPArray(HandPose->GetJointRotations()); } TArray USGHandPoseKismetLibrary::GetHandAngles(const USGHandPose* HandPose) { - return FSGArrayUtils::ToBPNestedArray(HandPose->GetHandAngles()); + return FSGArrayUtils::ToNestedBPArray(HandPose->GetHandAngles()); } bool USGHandPoseKismetLibrary::Equals(const USGHandPose* A, const USGHandPose* B) diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGNovaGloveCalibrationKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGNovaGloveCalibrationKismetLibrary.cpp index cbcf87d8..45a55002 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGNovaGloveCalibrationKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGNovaGloveCalibrationKismetLibrary.cpp @@ -54,9 +54,9 @@ void USGNovaGloveCalibrationKismetLibrary::ApplyInterpolationValues(const TArray { FSGNovaGloveCalibration::ApplyInterpolationValues( RetractedValues, ExtendedValues, - FSGArrayUtils::FromBPNestedArray< + FSGArrayUtils::FromNestedBPArray< FVector, FSGVectorArray, &FSGVectorArray::VectorArray>(RetractedAngles), - FSGArrayUtils::FromBPNestedArray< + FSGArrayUtils::FromNestedBPArray< FVector, FSGVectorArray, &FSGVectorArray::VectorArray>(ExtendedAngles), Profile); } \ No newline at end of file diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveInfoKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveInfoKismetLibrary.cpp index bcd534fc..4a3d1332 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveInfoKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveInfoKismetLibrary.cpp @@ -144,7 +144,7 @@ TArray USGSenseGloveInfoKismetLibrary::GetStartRotations_TArrayFRotato TArray USGSenseGloveInfoKismetLibrary::GetGloveLengths(const USGSenseGloveInfo* SenseGloveInfo) { - return FSGArrayUtils::ToBPNestedArray(SenseGloveInfo->GetGloveLengths()); + return FSGArrayUtils::ToNestedBPArray(SenseGloveInfo->GetGloveLengths()); } TArray USGSenseGloveInfoKismetLibrary::GetFunctions(const USGSenseGloveInfo* SenseGloveInfo) @@ -180,11 +180,11 @@ TArray USGSenseGloveInfoKismetLibrary::ToGloveAngles(const USGSe const TArray& SensorAngles) { TArray> SensorAnglesNestedArray{ - FSGArrayUtils::FromBPNestedArray< + FSGArrayUtils::FromNestedBPArray< float, FSGFloatArray, &FSGFloatArray::FloatArray>(SensorAngles) }; TArray GloveAngles{ - FSGArrayUtils::ToBPNestedArray( + FSGArrayUtils::ToNestedBPArray( SenseGloveInfo->ToGloveAngles(MoveTemp(SensorAnglesNestedArray))) }; return MoveTemp(GloveAngles); diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveKismetLibrary.cpp index ea6df713..33a1070b 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveKismetLibrary.cpp @@ -62,7 +62,7 @@ USGSenseGlovePose* USGSenseGloveKismetLibrary::CalculateGlovePose_GA_GM( const TArray& GloveAngles, const USGSenseGloveInfo* GloveModel) { TArray> GloveAnglesNestedArray{ - FSGArrayUtils::FromBPNestedArray(GloveAngles) + FSGArrayUtils::FromNestedBPArray(GloveAngles) }; return USGSenseGlove::CalculateGlovePose(WorldContextObject, MoveTemp(GloveAnglesNestedArray), GloveModel); } diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGlovePoseKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGlovePoseKismetLibrary.cpp index 378af4e9..c4f8fc0a 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGlovePoseKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGlovePoseKismetLibrary.cpp @@ -80,24 +80,24 @@ bool USGSenseGlovePoseKismetLibrary::IsRight(const USGSenseGlovePose* SenseGlove TArray USGSenseGlovePoseKismetLibrary::GetJointPositions(const USGSenseGlovePose* SenseGlovePose) { - return FSGArrayUtils::ToBPNestedArray(SenseGlovePose->GetJointPositions()); + return FSGArrayUtils::ToNestedBPArray(SenseGlovePose->GetJointPositions()); } TArray USGSenseGlovePoseKismetLibrary::GetJointRotations_TArrayFSGQuatArray( const USGSenseGlovePose* SenseGlovePose) { - return FSGArrayUtils::ToBPNestedArray(SenseGlovePose->GetJointRotationsQ()); + return FSGArrayUtils::ToNestedBPArray(SenseGlovePose->GetJointRotationsQ()); } TArray USGSenseGlovePoseKismetLibrary::GetJointRotations_TArrayFSGRotatorArray( const USGSenseGlovePose* SenseGlovePose) { - return FSGArrayUtils::ToBPNestedArray(SenseGlovePose->GetJointRotations()); + return FSGArrayUtils::ToNestedBPArray(SenseGlovePose->GetJointRotations()); } TArray USGSenseGlovePoseKismetLibrary::GetGloveAngles(const USGSenseGlovePose* SenseGlovePose) { - return FSGArrayUtils::ToBPNestedArray(SenseGlovePose->GetGloveAngles()); + return FSGArrayUtils::ToNestedBPArray(SenseGlovePose->GetGloveAngles()); } TArray USGSenseGlovePoseKismetLibrary::GetThimblePositions(const USGSenseGlovePose* SenseGlovePose) diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveSensorDataKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveSensorDataKismetLibrary.cpp index 14b54ba6..43c487ba 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveSensorDataKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveSensorDataKismetLibrary.cpp @@ -81,7 +81,7 @@ USGSenseGloveSensorData* USGSenseGloveSensorDataKismetLibrary::Deserialize(UObje TArray USGSenseGloveSensorDataKismetLibrary::GetSensorAngles( const USGSenseGloveSensorData* SenseGloveSensorData) { - return FSGArrayUtils::ToBPNestedArray(SenseGloveSensorData->GetSensorAngles()); + return FSGArrayUtils::ToNestedBPArray(SenseGloveSensorData->GetSensorAngles()); } FQuat USGSenseGloveSensorDataKismetLibrary::GetImuRotation_FQuat(const USGSenseGloveSensorData* SenseGloveSensorData) diff --git a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveVarsKismetLibrary.cpp b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveVarsKismetLibrary.cpp index b995b39e..9541a1ea 100644 --- a/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveVarsKismetLibrary.cpp +++ b/Source/SenseGloveCoreKismet/Private/SGCoreKismet/SGSenseGloveVarsKismetLibrary.cpp @@ -70,7 +70,7 @@ TArray USGSenseGloveVarsKismetLibrary::GetStartRotations_TArrayFRotato TArray USGSenseGloveVarsKismetLibrary::GetGloveLengths(const FString& HardwareVersion) { - return FSGArrayUtils::ToBPNestedArray(FSGSenseGloveVars::GetGloveLengths(HardwareVersion)); + return FSGArrayUtils::ToNestedBPArray(FSGSenseGloveVars::GetGloveLengths(HardwareVersion)); } int32 USGSenseGloveVarsKismetLibrary::GetSensors(const FString& HardwareVersion) diff --git a/Source/SenseGloveUtils/Private/SGUtils/SGArrayUtils.cpp b/Source/SenseGloveUtils/Private/SGUtils/SGArrayUtils.cpp index c7d778c5..3c15674e 100644 --- a/Source/SenseGloveUtils/Private/SGUtils/SGArrayUtils.cpp +++ b/Source/SenseGloveUtils/Private/SGUtils/SGArrayUtils.cpp @@ -35,6 +35,8 @@ #include "SGUtils/SGArrayUtils.h" +#include "SGUtils/SGUnits.h" + TArray FSGArrayUtils::QuatsToRotators(const TArray& QuatsArray) { TArray RotatorsArray; @@ -85,4 +87,54 @@ TArray> FSGArrayUtils::RotatorsToQuats(const TArray FSGArrayUtils::FromMillimeters(const std::vector& Vector) +{ + TArray Array; + + for (const float Value: Vector) + { + Array.Add(FSGUnits::MillimetersToCentimeters(Value)); + } + + return MoveTemp(Array); +} + +TArray> FSGArrayUtils::FromMillimeters(const std::vector>& NestedVector) +{ + TArray> NestedArray; + + for (const std::vector& InnerVector: NestedVector) + { + TArray InnerArray{FromMillimeters(InnerVector)}; + NestedArray.Add(MoveTemp(InnerArray)); + } + + return MoveTemp(NestedArray); +} + +std::vector FSGArrayUtils::ToMillimeters(const TArray& Array) +{ + std::vector Vector; + + for (const float Value: Array) + { + Vector.emplace_back(FSGUnits::CentimetersToMillimeters(Value)); + } + + return MoveTemp(Vector); +} + +std::vector> FSGArrayUtils::ToMillimeters(const TArray>& NestedArray) +{ + std::vector> NestedVector; + + for (const TArray& InnerArray: NestedArray) + { + std::vector InnerVector{ToMillimeters(InnerArray)}; + NestedVector.emplace_back(MoveTemp(InnerVector)); + } + + return MoveTemp(NestedVector); } \ No newline at end of file diff --git a/Source/SenseGloveUtils/Private/SGUtils/SGUnits.cpp b/Source/SenseGloveUtils/Private/SGUtils/SGUnits.cpp new file mode 100644 index 00000000..fa62d08f --- /dev/null +++ b/Source/SenseGloveUtils/Private/SGUtils/SGUnits.cpp @@ -0,0 +1,36 @@ +/** + * @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 + * + * + */ + + +#include "SGUtils/SGUnits.h" \ No newline at end of file diff --git a/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h b/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h index 2f08c560..70ff4936 100644 --- a/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h +++ b/Source/SenseGloveUtils/Public/SGUtils/SGArrayUtils.h @@ -67,17 +67,17 @@ public: } template - static FORCEINLINE TArray> FromStdVector(const std::vector>& Vector) + static TArray> FromStdVector(const std::vector>& NestedVector) { - TArray> Array; + TArray> NestedArray; - for (const std::vector& InnerVector: Vector) + for (const std::vector& InnerVector: NestedVector) { TArray InnerArray{FromStdVector(InnerVector)}; - Array.Add(MoveTemp(InnerArray)); + NestedArray.Add(MoveTemp(InnerArray)); } - return MoveTemp(Array); + return MoveTemp(NestedArray); } template @@ -95,17 +95,17 @@ public: } template - static TArray> FromStdVector(const std::vector>& Vector) + static TArray> FromStdVector(const std::vector>& NestedVector) { - TArray> Array; + TArray> NestedArray; - for (const std::vector& InnerVector: Vector) + for (const std::vector& InnerVector: NestedVector) { TArray InnerArray{FromStdVector(InnerVector)}; - Array.Add(MoveTemp(InnerArray)); + NestedArray.Add(MoveTemp(InnerArray)); } - return MoveTemp(Array); + return MoveTemp(NestedArray); } template @@ -124,17 +124,17 @@ public: } template - static TArray> FromStdVector(const std::vector>& Vector) + static TArray> FromStdVector(const std::vector>& NestedVector) { - TArray> Array; + TArray> NestedArray; - for (const std::vector& InnerVector: Vector) + for (const std::vector& InnerVector: NestedVector) { TArray InnerArray{FromStdVector(InnerVector)}; - Array.Add(MoveTemp(InnerArray)); + NestedArray.Add(MoveTemp(InnerArray)); } - return MoveTemp(Array); + return MoveTemp(NestedArray); } template @@ -145,17 +145,17 @@ public: } template - static FORCEINLINE std::vector> ToStdVector(const TArray>& Array) + static std::vector> ToStdVector(const TArray>& NestedArray) { - std::vector> Vector; + std::vector> NestedVector; - for (const TArray& InnerArray: Array) + for (const TArray& InnerArray: NestedArray) { std::vector InnerVector{ToStdVector(InnerArray)}; - Vector.emplace_back(MoveTemp(InnerVector)); + NestedVector.emplace_back(MoveTemp(InnerVector)); } - return MoveTemp(Vector); + return MoveTemp(NestedVector); } template @@ -173,17 +173,17 @@ public: } template - static std::vector> ToStdVector(const TArray>& Array) + static std::vector> ToStdVector(const TArray>& NestedArray) { - std::vector> Vector; + std::vector> NestedVector; - for (const TArray& InnerArray: Array) + for (const TArray& InnerArray: NestedArray) { std::vector InnerVector{ToStdVector(InnerArray)}; - Vector.emplace_back(MoveTemp(InnerVector)); + NestedVector.emplace_back(MoveTemp(InnerVector)); } - return MoveTemp(Vector); + return MoveTemp(NestedVector); } template - static std::vector> ToStdVector(const TArray>& Array) + static std::vector> ToStdVector(const TArray>& NestedArray) { - std::vector> Vector; + std::vector> NestedVector; - for (const TArray& InnerArray: Array) + for (const TArray& InnerArray: NestedArray) { std::vector InnerVector{ToStdVector(InnerArray)}; - Vector.emplace_back(MoveTemp(InnerVector)); + NestedVector.emplace_back(MoveTemp(InnerVector)); } - return MoveTemp(Vector); + return MoveTemp(NestedVector); } template @@ -246,46 +246,46 @@ public: } template - static TArray> FromImplType(const TArray>& ImplArray) + static TArray> FromImplType(const TArray>& NestedImplArray) { - TArray> Array; + TArray> NestedArray; - for (const TArray& InnerImplArray: ImplArray) + for (const TArray& InnerImplArray: NestedImplArray) { TArray InnerArray{FromImplType(InnerImplArray)}; - Array.Add(MoveTemp(InnerArray)); + NestedArray.Add(MoveTemp(InnerArray)); } - return MoveTemp(Array); + return MoveTemp(NestedArray); } template - static TArray> FromImplType(UObject* Outer, const TArray>& ImplArray) + static TArray> FromImplType(UObject* Outer, const TArray>& NestedImplArray) { - TArray> Array; + TArray> NestedArray; - for (const TArray& InnerImplArray: ImplArray) + for (const TArray& InnerImplArray: NestedImplArray) { TArray InnerArray{FromImplType(Outer, InnerImplArray)}; - Array.Add(MoveTemp(InnerArray)); + NestedArray.Add(MoveTemp(InnerArray)); } - return MoveTemp(Array); + return MoveTemp(NestedArray); } template - static TArray FromImplType(const TArray>& ImplArray) + static TArray FromImplType(const TArray>& NestedImplArray) { - TArray Array; + TArray NestedBPArray; - for (const TArray& InnerImplArray: ImplArray) + for (const TArray& InnerImplArray: NestedImplArray) { TArray InnerArray{FromImplType(InnerImplArray)}; S InnerArrayContainer{MoveTemp(InnerArray)}; - Array.Add(MoveTemp(InnerArrayContainer)); + NestedBPArray.Add(MoveTemp(InnerArrayContainer)); } - return MoveTemp(Array); + return MoveTemp(NestedBPArray); } template @@ -405,132 +405,152 @@ public: } template S::*InnerArray> - static TArray> FromBPNestedArray(const TArray& BPNestedArray) + static TArray> FromNestedBPArray(const TArray& NestedBPArray) { TArray> NestedArray; - for (const S& BPInnerArrayContainer: BPNestedArray) + for (const S& InnerBPArrayContainer: NestedBPArray) { - NestedArray.Add(BPInnerArrayContainer.*InnerArray); + NestedArray.Add(InnerBPArrayContainer.*InnerArray); } return MoveTemp(NestedArray); } template - static TArray ToBPNestedArray(const TArray>& NestedArray) + static TArray ToNestedBPArray(const TArray>& Array) { - TArray BPNestedArray; + TArray NestedBPArray; - for (const TArray& InnerArray: NestedArray) + for (const TArray& InnerArray: Array) { - S BPInnerArrayContainer{InnerArray}; - BPNestedArray.Add(MoveTemp(BPInnerArrayContainer)); + S InnerBPArrayContainer{InnerArray}; + NestedBPArray.Add(MoveTemp(InnerBPArrayContainer)); } - return MoveTemp(BPNestedArray); + return MoveTemp(NestedBPArray); } template - static TArray ToBPNestedArray(const TArray>& NestedArray) + static TArray ToNestedBPArray(const TArray>& NestedArray) { - TArray BPNestedArray; + TArray NestedBPArray; for (const TArray& InnerArray: NestedArray) { - S BPInnerArrayContainer{InnerArray}; - BPNestedArray.Add(MoveTemp(BPInnerArrayContainer)); + S InnerBPArrayContainer{InnerArray}; + NestedBPArray.Add(MoveTemp(InnerBPArrayContainer)); } - return MoveTemp(BPNestedArray); + return MoveTemp(NestedBPArray); } static TArray QuatsToRotators(const TArray& QuatsArray); - static TArray> QuatsToRotators(const TArray>& QuatsNestedArray); + static TArray> QuatsToRotators(const TArray>& QuatsArray); template S::*InnerArray> static TArray> QuatsToRotators(const TArray& QuatsNestedArray) { - TArray> RotatorsNestedArray; + TArray> RotatorsArray; - for (const S& BPQuatsInnerArrayContainer: QuatsNestedArray) + for (const S& QuatsInnerBPArrayContainer: QuatsNestedArray) { - RotatorsNestedArray.Add(QuatsToRotators(BPQuatsInnerArrayContainer.*InnerArray)); + RotatorsArray.Add(QuatsToRotators(QuatsInnerBPArrayContainer.*InnerArray)); } - return MoveTemp(RotatorsNestedArray); + return MoveTemp(RotatorsArray); } template - static TArray QuatsToRotators(const TArray>& QuatsNestedArray) + static TArray QuatsToRotators(const TArray>& QuatsArray) { - TArray BPRotatorsNestedArray; + TArray RotatorsNestedBPArray; - for (const TArray& QuatsInnerArray: QuatsNestedArray) + for (const TArray& QuatsInnerArray: QuatsArray) { - S BPRotatorsInnerArrayContainer{QuatsToRotators(QuatsInnerArray)}; - BPRotatorsNestedArray.Add(MoveTemp(BPRotatorsInnerArrayContainer)); + S RotatorsInnerBPArrayContainer{QuatsToRotators(QuatsInnerArray)}; + RotatorsNestedBPArray.Add(MoveTemp(RotatorsInnerBPArrayContainer)); } - return MoveTemp(BPRotatorsNestedArray); + return MoveTemp(RotatorsNestedBPArray); } template Q::*InnerArray> static TArray QuatsToRotators(const TArray& QuatsNestedArray) { - TArray BPRotatorsNestedArray; + TArray RotatorsNestedBPArray; for (const Q& QuatsInnerArrayContainer: QuatsNestedArray) { - R BPRotatorsInnerArrayContainer{QuatsToRotators(QuatsInnerArrayContainer.*InnerArray)}; - BPRotatorsNestedArray.Add(MoveTemp(BPRotatorsInnerArrayContainer)); + R RotatorsInnerBPArrayContainer{QuatsToRotators(QuatsInnerArrayContainer.*InnerArray)}; + RotatorsNestedBPArray.Add(MoveTemp(RotatorsInnerBPArrayContainer)); } - return MoveTemp(BPRotatorsNestedArray); + return MoveTemp(RotatorsNestedBPArray); } - static TArray RotatorsToQuats(const TArray& RotatorsArray); + static TArray RotatorsToQuats(const TArray& RotatorsNestedArray); static TArray> RotatorsToQuats(const TArray>& RotatorsNestedArray); template S::*InnerArray> static TArray> RotatorsToQuats(const TArray& RotatorsNestedArray) { - TArray> QuatsNestedArray; + TArray> QuatsArray; - for (const S& BPRotatorsInnerArrayContainer: RotatorsNestedArray) + for (const S& RotatorsInnerBPArrayContainer: RotatorsNestedArray) { - QuatsNestedArray.Add(RotatorsToQuats(BPRotatorsInnerArrayContainer.*InnerArray)); + QuatsArray.Add(RotatorsToQuats(RotatorsInnerBPArrayContainer.*InnerArray)); } - return MoveTemp(QuatsNestedArray); + return MoveTemp(QuatsArray); } template static TArray RotatorsToQuats(const TArray>& RotatorsNestedArray) { - TArray BPQuatsNestedArray; + TArray QuatsNestedBPArray; for (const TArray& RotatorsInnerArray: RotatorsNestedArray) { - S BPQuatsInnerArrayContainer{RotatorsToQuats(RotatorsInnerArray)}; - BPQuatsNestedArray.Add(MoveTemp(BPQuatsInnerArrayContainer)); + S QuatsInnerBPArrayContainer{RotatorsToQuats(RotatorsInnerArray)}; + QuatsNestedBPArray.Add(MoveTemp(QuatsInnerBPArrayContainer)); } - return MoveTemp(BPQuatsNestedArray); + return MoveTemp(QuatsNestedBPArray); } template Q::*InnerArray> static TArray RotatorsToQuats(const TArray& RotatorsNestedArray) { - TArray BPQuatsNestedArray; + TArray QuatsNestedBPArray; for (const Q& RotatorsInnerArrayContainer: RotatorsNestedArray) { - R BPQuatsInnerArrayContainer{RotatorsToQuats(RotatorsInnerArrayContainer.*InnerArray)}; - BPQuatsNestedArray.Add(MoveTemp(BPQuatsInnerArrayContainer)); + R QuatsInnerBPArrayContainer{RotatorsToQuats(RotatorsInnerArrayContainer.*InnerArray)}; + QuatsNestedBPArray.Add(MoveTemp(QuatsInnerBPArrayContainer)); } - return MoveTemp(BPQuatsNestedArray); + return MoveTemp(QuatsNestedBPArray); + } + + static TArray FromMillimeters(const std::vector& Vector); + static TArray> FromMillimeters(const std::vector>& NestedVector); + + static std::vector ToMillimeters(const TArray& Array); + static std::vector> ToMillimeters(const TArray>& NestedArray); + + template S::*InnerArray> + static std::vector> ToMillimeters(const TArray& NestedBPArray) + { + std::vector> NestedVector; + + for (const S& InnerBPArrayContainer: NestedBPArray) + { + std::vector InnerVector{ToMillimeters(InnerBPArrayContainer.*InnerArray)}; + NestedVector.emplace_back(MoveTemp(InnerVector)); + } + + return MoveTemp(NestedVector); } public: diff --git a/Source/SenseGloveUtils/Public/SGUtils/SGUnits.h b/Source/SenseGloveUtils/Public/SGUtils/SGUnits.h new file mode 100644 index 00000000..6773e673 --- /dev/null +++ b/Source/SenseGloveUtils/Public/SGUtils/SGUnits.h @@ -0,0 +1,66 @@ +/** + * @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" + +class SENSEGLOVEUTILS_API FSGUnits final +{ +public: + static FORCEINLINE constexpr float CentimetersToMillimetersMultiplier() + { + return 10.0f; + } + + static FORCEINLINE constexpr float MillimetersToCentimetersMultiplier() + { + return 0.1f; + } + + static FORCEINLINE float CentimetersToMillimeters(const float Value) + { + return Value * CentimetersToMillimetersMultiplier(); + } + + static FORCEINLINE float MillimetersToCentimeters(const float Value) + { + return Value * MillimetersToCentimetersMultiplier(); + } + +public: + FSGUnits() = delete; + virtual ~FSGUnits() = delete; +}; \ No newline at end of file