protected void UpdateHandRay(ManagedHandSkeleton hand) { //shoulder: float shoulderDistance = shoulderWidth * .5f; //swap for the left shoulder: if (ControllerHandedness == Handedness.Left) { shoulderDistance *= -1; } Transform camera = CameraCache.Main.transform; //source locations: Vector3 flatForward = Vector3.ProjectOnPlane(camera.forward, Vector3.up); Vector3 shoulder = TransformUtilities.WorldPosition(camera.position, Quaternion.LookRotation(flatForward), new Vector2(shoulderDistance, Mathf.Abs(shoulderDistanceBelowHead) * -1)); Vector3 pointerOrigin = Vector3.Lerp(hand.Thumb.Knuckle.positionFiltered, hand.Position, .5f); //direction: Quaternion orientation = Quaternion.LookRotation(Vector3.Normalize(pointerOrigin - shoulder), hand.Rotation * Vector3.up); currentPointerPose.Position = pointerOrigin; currentPointerPose.Rotation = orientation; }
// Magic Leap conversion code inspired by the work of Tarukosu // https://github.com/HoloLabInc/MRTKExtensionForMagicLeap/blob/master/Assets/MixedRealityToolkit.ThirdParty/MagicLeapInput/Scripts/MagicLeapHand.cs // Combined with usage of Magic Leap Toolkit protected void UpdateHandData(ManagedHandSkeleton hand) { // Update joint positions var pinky = hand.Pinky; ConvertMagicLeapKeyPoint(pinky.Tip, TrackedHandJoint.PinkyTip); ConvertMagicLeapKeyPoint(pinky.Knuckle, TrackedHandJoint.PinkyKnuckle); var ring = hand.Ring; ConvertMagicLeapKeyPoint(ring.Tip, TrackedHandJoint.RingTip); ConvertMagicLeapKeyPoint(ring.Knuckle, TrackedHandJoint.RingKnuckle); var middle = hand.Middle; ConvertMagicLeapKeyPoint(middle.Tip, TrackedHandJoint.MiddleTip); ConvertMagicLeapKeyPoint(middle.Joint, TrackedHandJoint.MiddleMiddleJoint); ConvertMagicLeapKeyPoint(middle.Knuckle, TrackedHandJoint.MiddleKnuckle); var index = hand.Index; ConvertMagicLeapKeyPoint(index.Tip, TrackedHandJoint.IndexTip); ConvertMagicLeapKeyPoint(index.Joint, TrackedHandJoint.IndexMiddleJoint); ConvertMagicLeapKeyPoint(index.Knuckle, TrackedHandJoint.IndexKnuckle); var thumb = hand.Thumb; ConvertMagicLeapKeyPoint(thumb.Tip, TrackedHandJoint.ThumbTip); ConvertMagicLeapKeyPoint(thumb.Joint, TrackedHandJoint.ThumbDistalJoint); ConvertMagicLeapKeyPoint(thumb.Knuckle, TrackedHandJoint.ThumbProximalJoint); // Wrist and palm reference hand skeleton rotation directly UpdateJointPose(TrackedHandJoint.Palm, hand.HandCenter.GetPosition(FilterType.Filtered), hand.Rotation); UpdateJointPose(TrackedHandJoint.Wrist, hand.WristCenter.GetPosition(FilterType.Filtered), hand.Rotation); CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses); }