Files
Plugin/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGSenseGloveHandProfileImpl.cpp
T

268 lines
8.7 KiB
C++
Raw Normal View History

2022-11-02 22:43:14 +01:00
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#include "SGCoreImpl/SGSenseGloveHandProfileImpl.h"
#include <string>
#include <vector>
#include "Containers/StringConv.h"
#include "Runtime/Launch/Resources/Version.h"
#include "SGBuildHacks/SGInclude_Core_HandInterpolator.h"
#include "SGBuildHacks/SGInclude_Core_Quat.h"
#include "SGBuildHacks/SGInclude_Core_Vect3D.h"
#include "SGCoreImpl/SGCoreEnumCast.h"
#include "SGCoreImpl/SGHandInterpolatorImpl.h"
#include "SGCoreImpl/SGVect3DImpl.h"
#include "SGUtils/SGArrayUtils.h"
struct FSGSenseGloveHandProfileImpl::FImpl
{
/************************
* Member variables
************************/
FSenseGloveHandProfileType SenseGloveHandProfile;
/************************
* Owner object
************************/
FSGSenseGloveHandProfileImpl* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGSenseGloveHandProfileImpl* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FSGSenseGloveHandProfileImpl FSGSenseGloveHandProfileImpl::Default(const bool bRightHanded)
{
FSGSenseGloveHandProfileImpl SenseGloveHandProfileImpl(FSenseGloveHandProfileType::Default(bRightHanded));
return SenseGloveHandProfileImpl;
}
FSGSenseGloveHandProfileImpl FSGSenseGloveHandProfileImpl::Deserialize(const FString& SerializedString)
{
std::string Serialized(TCHAR_TO_UTF8(*SerializedString));
const FSGSenseGloveHandProfileImpl HandProfile(FSenseGloveHandProfileType::Deserialize(MoveTemp(Serialized)));
return HandProfile;
}
const FVector& FSGSenseGloveHandProfileImpl::GetDefaultThimbleOffset()
{
static const FVector DefaultThimbleOffset(
FSGVect3DImpl(FSenseGloveHandProfileType::GetDefaultThimbleOffset()).ToFVector());
return DefaultThimbleOffset;
}
FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl()
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
}
FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(const bool bRightHanded,
const FSGHandInterpolatorImpl& Interpolator,
const ESGThumbSolver ThumbSolver,
const ESGFingerSolver FingerSolver,
const TArray<FVector>& FingerThimbleOffset)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
std::vector<FSGVect3DImpl::FVect3DType> FingerThimbleOffsetVector{
2022-11-16 14:55:29 +01:00
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(FingerThimbleOffset)
2022-11-02 22:43:14 +01:00
};
Pimpl->SenseGloveHandProfile = FSenseGloveHandProfileType(
bRightHanded, Interpolator.ToHandInterpolator(),
FSGCoreEnumCast::ToEThumbSolver(ThumbSolver),
FSGCoreEnumCast::ToEFingerSolver(FingerSolver),
MoveTemp(FingerThimbleOffsetVector));
}
FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(const FSenseGloveHandProfileType& SenseGloveHandProfile)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->SenseGloveHandProfile = SenseGloveHandProfile;
}
FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(const FSGSenseGloveHandProfileImpl& Rhs)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->Owner = this;
}
FSGSenseGloveHandProfileImpl::FSGSenseGloveHandProfileImpl(FSGSenseGloveHandProfileImpl&& Rhs)
#if SG_CPP17
noexcept
#endif /* SG_CPP17 */
= default;
2022-11-02 22:43:14 +01:00
FSGSenseGloveHandProfileImpl::~FSGSenseGloveHandProfileImpl() = default;
FSGSenseGloveHandProfileImpl& FSGSenseGloveHandProfileImpl::operator=(const FSGSenseGloveHandProfileImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGSenseGloveHandProfileImpl& FSGSenseGloveHandProfileImpl::operator=(FSGSenseGloveHandProfileImpl&& Rhs)
#if SG_CPP17
noexcept
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
= default;
const FSGSenseGloveHandProfileImpl::FSenseGloveHandProfileType& FSGSenseGloveHandProfileImpl::ToSenseGloveHandProfile(
) const
{
return Pimpl->SenseGloveHandProfile;
}
bool FSGSenseGloveHandProfileImpl::IsRight() const
{
return Pimpl->SenseGloveHandProfile.IsRight();
}
void FSGSenseGloveHandProfileImpl::SetIsRight(const bool bRightHanded)
{
Pimpl->SenseGloveHandProfile.SetIsRight(bRightHanded);
}
FSGHandInterpolatorImpl FSGSenseGloveHandProfileImpl::GetInterpolationSet() const
{
const FSGHandInterpolatorImpl HandInterpolatorImpl(
FSGHandInterpolatorImpl::FHandInterpolatorType(Pimpl->SenseGloveHandProfile.GetInterpolationSet()));
return HandInterpolatorImpl;
}
void FSGSenseGloveHandProfileImpl::SetInterpolationSet(const FSGHandInterpolatorImpl& InterpolationSet)
{
Pimpl->SenseGloveHandProfile.SetInterpolationSet(InterpolationSet.ToHandInterpolator());
}
ESGThumbSolver FSGSenseGloveHandProfileImpl::GetThumbSolver() const
{
return FSGCoreEnumCast::ToESGThumbSolver(Pimpl->SenseGloveHandProfile.GetThumbSolver());
}
void FSGSenseGloveHandProfileImpl::SetThumbSolver(const ESGThumbSolver ThumbSolver)
{
Pimpl->SenseGloveHandProfile.SetThumbSolver(FSGCoreEnumCast::ToEThumbSolver(ThumbSolver));
}
ESGFingerSolver FSGSenseGloveHandProfileImpl::GetFingerSolver() const
{
return FSGCoreEnumCast::ToESGFingerSolver(Pimpl->SenseGloveHandProfile.GetFingerSolver());
}
void FSGSenseGloveHandProfileImpl::SetFingerSolver(const ESGFingerSolver FingerSolver)
{
Pimpl->SenseGloveHandProfile.SetFingerSolver(FSGCoreEnumCast::ToEFingerSolver(FingerSolver));
}
TArray<FVector> FSGSenseGloveHandProfileImpl::GetFingerThimbleOffset() const
{
const TArray<FVector> FingerThimbleOffset{
2022-11-16 14:55:29 +01:00
FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(
2022-11-02 22:43:14 +01:00
Pimpl->SenseGloveHandProfile.GetFingerThimbleOffset())
};
return FingerThimbleOffset;
}
void FSGSenseGloveHandProfileImpl::SetFingerThimbleOffset(const TArray<FVector>& FingerThimbleOffset)
{
std::vector<FSGVect3DImpl::FVect3DType> FingerThimbleOffsetVector{
2022-11-16 14:55:29 +01:00
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(FingerThimbleOffset)
2022-11-02 22:43:14 +01:00
};
Pimpl->SenseGloveHandProfile.SetFingerThimbleOffset(MoveTemp(FingerThimbleOffsetVector));
}
bool FSGSenseGloveHandProfileImpl::Equals(const FSGSenseGloveHandProfileImpl& SenseGloveHandProfileImpl) const
{
return Pimpl->SenseGloveHandProfile.Equals(SenseGloveHandProfileImpl.ToSenseGloveHandProfile());
}
void FSGSenseGloveHandProfileImpl::Reset()
{
Pimpl->SenseGloveHandProfile.Reset();
}
FString FSGSenseGloveHandProfileImpl::Serialize() const
{
const FString Serialized(UTF8_TO_TCHAR(Pimpl->SenseGloveHandProfile.Serialize().c_str()));
return Serialized;
}
FSGSenseGloveHandProfileImpl::FImpl::FImpl(FSGSenseGloveHandProfileImpl* InOwner)
: Owner(InOwner)
{
}
FSGSenseGloveHandProfileImpl::FImpl::~FImpl() = default;
void FSGSenseGloveHandProfileImpl::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}