/// <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> /// Gets the interpolated value between two rotations of the same bone (same indentifier). /// </summary> /// <param name="from">Base rotation to interpolate from.</param> /// <param name="to">Target rotation to interpolate to.</param> /// <param name="t">Interpolation factor, 0 for base, 1 for target rotation</param> /// <returns>A new BoneRotation between base and target, null if bone is invalid.</returns> public static BoneRotation?Lerp(BoneRotation from, BoneRotation to, float t) { if (from.boneID != to.boneID) { Debug.LogError("Bones must have same id for interpolation"); return(null); } return(new BoneRotation() { boneID = from.boneID, rotation = Quaternion.Lerp(from.rotation, to.rotation, t) }); }