void rotateElbowWithHandFoward()
        {
            var     s            = handSettings;
            Vector3 handRightVec = target.rotation * armDirection;

            float elbowTargetAngleForward = VectorHelpers.getAngleBetween(lowerArmRotation * armDirection, handRightVec,
                                                                          lowerArmRotation * Vector3.up, lowerArmRotation * Vector3.forward);

            float deltaElbowForward = (elbowTargetAngleForward + (left ? -s.handDeltaForwardOffset : s.handDeltaForwardOffset)) / 180f;

            if (Mathf.Abs(deltaElbowForward) < s.handDeltaForwardDeadzone)
            {
                deltaElbowForward = 0f;
            }
            else
            {
                deltaElbowForward = (deltaElbowForward - Mathf.Sign(deltaElbowForward) * s.handDeltaForwardDeadzone) / (1f - s.handDeltaForwardDeadzone);
            }

            deltaElbowForward             = Mathf.Sign(deltaElbowForward) * Mathf.Pow(Mathf.Abs(deltaElbowForward), s.handDeltaForwardPow) * 180f;
            interpolatedDeltaElbowForward = Mathf.LerpAngle(interpolatedDeltaElbowForward, deltaElbowForward, Time.deltaTime / s.rotateElbowWithHandDelay);

            float signedInterpolated = interpolatedDeltaElbowForward.toSignedEulerAngle();

            rotateElbow(signedInterpolated * s.handDeltaForwardFactor);
        }
        public void rotateHand()
        {
            if (handSettings.useWristRotation)
            {
                Vector3 handUpVec    = target.rotation * Vector3.up;
                float   forwardAngle = VectorHelpers.getAngleBetween(lowerArmRotation * Vector3.right, target.rotation * Vector3.right,
                                                                     lowerArmRotation * Vector3.up, lowerArmRotation * Vector3.forward);

                // todo reduce influence if hand local forward rotation is high (hand tilted inside)
                Quaternion handForwardRotation = Quaternion.AngleAxis(-forwardAngle, lowerArmRotation * Vector3.forward);
                handUpVec = handForwardRotation * handUpVec;

                float elbowTargetAngle = VectorHelpers.getAngleBetween(lowerArmRotation * Vector3.up, handUpVec,
                                                                       lowerArmRotation * Vector3.forward, lowerArmRotation * armDirection);

                elbowTargetAngle = Mathf.Clamp(elbowTargetAngle, -90f, 90f);
                if (arm.wrist1 != null)
                {
                    setWrist1Rotation(Quaternion.AngleAxis(elbowTargetAngle * .3f, lowerArmRotation * armDirection) * lowerArmRotation);
                }
                if (arm.wrist2 != null)
                {
                    setWrist2Rotation(Quaternion.AngleAxis(elbowTargetAngle * .8f, lowerArmRotation * armDirection) * lowerArmRotation);
                }
            }
            setHandRotation(target.rotation);
        }
Beispiel #3
0
        protected virtual void rotateShoulderRight()
        {
            float heightDiff         = vrTrackingReferences.hmd.transform.position.y;
            float relativeHeightDiff = heightDiff / PoseManager.Instance.playerHeightHmd;

            float headRightRotation = VectorHelpers.getAngleBetween(shoulder.transform.forward,
                                                                    avatarTrackingReferences.hmd.transform.forward,
                                                                    Vector3.up, shoulder.transform.right) + rightRotationHeadRotationOffset;
            float heightFactor = Mathf.Clamp(relativeHeightDiff - rightRotationStartHeight, 0f, 1f);

            shoulderRightRotation  = heightFactor * rightRotationHeightFactor;
            shoulderRightRotation += Mathf.Clamp(headRightRotation * rightRotationHeadRotationFactor * heightFactor, 0f, 50f);

            Quaternion deltaRot = Quaternion.AngleAxis(shoulderRightRotation, shoulder.transform.right);


            shoulder.transform.rotation = deltaRot * shoulder.transform.rotation;
            positionShoulderRelative();
        }
        void rotateElbowWithHandRight()
        {
            var     s            = handSettings;
            Vector3 handUpVec    = target.rotation * Vector3.up;
            float   forwardAngle = VectorHelpers.getAngleBetween(lowerArmRotation * Vector3.right, target.rotation * Vector3.right,
                                                                 lowerArmRotation * Vector3.up, lowerArmRotation * Vector3.forward);

            // todo reduce influence if hand local forward rotation is high (hand tilted inside)
            Quaternion handForwardRotation = Quaternion.AngleAxis(-forwardAngle, lowerArmRotation * Vector3.forward);

            handUpVec = handForwardRotation * handUpVec;

            float elbowTargetAngle = VectorHelpers.getAngleBetween(lowerArmRotation * Vector3.up, handUpVec,
                                                                   lowerArmRotation * Vector3.forward, lowerArmRotation * armDirection);

            float deltaElbow = (elbowTargetAngle + (left ? -s.handDeltaOffset : s.handDeltaOffset)) / 180f;

            deltaElbow             = Mathf.Sign(deltaElbow) * Mathf.Pow(Mathf.Abs(deltaElbow), s.handDeltaPow) * 180f * s.handDeltaFactor;
            interpolatedDeltaElbow =
                Mathf.LerpAngle(interpolatedDeltaElbow, deltaElbow, Time.deltaTime / s.rotateElbowWithHandDelay);
            rotateElbow(interpolatedDeltaElbow);
        }