improve the wrist tracking code when using motion controllers

This commit is contained in:
Mamadou Babaei
2024-08-16 18:00:53 +02:00
parent a238887ac2
commit c132a967f3
@@ -1495,8 +1495,11 @@ bool FSGXRTracker::FImpl::UpdateXRHandTrackingData(
XR_ENSURE(XRLocateHandJointsEXT(OutHandState.HandTracker, &LocateInfo, &OutHandState.Locations));
OutHandState.bReceivedJointPoses = OutHandState.Locations.isActive == XR_TRUE;
if (!!OutHandState.bReceivedJointPoses)
if (!OutHandState.bReceivedJointPoses)
{
return false;
}
static_assert(
XR_HAND_JOINT_PALM_EXT == 0 && XR_HAND_JOINT_LITTLE_TIP_EXT == XR_HAND_JOINT_COUNT_EXT - 1,
"XrHandJointEXT enum is not as assumed for the following loop!");
@@ -1512,7 +1515,6 @@ bool FSGXRTracker::FImpl::UpdateXRHandTrackingData(
}
return true;
}
return false;
}
@@ -1529,17 +1531,18 @@ bool FSGXRTracker::FImpl::GetOpenXRHandTrackingWristTransform(
FXRMotionControllerData MotionControllerData;
XRTrackingSystem->GetMotionControllerData(World, DeviceHand, MotionControllerData);
if (MotionControllerData.bValid)
if (!MotionControllerData.bValid)
{
return false;
}
static constexpr int32_t WristJointIndex = static_cast<int32>(EHandKeypoint::Wrist);
OutTransform = FTransform{
MotionControllerData.HandKeyRotations[WristJointIndex],
MotionControllerData.HandKeyPositions[WristJointIndex]
};
return true;
}
return false;
return true;
}
bool FSGXRTracker::FImpl::GetOpenXRWristTransform(
@@ -1556,14 +1559,18 @@ bool FSGXRTracker::FImpl::GetOpenXRWristTransform(
FRotator TrackerRotation;
const bool bGotTransform = MotionController->GetControllerOrientationAndPosition(
CurrentPlayerControllerIndex, MotionSource, TrackerRotation, TrackerLocation, WorldToMetersScale);
if (bGotTransform)
if (!bGotTransform)
{
const bool bIsRight = DeviceHand == EControllerHand::Right;
return false;
}
const FSGWristTrackingSettings& Settings{GetWristTrackingSettings()};
const bool bIsRight = DeviceHand == Settings.RightHandMotionSource;
const ESGPositionalTrackingHardware TrackingHardware = GetPositionalTrackingHardware();
if (TrackingHardware == ESGPositionalTrackingHardware::Custom)
{
FSGWristTrackingSettings Settings{GetWristTrackingSettings()};
if (bIsRight)
{
TrackerLocation += Settings.TrackingHardwareLocationOffsetRightHand;
@@ -1576,26 +1583,22 @@ bool FSGXRTracker::FImpl::GetOpenXRWristTransform(
}
}
FVector WristLocation;
FRotator WristRotation;
const USGHapticGlove* Glove{GetGlove(bIsRight)};
if (!IsValid(Glove))
{
return false;
}
FVector WristLocation;
FRotator WristRotation;
Glove->GetWristLocation(TrackerLocation, TrackerRotation, TrackingHardware,
WristLocation, WristRotation);
OutTransform = FTransform{MoveTemp(WristRotation), WristLocation};
OutTransform = FTransform{MoveTemp(WristRotation), MoveTemp(WristLocation)};
return true;
}
return false;
}
bool FSGXRTracker::FImpl::GetWristTransform(
const EControllerHand DeviceHand, FTransform& OutTransform, bool& bOutMotionSourceHandTracking) const
{