public void InterpolateOffsets(SimulatedHandPose poseA, SimulatedHandPose poseB, float value)
 {
     for (int i = 0; i < jointCount; i++)
     {
         jointOffsets[i] = Vector3.Lerp(poseA.jointOffsets[i], poseB.jointOffsets[i], value);
     }
 }
        public void AnimateGesture(SimulatedHandPose.GestureId newGesture, float gestureAnimDelta)
        {
            if (!IsSimulated)
            {
                return;
            }

            if (newGesture != SimulatedHandPose.GestureId.None && newGesture != gesture)
            {
                gesture            = newGesture;
                lastGestureAnim    = 0.0f;
                currentGestureAnim = Mathf.Clamp01(gestureAnimDelta);
            }
            else
            {
                lastGestureAnim    = currentGestureAnim;
                currentGestureAnim = Mathf.Clamp01(currentGestureAnim + gestureAnimDelta);
            }

            SimulatedHandPose gesturePose = SimulatedHandPose.GetGesturePose(gesture);

            if (gesturePose != null)
            {
                pose.TransitionTo(gesturePose, lastGestureAnim, currentGestureAnim);
            }

            // Pinch is a special gesture that triggers the Select and TriggerPress input actions
            IsPinching = (gesture == SimulatedHandPose.GestureId.Pinch && currentGestureAnim > 0.9f);
        }
        public void ResetGesture()
        {
            gestureBlending = 1.0f;

            SimulatedHandPose gesturePose = SimulatedHandPose.GetGesturePose(gesture);

            if (gesturePose != null)
            {
                pose.Copy(gesturePose);
            }
        }
        internal void FillCurrentFrame(Vector3[] jointsOut)
        {
            SimulatedHandPose gesturePose = SimulatedHandPose.GetGesturePose(gesture);

            if (gesturePose != null)
            {
                pose.TransitionTo(gesturePose, poseBlending, gestureBlending);
            }
            poseBlending = gestureBlending;

            Quaternion rotation = Quaternion.Euler(HandRotateEulerAngles);
            Vector3    position = CameraCache.Main.ScreenToWorldPoint(ScreenPosition + JitterOffset);

            pose.ComputeJointPositions(handedness, rotation, position, jointsOut);
        }
        private void RecordPose(Handedness handedness)
        {
            Vector3[] jointPositions = new Vector3[jointCount];

            for (int i = 0; i < jointCount; ++i)
            {
                GetJointPosition(jointPositions, (TrackedHandJoint)i, handedness);
            }

            SimulatedHandPose pose = new SimulatedHandPose();

            pose.ParseFromJointPositions(jointPositions, handedness, Quaternion.identity, offset);

            Debug.Log(pose.GenerateInitializerCode());
        }
        public void TransitionTo(SimulatedHandPose other, float lastAnim, float currentAnim)
        {
            if (currentAnim <= lastAnim)
            {
                return;
            }

            float range      = Mathf.Clamp01(1.0f - lastAnim);
            float lerpFactor = range > 0.0f ? (currentAnim - lastAnim) / range : 1.0f;

            for (int i = 0; i < jointCount; i++)
            {
                jointOffsets[i] = Vector3.Lerp(jointOffsets[i], other.jointOffsets[i], lerpFactor);
            }
        }
        public void Reset(float defaultHandDistance, SimulatedHandPose.GestureId defaultGesture)
        {
            // Start at current mouse position
            Vector3 mousePos = UnityEngine.Input.mousePosition;

            screenPosition = new Vector3(mousePos.x, mousePos.y, defaultHandDistance);

            gesture            = defaultGesture;
            lastGestureAnim    = 1.0f;
            currentGestureAnim = 1.0f;

            SimulatedHandPose gesturePose = SimulatedHandPose.GetGesturePose(gesture);

            if (gesturePose != null)
            {
                pose.Copy(gesturePose);
            }

            handRotateEulerAngles = Vector3.zero;
            jitterOffset          = Vector3.zero;
        }
 public void Copy(SimulatedHandPose other)
 {
     Array.Copy(other.jointOffsets, jointOffsets, jointCount);
 }