// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Utilities;
namespace Microsoft.MixedReality.Toolkit.Input
{
public static class HandJointUtils
{
///
/// Tries to get the pose of the requested joint for the first controller with the specified handedness.
///
/// The requested joint
/// The specific hand of interest. This should be either Handedness.Left or Handedness.Right
/// The output pose data
public static bool TryGetJointPose(TrackedHandJoint joint, Handedness handedness, out MixedRealityPose pose)
{
return TryGetJointPose(joint, handedness, out pose);
}
///
/// Try to find the first matching hand controller of the given type and return the pose of the requested joint for that hand.
///
public static bool TryGetJointPose(TrackedHandJoint joint, Handedness handedness, out MixedRealityPose pose) where T : class, IMixedRealityHand
{
T hand = FindHand(handedness);
if (hand != null)
{
return hand.TryGetJoint(joint, out pose);
}
pose = MixedRealityPose.ZeroIdentity;
return false;
}
///
/// Find the first detected hand controller with matching handedness.
///
///
/// The given handedness should be either Handedness.Left or Handedness.Right.
///
public static IMixedRealityHand FindHand(Handedness handedness)
{
return FindHand(handedness);
}
///
/// Find the first detected hand controller of the given type with matching handedness.
///
public static T FindHand(Handedness handedness) where T : class, IMixedRealityHand
{
System.Collections.Generic.HashSet controllers = CoreServices.InputSystem?.DetectedControllers;
if (controllers == null)
{
return null;
}
foreach (IMixedRealityController detectedController in controllers)
{
if (detectedController is T hand)
{
if (detectedController.ControllerHandedness.IsMatch(handedness))
{
return hand;
}
}
}
return null;
}
}
}