/** * @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 "SGCore/SGSenseGloveHandProfile.h" #include "Runtime/Launch/Resources/Version.h" #include "SGCore/SGHandInterpolator.h" #include "SGCoreImpl/SGExportedFunctions.h" #include "SGCoreImpl/SGSenseGloveHandProfileImpl.h" #include "SGInterop/SGIC_ESGFingerSolver.h" #include "SGInterop/SGIC_ESGThumbSolver.h" #include "SGInterop/SGIC_FSGHandInterpolatorImpl.h" #include "SGInterop/SGIC_FSGSenseGloveHandProfileImpl.h" #include "SGInterop/SGIC_FString.h" #include "SGInterop/SGIC_FVector.h" #include "SGInterop/SGIC_TArray_FVector.h" struct USGSenseGloveHandProfile::FImpl { /************************ * Member variables ************************/ FSGSenseGloveHandProfileImpl SenseGloveHandProfileImpl; /************************ * Owner object ************************/ USGSenseGloveHandProfile* Owner; /************************ * Constructor / Destructor ************************/ explicit FImpl(USGSenseGloveHandProfile* InOwner); ~FImpl(); /************************ * Default copy constructor & copy assignment operator ************************/ FImpl(const FImpl& Rhs) = default; FImpl& operator=(const FImpl& Rhs) = default; /************************ * Methods ************************/ void SyncUProperties(); void SyncImplObject(); }; USGSenseGloveHandProfile* USGSenseGloveHandProfile::NewSenseGloveHandProfile( UObject* Outer, const FSGSenseGloveHandProfileImpl& SenseGloveHandProfileImpl) { USGSenseGloveHandProfile* Instance = NewObject(Outer); Instance->SetSenseGloveHandProfileImpl(SenseGloveHandProfileImpl); return Instance; } USGSenseGloveHandProfile* USGSenseGloveHandProfile::NewSenseGloveHandProfile(UObject* Outer) { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileImplContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_ctor(&OutSenseGloveHandProfileImplContainer); return NewSenseGloveHandProfile(Outer, MoveTemp(OutSenseGloveHandProfileImplContainer.SenseGloveHandProfileImpl)); } USGSenseGloveHandProfile* USGSenseGloveHandProfile::NewSenseGloveHandProfile( UObject* Outer, const bool bRightHanded, const USGHandInterpolator* Interpolator, const ESGThumbSolver ThumbSolver, const ESGFingerSolver FingerSolver, const TArray& FingerThimbleOffset) { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileImplContainer; FSGIC_FSGHandInterpolatorImpl InterpolatorContainer{Interpolator->ToHandInterpolatorImpl()}; FSGIC_ESGThumbSolver ThumbSolverContainer{ThumbSolver}; FSGIC_ESGFingerSolver FingerSolverContainer{FingerSolver}; FSGIC_TArray_FVector FingerThimbleOffsetContainer{FingerThimbleOffset}; SGCoreImpl_FSGSenseGloveHandProfileImpl_ctor_bRightHanded_Interpolator_ThumbSolver_FingerSolver_FingerThimbleOffset( &OutSenseGloveHandProfileImplContainer, bRightHanded, &InterpolatorContainer, &ThumbSolverContainer, &FingerSolverContainer, &FingerThimbleOffsetContainer); return NewSenseGloveHandProfile(Outer, MoveTemp(OutSenseGloveHandProfileImplContainer.SenseGloveHandProfileImpl)); } USGSenseGloveHandProfile* USGSenseGloveHandProfile::Default(UObject* Outer, const bool bRightHanded) { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileImplContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_Default(&OutSenseGloveHandProfileImplContainer, bRightHanded); return NewSenseGloveHandProfile(Outer, MoveTemp(OutSenseGloveHandProfileImplContainer.SenseGloveHandProfileImpl)); } USGSenseGloveHandProfile* USGSenseGloveHandProfile::Deserialize(UObject* Outer, const FString& SerializedString) { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileImplContainer; FSGIC_FString SerializedStringContainer{SerializedString}; SGCoreImpl_FSGSenseGloveHandProfileImpl_Deserialize(&OutSenseGloveHandProfileImplContainer, &SerializedStringContainer); return NewSenseGloveHandProfile(Outer, MoveTemp(OutSenseGloveHandProfileImplContainer.SenseGloveHandProfileImpl)); } FVector USGSenseGloveHandProfile::GetDefaultThimbleOffset() { FSGIC_FVector OutOffsetContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_GetDefaultThimbleOffset(&OutOffsetContainer); return MoveTemp(OutOffsetContainer.Vector); } USGSenseGloveHandProfile::USGSenseGloveHandProfile() : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */ { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileImplContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_ctor(&OutSenseGloveHandProfileImplContainer); Pimpl->SenseGloveHandProfileImpl = MoveTemp(OutSenseGloveHandProfileImplContainer.SenseGloveHandProfileImpl); Pimpl->SyncUProperties(); } USGSenseGloveHandProfile::USGSenseGloveHandProfile(const bool bRightHanded, const USGHandInterpolator* Interpolator, const ESGThumbSolver ThumbSolver, const ESGFingerSolver FingerSolver, const TArray& FingerThimbleOffset) : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */ { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileImplContainer; FSGIC_FSGHandInterpolatorImpl InterpolatorContainer{Interpolator->ToHandInterpolatorImpl()}; FSGIC_ESGThumbSolver ThumbSolverContainer{ThumbSolver}; FSGIC_ESGFingerSolver FingerSolverContainer{FingerSolver}; FSGIC_TArray_FVector FingerThimbleOffsetContainer{FingerThimbleOffset}; SGCoreImpl_FSGSenseGloveHandProfileImpl_ctor_bRightHanded_Interpolator_ThumbSolver_FingerSolver_FingerThimbleOffset( &OutSenseGloveHandProfileImplContainer, bRightHanded, &InterpolatorContainer, &ThumbSolverContainer, &FingerSolverContainer, &FingerThimbleOffsetContainer); Pimpl->SenseGloveHandProfileImpl = MoveTemp(OutSenseGloveHandProfileImplContainer.SenseGloveHandProfileImpl); Pimpl->SyncUProperties(); } USGSenseGloveHandProfile::USGSenseGloveHandProfile(const FSGSenseGloveHandProfileImpl& SenseGloveHandProfileImpl) : #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */ { SetSenseGloveHandProfileImpl(SenseGloveHandProfileImpl); Pimpl->SyncUProperties(); } USGSenseGloveHandProfile::~USGSenseGloveHandProfile() = default; void USGSenseGloveHandProfile::SetSenseGloveHandProfileImpl( const FSGSenseGloveHandProfileImpl& SenseGloveHandProfileImpl) { FSGIC_FSGSenseGloveHandProfileImpl OutSenseGloveHandProfileContainer; FSGIC_FSGSenseGloveHandProfileImpl RhsContainer{SenseGloveHandProfileImpl}; SGCoreImpl_FSGSenseGloveHandProfileImpl_ctor_copy(&OutSenseGloveHandProfileContainer, &RhsContainer); Pimpl->SenseGloveHandProfileImpl = MoveTemp(OutSenseGloveHandProfileContainer.SenseGloveHandProfileImpl); } const FSGSenseGloveHandProfileImpl& USGSenseGloveHandProfile::ToSenseGloveHandProfileImpl() const { Pimpl->SyncImplObject(); return Pimpl->SenseGloveHandProfileImpl; } bool USGSenseGloveHandProfile::IsRight() const { FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; return SGCoreImpl_FSGSenseGloveHandProfileImpl_IsRight(&InstanceContainer); } USGHandInterpolator* USGSenseGloveHandProfile::GetInterpolationSet(UObject* Outer) const { FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; FSGIC_FSGHandInterpolatorImpl OutSetContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_GetInterpolationSet(&InstanceContainer, &OutSetContainer); return USGHandInterpolator::NewHandInterpolator(Outer, MoveTemp(OutSetContainer.HandInterpolatorImpl)); } ESGThumbSolver USGSenseGloveHandProfile::GetThumbSolver() const { FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; FSGIC_ESGThumbSolver OutSolverContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_GetThumbSolver(&InstanceContainer, &OutSolverContainer); return OutSolverContainer.Solver; } ESGFingerSolver USGSenseGloveHandProfile::GetFingerSolver() const { FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; FSGIC_ESGFingerSolver OutSolverContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_GetFingerSolver(&InstanceContainer, &OutSolverContainer); return OutSolverContainer.Solver; } TArray USGSenseGloveHandProfile::GetFingerThimbleOffset() const { FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; FSGIC_TArray_FVector OutOffsetContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_GetFingerThimbleOffset(&InstanceContainer, &OutOffsetContainer); return MoveTemp(OutOffsetContainer.Array); } bool USGSenseGloveHandProfile::Equals(const USGSenseGloveHandProfile* SenseGloveHandProfile) const { Pimpl->SyncImplObject(); FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; FSGIC_FSGSenseGloveHandProfileImpl SenseGloveHandProfileContainer{ SenseGloveHandProfile->ToSenseGloveHandProfileImpl()}; return SGCoreImpl_FSGSenseGloveHandProfileImpl_Equals(&InstanceContainer, &SenseGloveHandProfileContainer); } void USGSenseGloveHandProfile::Reset() { Pimpl->SyncImplObject(); FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; SGCoreImpl_FSGSenseGloveHandProfileImpl_Reset(&InstanceContainer); Pimpl->SyncUProperties(); } FString USGSenseGloveHandProfile::SGSerialize() const { Pimpl->SyncImplObject(); FSGIC_FSGSenseGloveHandProfileImpl InstanceContainer{ToSenseGloveHandProfileImpl()}; FSGIC_FString OutStringContainer; SGCoreImpl_FSGSenseGloveHandProfileImpl_Serialize(&InstanceContainer, &OutStringContainer); return MoveTemp(OutStringContainer.String); } USGSenseGloveHandProfile::FImpl::FImpl(USGSenseGloveHandProfile* InOwner) : Owner(InOwner) { } USGSenseGloveHandProfile::FImpl::~FImpl() = default; void USGSenseGloveHandProfile::FImplDeleter::operator()(const FImpl* P) const { delete P; } void USGSenseGloveHandProfile::FImpl::SyncUProperties() { } void USGSenseGloveHandProfile::FImpl::SyncImplObject() { }