improve the wrist tracking code when using motion controllers
This commit is contained in:
@@ -1495,25 +1495,27 @@ bool FSGXRTracker::FImpl::UpdateXRHandTrackingData(
|
|||||||
XR_ENSURE(XRLocateHandJointsEXT(OutHandState.HandTracker, &LocateInfo, &OutHandState.Locations));
|
XR_ENSURE(XRLocateHandJointsEXT(OutHandState.HandTracker, &LocateInfo, &OutHandState.Locations));
|
||||||
|
|
||||||
OutHandState.bReceivedJointPoses = OutHandState.Locations.isActive == XR_TRUE;
|
OutHandState.bReceivedJointPoses = OutHandState.Locations.isActive == XR_TRUE;
|
||||||
if (!!OutHandState.bReceivedJointPoses)
|
if (!OutHandState.bReceivedJointPoses)
|
||||||
{
|
{
|
||||||
static_assert(
|
return false;
|
||||||
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!");
|
|
||||||
|
|
||||||
for (int j = 0; j < XR_HAND_JOINT_COUNT_EXT; ++j)
|
|
||||||
{
|
|
||||||
const XrHandJointLocationEXT& JointLocation{OutHandState.JointLocations[j]};
|
|
||||||
const XrPosef& Pose{JointLocation.pose};
|
|
||||||
FTransform Transform{ToFTransform(Pose, WorldToMetersScale)};
|
|
||||||
OutHandState.KeypointTransforms[j] = MoveTemp(Transform);
|
|
||||||
OutHandState.Radii[j] = JointLocation.radius * WorldToMetersScale;
|
|
||||||
// velocities would go here
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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!");
|
||||||
|
|
||||||
|
for (int j = 0; j < XR_HAND_JOINT_COUNT_EXT; ++j)
|
||||||
|
{
|
||||||
|
const XrHandJointLocationEXT& JointLocation{OutHandState.JointLocations[j]};
|
||||||
|
const XrPosef& Pose{JointLocation.pose};
|
||||||
|
FTransform Transform{ToFTransform(Pose, WorldToMetersScale)};
|
||||||
|
OutHandState.KeypointTransforms[j] = MoveTemp(Transform);
|
||||||
|
OutHandState.Radii[j] = JointLocation.radius * WorldToMetersScale;
|
||||||
|
// velocities would go here
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1529,17 +1531,18 @@ bool FSGXRTracker::FImpl::GetOpenXRHandTrackingWristTransform(
|
|||||||
|
|
||||||
FXRMotionControllerData MotionControllerData;
|
FXRMotionControllerData MotionControllerData;
|
||||||
XRTrackingSystem->GetMotionControllerData(World, DeviceHand, MotionControllerData);
|
XRTrackingSystem->GetMotionControllerData(World, DeviceHand, MotionControllerData);
|
||||||
if (MotionControllerData.bValid)
|
if (!MotionControllerData.bValid)
|
||||||
{
|
{
|
||||||
static constexpr int32_t WristJointIndex = static_cast<int32>(EHandKeypoint::Wrist);
|
return false;
|
||||||
OutTransform = FTransform{
|
|
||||||
MotionControllerData.HandKeyRotations[WristJointIndex],
|
|
||||||
MotionControllerData.HandKeyPositions[WristJointIndex]
|
|
||||||
};
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
static constexpr int32_t WristJointIndex = static_cast<int32>(EHandKeypoint::Wrist);
|
||||||
|
OutTransform = FTransform{
|
||||||
|
MotionControllerData.HandKeyRotations[WristJointIndex],
|
||||||
|
MotionControllerData.HandKeyPositions[WristJointIndex]
|
||||||
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FSGXRTracker::FImpl::GetOpenXRWristTransform(
|
bool FSGXRTracker::FImpl::GetOpenXRWristTransform(
|
||||||
@@ -1556,44 +1559,44 @@ bool FSGXRTracker::FImpl::GetOpenXRWristTransform(
|
|||||||
FRotator TrackerRotation;
|
FRotator TrackerRotation;
|
||||||
const bool bGotTransform = MotionController->GetControllerOrientationAndPosition(
|
const bool bGotTransform = MotionController->GetControllerOrientationAndPosition(
|
||||||
CurrentPlayerControllerIndex, MotionSource, TrackerRotation, TrackerLocation, WorldToMetersScale);
|
CurrentPlayerControllerIndex, MotionSource, TrackerRotation, TrackerLocation, WorldToMetersScale);
|
||||||
if (bGotTransform)
|
if (!bGotTransform)
|
||||||
{
|
{
|
||||||
const bool bIsRight = DeviceHand == EControllerHand::Right;
|
return false;
|
||||||
|
|
||||||
const ESGPositionalTrackingHardware TrackingHardware = GetPositionalTrackingHardware();
|
|
||||||
if (TrackingHardware == ESGPositionalTrackingHardware::Custom)
|
|
||||||
{
|
|
||||||
FSGWristTrackingSettings Settings{GetWristTrackingSettings()};
|
|
||||||
if (bIsRight)
|
|
||||||
{
|
|
||||||
TrackerLocation += Settings.TrackingHardwareLocationOffsetRightHand;
|
|
||||||
TrackerRotation += Settings.TrackingHardwareRotationOffsetRightHand;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TrackerLocation += Settings.TrackingHardwareLocationOffsetLeftHand;
|
|
||||||
TrackerRotation += Settings.TrackingHardwareRotationOffsetLeftHand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FVector WristLocation;
|
|
||||||
FRotator WristRotation;
|
|
||||||
|
|
||||||
const USGHapticGlove* Glove{GetGlove(bIsRight)};
|
|
||||||
if (!IsValid(Glove))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Glove->GetWristLocation(TrackerLocation, TrackerRotation, TrackingHardware,
|
|
||||||
WristLocation, WristRotation);
|
|
||||||
|
|
||||||
OutTransform = FTransform{MoveTemp(WristRotation), WristLocation};
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
const FSGWristTrackingSettings& Settings{GetWristTrackingSettings()};
|
||||||
|
|
||||||
|
const bool bIsRight = DeviceHand == Settings.RightHandMotionSource;
|
||||||
|
|
||||||
|
const ESGPositionalTrackingHardware TrackingHardware = GetPositionalTrackingHardware();
|
||||||
|
if (TrackingHardware == ESGPositionalTrackingHardware::Custom)
|
||||||
|
{
|
||||||
|
if (bIsRight)
|
||||||
|
{
|
||||||
|
TrackerLocation += Settings.TrackingHardwareLocationOffsetRightHand;
|
||||||
|
TrackerRotation += Settings.TrackingHardwareRotationOffsetRightHand;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TrackerLocation += Settings.TrackingHardwareLocationOffsetLeftHand;
|
||||||
|
TrackerRotation += Settings.TrackingHardwareRotationOffsetLeftHand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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), MoveTemp(WristLocation)};
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FSGXRTracker::FImpl::GetWristTransform(
|
bool FSGXRTracker::FImpl::GetWristTransform(
|
||||||
|
|||||||
Reference in New Issue
Block a user