/// <summary> /// Interpolates between two HandPoses, if they have the same handeness and bones. /// </summary> /// <param name="from">Base HandPose to interpolate from.</param> /// <param name="to">Target HandPose to interpolate to.</param> /// <param name="t">Interpolation factor, 0 for the base, 1 for the target.</param> /// <returns>A new HandPose positioned/rotated between the base and target, null if the hands cannot be interpolated.</returns> public static HandPose?Lerp(HandPose from, HandPose to, float t) { if (from.handeness != to.handeness) { Debug.LogError("Hand poses must have same handenness for lerping"); return(null); } if (from.Bones.Count != to.Bones.Count) { Debug.LogError("Hand poses must have same Bones for lerping"); return(null); } HandPose result = new HandPose(); result.relativeGrip = PoseUtils.Lerp(from.relativeGrip, to.relativeGrip, t); result.handeness = from.handeness; result.Bones.Clear(); for (int i = 0; i < from.Bones.Count; i++) { BoneRotation?bone = BoneRotation.Lerp(from.Bones[i], to.Bones[i], t); if (bone.HasValue) { result.Bones.Add(bone.Value); } else { Debug.LogError("Hand poses must have same Bones for lerping"); return(null); } } return(result); }
/// <summary> /// Moves the hand at a given pose towards the given Grip pose using interpolation. /// The target pose is specified in local units from a reference transform. /// </summary> /// <param name="pose">The relative target position for the grip point of the hand</param> /// <param name="weight">Interpolation factor, 0 for not changing the hand, 1 for fully alligning the grip point with the given pose.</param> /// <param name="relativeTo">The reference transform in which the pose is provided. If null, the Hand Anchor coordinates are used</param> public void LerpGripOffset(Pose pose, float weight, Transform relativeTo = null) { Pose gripOffset = this.gripPoint.RelativeOffset(this.transform); Pose basic = TrackedGripPose; Pose target = (relativeTo ?? this.handAnchor).GlobalPose(pose); Pose result = PoseUtils.Lerp(basic, target, weight); result = PoseUtils.Multiply(result, gripOffset); this.transform.SetPose(result); }
/// <summary> /// Moves the hand at a given pose towards the given Grip pose using interpolation. /// The target pose is specified in local units from a reference transform. /// </summary> /// <param name="pose">The relative target position for the grip point of the hand</param> /// <param name="weight">Interpolation factor, 0 for not changing the hand, 1 for fully alligning the grip point with the given pose.</param> /// <param name="relativeTo">The reference transform in which the pose is provided.</param> public void LerpGripOffset(Pose pose, float weight, Transform relativeTo) { Pose fromGrip = this.gripPoint.GetPose(); Pose toGrip = (relativeTo ?? this.transform).GlobalPose(pose); Pose targetGrip = PoseUtils.Lerp(fromGrip, toGrip, weight); Pose inverseGrip = this.gripPoint.RelativeOffset(this.transform); Pose targetPose = PoseUtils.Multiply(targetGrip, inverseGrip); this.transform.SetPose(targetPose); }