Exemplo n.º 1
0
 private IKLink point(IKLink link, IKTarget target)
 {
     return link;
 }
Exemplo n.º 2
0
 private static void destroyLinks(IKLink[] links)
 {
     if(links.Length > 0) GameObject.Destroy(links[0].transform.gameObject);
 }
Exemplo n.º 3
0
        private static Quaternion constrainCone(Quaternion quat, IKLink link)
        {
            // Debug.Log(link.transform.name);
            if (!link.segRef.Constrain) return quat;
            Quaternion baseQuat = link.segRef.GetBaseRotation();
            float error = 360;
            int iterations = 1;
            while (error > 0.5f && iterations < 10) {
                Vector3 center = baseQuat * Vector3.up;
                Vector3 expected = quat * Vector3.up;

                float angle = Vector3.Angle(center, expected);
               // Debug.LogFormat("{0} {1}", link.segRef.ConeRadius, angle);
                if(angle > link.segRef.ConeRadius) {
                    quat = Quaternion.Slerp(Quaternion.identity, quat, 1 - iterations*0.1f);
                } else {
                    //Debug.Log("DONE");
                    break;
                }

                iterations++;
            }
            return quat;
        }
Exemplo n.º 4
0
        private static IKLink[] createLinks(IKSegment[] segments, Transform effector, out Transform contact)
        {
            IKLink[] links = new IKLink[segments.Length];
            IKLink previous = null;
            for(int i = 0; i < links.Length; i++) {
                links[i] = new IKLink(segments[i]);
                if(previous != null) {
                    //Debug.LogFormat("from {0} to {1}", previous.transform.name, links[i].transform.name);
                    connectTransform(previous.segRef.transform, links[i].segRef.transform, links[i].transform, previous.transform);
                } else {
                    links[i].transform.SetParent(segments[0].transform.parent);
                }
                previous = links[i];
            }

            GameObject go = new GameObject();
            go.name = "Effector";
            go.transform.SetParent(links[links.Length - 1].transform);
            go.transform.position = effector.position;
            go.transform.rotation = effector.rotation;
            go.transform.localScale = effector.localScale;
            contact = go.transform;

            return links;
        }
Exemplo n.º 5
0
        private static Quaternion constrainAxis(IKLink root, Vector3 axis, Vector3 angleAxis, Vector3 toChild, Vector3 dir, float min, float max, out float actualAngle)
        {
            actualAngle = IKMath.AngleOnPlane(dir, toChild, axis);

            float angle = Mathf.Clamp(actualAngle, min, max);
            //Debug.LogFormat("{2}: {0} {1}", actualAngle, angle, root.transform.name);
            return Quaternion.AngleAxis(angle, angleAxis);
        }