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

214 lines
7.3 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2024 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#include "SGCoreImpl/SGHandLayerImpl.h"
#include <vector>
#include "Containers/StringConv.h"
#include "SGBuildHacks/SGInclude_Core_CustomWaveform.h"
#include "SGBuildHacks/SGInclude_Core_HandLayer.h"
#include "SGBuildHacks/SGInclude_Core_HandPose.h"
#include "SGBuildHacks/SGInclude_Core_Quat.h"
#include "SGBuildHacks/SGInclude_Core_Vect3D.h"
#include "SGCoreImpl/SGCustomWaveformImpl.h"
#include "SGCoreImpl/SGCustomWaveformImpl.h"
#include "SGCoreImpl/SGCoreEnumCast.h"
#include "SGCoreImpl/SGHandPoseImpl.h"
#include "SGCoreImpl/SGHapticGloveImpl.h"
#include "SGCoreImpl/SGQuatImpl.h"
#include "SGCoreImpl/SGVect3DImpl.h"
#include "SGUtils/SGArrayUtils.h"
bool FSGHandLayerImpl::DeviceConnected(const bool bRightHanded)
{
return FHandLayerType::DeviceConnected(bRightHanded);
}
ESGDeviceType FSGHandLayerImpl::GetDeviceType(const bool bRightHanded)
{
return FSGCoreEnumCast::ToESGDeviceType(FHandLayerType::GetDeviceType(bRightHanded));
}
bool FSGHandLayerImpl::GetFirstGloveHandedness()
{
return FHandLayerType::GetFirstGloveHandedness();
}
int32 FSGHandLayerImpl::GlovesConnected()
{
return FHandLayerType::GlovesConnected();
}
bool FSGHandLayerImpl::GetGloveInstance(const bool bRightHanded, TSharedPtr<FSGHapticGloveImpl>& OutGlove)
{
FSGHapticGloveImpl::FHapticGlovePtrType Glove;
const bool bResult = FHandLayerType::GetGloveInstance(bRightHanded, Glove);
if (bResult)
{
OutGlove = MakeShared<FSGHapticGloveImpl>(MoveTemp(Glove));
}
return bResult;
}
ESGHapticGloveCalibrationState FSGHandLayerImpl::GetCalibrationState(const bool bRightHanded)
{
return FSGCoreEnumCast::ToESGHapticGloveCalibrationState(FHandLayerType::GetCalibrationState(bRightHanded));
}
FString FSGHandLayerImpl::GetCalibrationInstructions(const bool bRightHanded)
{
FString Instructions{UTF8_TO_TCHAR(FHandLayerType::GetCalibrationInstructions(bRightHanded).c_str())};
return MoveTemp(Instructions);
}
void FSGHandLayerImpl::ResetCalibration(const bool bRightHanded)
{
FHandLayerType::ResetCalibration(bRightHanded);
}
void FSGHandLayerImpl::EndCalibration(const bool bRightHanded)
{
FHandLayerType::EndCalibration(bRightHanded);
}
bool FSGHandLayerImpl::GetHandPose(const bool bRightHanded, FSGHandPoseImpl& OutHandPose)
{
FSGHandPoseImpl::FHandPoseType HandPose;
const bool bResult = FHandLayerType::GetHandPose(bRightHanded, HandPose);
OutHandPose = FSGHandPoseImpl{HandPose};
return bResult;
}
void FSGHandLayerImpl::GetWristLocation(
const bool bRightHanded, const FVector& ReferencePosition, const FQuat& ReferenceRotation,
const ESGPositionalTrackingHardware TrackingHardware,
FVector& OutWristPosition,
FQuat& OutWristRotation)
{
FSGVect3DImpl::FVect3DType WristPosition;
FSGQuatImpl::FQuatType WristRotation;
FHandLayerType::GetWristLocation(
bRightHanded,
FSGVect3DImpl{ReferencePosition}.ToVect3D(), FSGQuatImpl{ReferenceRotation}.ToQuat(),
FSGCoreEnumCast::ToEPositionalTrackingHardware(TrackingHardware),
WristPosition, WristRotation);
OutWristPosition = FSGVect3DImpl{WristPosition}.ToFVector();
OutWristRotation = FSGQuatImpl{WristRotation}.ToFQuat();
}
bool FSGHandLayerImpl::SendHaptics(const bool bRightHanded)
{
return FHandLayerType::SendHaptics(bRightHanded);
}
void FSGHandLayerImpl::StopAllHaptics(const bool bRightHanded)
{
FHandLayerType::StopAllHaptics(bRightHanded);
}
bool FSGHandLayerImpl::QueueCommand_ForceFeedbackLevel(
const bool bRightHanded, const int32 Finger, const float Level01, const bool bSendImmediate)
{
return FHandLayerType::QueueCommand_ForceFeedbackLevel(bRightHanded, Finger, Level01, bSendImmediate);
}
bool FSGHandLayerImpl::QueueCommand_ForceFeedbackLevels(
const bool bRightHanded, const TArray<float>& Levels01, const bool bSendImmediate)
{
std::vector<float> Levels01Vector{FSGArrayUtils::ToStdVector(Levels01)};
return FHandLayerType::QueueCommand_ForceFeedbackLevels(bRightHanded, MoveTemp(Levels01Vector), bSendImmediate);
}
bool FSGHandLayerImpl::QueueCommand_SetVibroLevel(
const bool bRightHanded, const int32 Finger, const float Level01, const bool bSendImmediate)
{
return FHandLayerType::QueueCommand_SetVibroLevel(bRightHanded, Finger, Level01, bSendImmediate);
}
bool FSGHandLayerImpl::QueueCommand_SetVibroLevels(
const bool bRightHanded, const TArray<float>& Levels01, const bool bSendImmediate)
{
std::vector<float> Levels01Vector{FSGArrayUtils::ToStdVector(Levels01)};
return FHandLayerType::QueueCommand_SetVibroLevels(bRightHanded, MoveTemp(Levels01Vector), bSendImmediate);
}
bool FSGHandLayerImpl::SupportsCustomWaveform(const bool bRightHanded, const ESGHapticLocation AtLocation)
{
return FHandLayerType::SupportsCustomWaveform(bRightHanded, FSGCoreEnumCast::ToEHapticLocation(AtLocation));
}
bool FSGHandLayerImpl::SendCustomWaveform(
const bool bRightHanded, FSGCustomWaveformImpl& OutWaveform, const ESGHapticLocation Location)
{
const bool bResult = FHandLayerType::SendCustomWaveform(
bRightHanded, OutWaveform.ToCustomWaveform(), FSGCoreEnumCast::ToEHapticLocation(Location));
return bResult;
}
bool FSGHandLayerImpl::SupportsWristSqueeze(const bool bRightHanded)
{
return FHandLayerType::SupportsWristSqueeze(bRightHanded);
}
bool FSGHandLayerImpl::QueueCommand_WristSqueeze(
const bool bRightHanded, const float SqueezeLevel01, const bool bSendImmediate)
{
return FHandLayerType::QueueCommand_WristSqueeze(bRightHanded, SqueezeLevel01, bSendImmediate);
}
bool FSGHandLayerImpl::SupportsFlexionLocks(const bool bRightHanded)
{
return FHandLayerType::SupportsFlexionLocks(bRightHanded);
}
bool FSGHandLayerImpl::QueueCommand_FlexionLock(
const bool bRightHanded, const int32 Finger, const float Flexion01, const bool bSendImmediate)
{
return FHandLayerType::QueueCommand_FlexionLock(bRightHanded, Finger, Flexion01, bSendImmediate);
}
bool FSGHandLayerImpl::QueueCommand_ClearFlexionLock(
const bool bRightHanded, const int32 Finger, const bool bSendImmediate)
{
return FHandLayerType::QueueCommand_ClearFlexionLock(bRightHanded, Finger, bSendImmediate);
}