Ejemplo n.º 1
0
 public void RotateTo(Vector3 position)
 {
     if (this.pivot == null)
     {
         return;
     }
     if (this.pivot != this.lastPivot)
     {
         this.defaultLocalRotation = this.pivot.localRotation;
         this.lastPivot            = this.pivot;
     }
     this.pivot.localRotation = this.defaultLocalRotation;
     if (this.twistWeight > 0f)
     {
         Vector3 fromDirection = base.transform.position - this.pivot.position;
         Vector3 vector        = this.pivot.rotation * this.twistAxis;
         Vector3 vector2       = vector;
         Vector3.OrthoNormalize(ref vector2, ref fromDirection);
         vector2 = vector;
         Vector3 toDirection = position - this.pivot.position;
         Vector3.OrthoNormalize(ref vector2, ref toDirection);
         Quaternion b = QuaTools.FromToAroundAxis(fromDirection, toDirection, vector);
         this.pivot.rotation = Quaternion.Lerp(Quaternion.identity, b, this.twistWeight) * this.pivot.rotation;
     }
     if (this.swingWeight > 0f)
     {
         Quaternion b2 = Quaternion.FromToRotation(base.transform.position - this.pivot.position, position - this.pivot.position);
         this.pivot.rotation = Quaternion.Lerp(Quaternion.identity, b2, this.swingWeight) * this.pivot.rotation;
     }
 }
Ejemplo n.º 2
0
        /*
         * Apply the bend constraint
         * */
        public void Solve()
        {
            weight = Mathf.Clamp(weight, 0f, 1f);

            // Get the direction to node2 ortho-normalized to the chain direction
            Vector3 directionTangent = OrthoToLimb(rotationOffset * OrthoToLimb(GetDir()));
            Vector3 node2Tangent     = OrthoToLimb(node2.solverPosition - node1.solverPosition);

            // Rotation from the current position to the desired position
            Quaternion fromTo = QuaTools.FromToAroundAxis(node2Tangent, directionTangent, (node3.solverPosition - node1.solverPosition).normalized);

            // Repositioning node2
            Vector3 to2 = node2.solverPosition - node1.solverPosition;

            node2.solverPosition = node1.solverPosition + fromTo * to2;
        }
Ejemplo n.º 3
0
        // Rotate this target towards a position
        public void RotateTo(Vector3 position)
        {
            if (pivot == null)
            {
                return;
            }

            if (pivot != lastPivot)
            {
                defaultLocalRotation = pivot.localRotation;
                lastPivot            = pivot;
            }

            // Rotate to the default local rotation
            pivot.localRotation = defaultLocalRotation;

            // Twisting around the twist axis
            if (twistWeight > 0f)
            {
                Vector3 targetTangent = transform.position - pivot.position;
                Vector3 n             = pivot.rotation * twistAxis;
                Vector3 normal        = n;
                Vector3.OrthoNormalize(ref normal, ref targetTangent);

                normal = n;
                Vector3 direction = position - pivot.position;
                Vector3.OrthoNormalize(ref normal, ref direction);

                Quaternion q = QuaTools.FromToAroundAxis(targetTangent, direction, n);
                pivot.rotation = Quaternion.Lerp(Quaternion.identity, q, twistWeight) * pivot.rotation;
            }

            // Swinging freely
            if (swingWeight > 0f)
            {
                Quaternion s = Quaternion.FromToRotation(transform.position - pivot.position, position - pivot.position);
                pivot.rotation = Quaternion.Lerp(Quaternion.identity, s, swingWeight) * pivot.rotation;
            }
        }
Ejemplo n.º 4
0
        /*
         * Apply the bend constraint
         * */
        public void Solve()
        {
            weight = Mathf.Clamp(weight, 0f, 1f);

            direction = direction.normalized;
            Vector3 dir = direction;

            dir = rotationOffset * dir;

            // Maintaining bend
            // Rotating the default bend direction by offset from the initial chain direction
            Quaternion f = Quaternion.FromToRotation(node3.transform.position - node1.transform.position, node3.solverPosition - node1.solverPosition);

            dir = f * (rotationOffset * bendBoneTransform.rotation * defaultLocalDirection);

            // Effector rotation
            if (node3.effectorRotationWeight > 0f)
            {
                // Bend direction according to the effector rotation
                Vector3 effectorDirection = -Vector3.Cross(node3.solverPosition - node1.solverPosition, node3.solverRotation * defaultChildDirection);
                dir = Vector3.Lerp(dir, effectorDirection, node3.effectorRotationWeight);
            }

            dir = Vector3.Lerp(dir, direction, weight);

            // Get the direction to node2 ortho-normalized to the chain direction
            Vector3 directionTangent = OrthoToLimb(dir);
            Vector3 node2Tangent     = OrthoToLimb(node2.solverPosition - node1.solverPosition);

            // Rotation from the current position to the desired position
            Quaternion fromTo = QuaTools.FromToAroundAxis(node2Tangent, directionTangent, (node3.solverPosition - node1.solverPosition).normalized);

            // Repositioning node2
            Vector3 to2 = node2.solverPosition - node1.solverPosition;

            node2.solverPosition = node1.solverPosition + fromTo * to2;
        }
Ejemplo n.º 5
0
        // Rotate this target towards a position
        public void RotateTo(Transform bone)
        {
            if (pivot == null)
            {
                return;
            }

            if (pivot != lastPivot)
            {
                defaultLocalRotation = pivot.localRotation;
                lastPivot            = pivot;
            }

            // Rotate to the default local rotation
            pivot.localRotation = defaultLocalRotation;

            switch (rotationMode)
            {
            case RotationMode.TwoDOF:
                // Twisting around the twist axis
                if (twistWeight > 0f)
                {
                    Vector3 targetTangent = transform.position - pivot.position;
                    Vector3 n             = pivot.rotation * twistAxis;
                    Vector3 normal        = n;
                    Vector3.OrthoNormalize(ref normal, ref targetTangent);

                    normal = n;
                    Vector3 direction = bone.position - pivot.position;
                    Vector3.OrthoNormalize(ref normal, ref direction);

                    Quaternion q = QuaTools.FromToAroundAxis(targetTangent, direction, n);
                    pivot.rotation = Quaternion.Lerp(Quaternion.identity, q, twistWeight) * pivot.rotation;
                }

                // Swinging freely
                if (swingWeight > 0f)
                {
                    Quaternion s = Quaternion.FromToRotation(transform.position - pivot.position, bone.position - pivot.position);
                    pivot.rotation = Quaternion.Lerp(Quaternion.identity, s, swingWeight) * pivot.rotation;
                }
                break;

            case RotationMode.ThreeDOF:
                // Free rotation around all axes
                if (threeDOFWeight <= 0f)
                {
                    break;
                }
                Quaternion fromTo = QuaTools.FromToRotation(transform.rotation, bone.rotation);
                if (threeDOFWeight >= 1f)
                {
                    pivot.rotation = fromTo * pivot.rotation;
                }
                else
                {
                    pivot.rotation = Quaternion.Slerp(Quaternion.identity, fromTo, threeDOFWeight) * pivot.rotation;
                }
                break;
            }
        }