Example #1
0
        public static Quaternion CalculateNeckRotation(Quaternion hipRotation, Quaternion headRotation)
        {
            Vector3    headAnglesCharacterSpace = (Quaternion.Inverse(hipRotation) * headRotation).eulerAngles;
            float      neckYRotation            = UnityAngles.Normalize(headAnglesCharacterSpace.y) * 0.6F;
            Quaternion neckRotation             = hipRotation * Quaternion.Euler(headAnglesCharacterSpace.x, neckYRotation, headAnglesCharacterSpace.z);

            return(neckRotation);
        }
Example #2
0
        public static Quaternion CalculateChestRotation(Quaternion chestRotation, Quaternion hipRotation, Quaternion headRotation)
        {
            Vector3    chestAngles = chestRotation.eulerAngles;
            Vector3    headAnglesCharacterSpace = (Quaternion.Inverse(hipRotation) * headRotation).eulerAngles;
            float      chestYRotation           = UnityAngles.Normalize(headAnglesCharacterSpace.y) * 0.3F;
            Quaternion newChestRotation         = hipRotation * Quaternion.Euler(chestAngles.x, chestYRotation, chestAngles.z);

            return(newChestRotation);
        }
Example #3
0
            protected float CalculateFingerCurl()
            {
                Quaternion rotation = proximal.target.transform.localRotation * Quaternion.Inverse(proximal.target.baseRotation);
                float      angle    = fingers.handTarget.isLeft ? rotation.eulerAngles.z : -rotation.eulerAngles.z;

                angle = UnityAngles.Normalize(angle);
                _curl = angle / 70;

                _curl = Mathf.Clamp(_curl, -0.1F, 1);
                return(_curl);
            }
Example #4
0
        private void LookAtTarget(Vector3 targetPosition)
        {
            Vector3    targetDirection = targetPosition - eyeTarget.bone.transform.position;
            Quaternion headRotation    = eyeTarget.headTarget.head.bone.transform.rotation * eyeTarget.headTarget.head.bone.toTargetRotation;

            Vector3 headForward = headRotation * Vector3.forward;
            Vector3 headUp      = headRotation * Vector3.up;

            Vector3 targetEyeAngles = Quaternion.FromToRotation(headForward, targetDirection).eulerAngles;
            Vector3 eyeAngles       = UnityAngles.Clamp(targetEyeAngles, eyeTarget.bone.minAngles, eyeTarget.bone.maxAngles);

            targetDirection = Quaternion.Euler(eyeAngles) * headForward;

            eyeTarget.target.transform.rotation = Quaternion.LookRotation(targetDirection, headUp);
        }
Example #5
0
        protected Vector3 CalculateTorque()
        {
            Quaternion sollRotation = handTarget.hand.target.transform.rotation * handTarget.hand.target.toBoneRotation;
            Quaternion istRotation  = handTarget.hand.bone.transform.rotation;
            Quaternion dRot         = sollRotation * Quaternion.Inverse(istRotation);

            float   angle;
            Vector3 axis;

            dRot.ToAngleAxis(out angle, out axis);
            angle = UnityAngles.Normalize(angle);

            Vector3 angleDifference = axis.normalized * (angle * Mathf.Deg2Rad);
            Vector3 torque          = angleDifference * handTarget.strength * 0.1F;

            return(torque);
        }
Example #6
0
 public float GetSwing()
 {
     if (fingers == null || proximal.target.transform == null)
     {
         _swing = 0;
     }
     else if (this == fingers.thumb)
     {
         float angle = proximal.target.transform.localEulerAngles.z;
         _swing = UnityAngles.Normalize(angle) / 90;
     }
     else
     {
         float angle = proximal.target.transform.localEulerAngles.y;
         _swing = UnityAngles.Normalize(angle) / 90;
     }
     return(_swing);
 }
        public static Quaternion CalculateHipsRotation(Vector3 hipsPosition, Quaternion hipsRotation, Quaternion leftHandRotation, Quaternion rightHandRotation, Transform leftFoot, Transform rightFoot, Quaternion neckRotation, Vector3 neckPosition)
        {
            float angleX = hipsRotation.eulerAngles.x;
            float angleY = hipsRotation.eulerAngles.y;
            float angleZ = hipsRotation.eulerAngles.z;

            float dOrientation = 0;

            Vector3 leftHandForward  = leftHandRotation * Vector3.left;
            Vector3 rightHandForward = rightHandRotation * Vector3.right;
            Vector3 hipsForward      = hipsRotation * Vector3.forward;

            Vector2 leftHandForward2  = new Vector2(leftHandForward.x, leftHandForward.z);
            Vector2 rightHandForward2 = new Vector2(rightHandForward.x, rightHandForward.z);
            Vector2 hipsRotation2     = new Vector2(hipsForward.x, hipsForward.z);

            // Check for hands not pointing up/down too much
            float dOrientationL = leftHandForward2.sqrMagnitude > 0.1F ? UnityAngles.SignedAngle(hipsRotation2, leftHandForward2) : 0;
            float dOrientationR = rightHandForward2.sqrMagnitude > 0.1F ? UnityAngles.SignedAngle(hipsRotation2, rightHandForward2) : 0;

            if (Mathf.Sign(dOrientationL) == Mathf.Sign(dOrientationR))
            {
                if (Mathf.Abs(dOrientationL) < Mathf.Abs(dOrientationR))
                {
                    dOrientation = dOrientationL;
                }
                else
                {
                    dOrientation = dOrientationR;
                }
            }

            float neckOrientation = UnityAngles.Difference(neckRotation.eulerAngles.y, angleY + dOrientation);

            if (neckOrientation < 90 && neckOrientation > -90)   // head cannot turn more than 90 degrees
            {
                angleY += dOrientation;
            }

            Quaternion newHipsRotation = Quaternion.Euler(angleX, angleY, angleZ);

            return(newHipsRotation);
        }
Example #8
0
            protected float CalculateThumbCurl()
            {
                Quaternion rotation = Quaternion.Inverse(proximal.target.transform.rotation) * distal.target.transform.rotation;
                float      angle    = fingers.handTarget.isLeft ? rotation.eulerAngles.z : -rotation.eulerAngles.z;

                angle = UnityAngles.Normalize(angle);
                angle = angle - 15;
                if (angle < 0)
                {
                    _curl = angle / 80;
                }
                else
                {
                    _curl = angle / 80;
                }

                _curl = Mathf.Clamp(_curl, -0.5F, 1);

                return(_curl);
            }
Example #9
0
 public static float LimitKneeAngle(FootTarget.TargetedLowerLegBone lowerLeg, float angle)
 {
     return(UnityAngles.Clamp(angle, 0, lowerLeg.bone.maxAngle));
 }
Example #10
0
 protected Vector3 LimitAngles(HumanoidTarget.TargetedBone bone, Vector3 angles)
 {
     angles = UnityAngles.Clamp(angles, bone.bone.minAngles, bone.bone.maxAngles);
     return(angles);
 }