CalculateDirection() private static method

private static CalculateDirection ( Vector3 point, int &direction, float &distance ) : void
point UnityEngine.Vector3
direction int
distance float
return void
Example #1
0
        private void AddHeadCollider()
        {
            if (this.head.GetComponent <Collider>())
            {
                UnityEngine.Object.Destroy(this.head.GetComponent <Collider>());
            }
            float num = Vector3.Distance(this.leftArm.transform.position, this.rightArm.transform.position);

            num /= 4f;
            SphereCollider sphereCollider = this.head.gameObject.AddComponent <SphereCollider>();

            sphereCollider.radius = num;
            Vector3 zero = Vector3.zero;
            int     index;
            float   num2;

            RagdollBuilder.CalculateDirection(this.head.InverseTransformPoint(this.pelvis.position), out index, out num2);
            if (num2 > 0f)
            {
                zero[index] = -num;
            }
            else
            {
                zero[index] = num;
            }
            sphereCollider.center = zero;
        }
        private static Vector3 CalculateDirectionAxis(Vector3 point)
        {
            int   direction = 0;
            float distance;

            RagdollBuilder.CalculateDirection(point, out direction, out distance);
            Vector3 zero = Vector3.zero;

            zero[direction] = (double)distance <= 0.0 ? -1f : 1f;
            return(zero);
        }
Example #3
0
 private void BuildCapsules()
 {
     foreach (RagdollBuilder.BoneInfo boneInfo in this.bones)
     {
         if (boneInfo.colliderType == typeof(CapsuleCollider))
         {
             int   num;
             float num2;
             if (boneInfo.children.Count == 1)
             {
                 RagdollBuilder.BoneInfo boneInfo2 = (RagdollBuilder.BoneInfo)boneInfo.children[0];
                 Vector3 position = boneInfo2.anchor.position;
                 RagdollBuilder.CalculateDirection(boneInfo.anchor.InverseTransformPoint(position), out num, out num2);
             }
             else
             {
                 Vector3 position2 = boneInfo.anchor.position - boneInfo.parent.anchor.position + boneInfo.anchor.position;
                 RagdollBuilder.CalculateDirection(boneInfo.anchor.InverseTransformPoint(position2), out num, out num2);
                 if (boneInfo.anchor.GetComponentsInChildren(typeof(Transform)).Length > 1)
                 {
                     Bounds      bounds = default(Bounds);
                     Component[] componentsInChildren = boneInfo.anchor.GetComponentsInChildren(typeof(Transform));
                     for (int i = 0; i < componentsInChildren.Length; i++)
                     {
                         Transform transform = (Transform)componentsInChildren[i];
                         bounds.Encapsulate(boneInfo.anchor.InverseTransformPoint(transform.position));
                     }
                     if (num2 > 0f)
                     {
                         num2 = bounds.max[num];
                     }
                     else
                     {
                         num2 = bounds.min[num];
                     }
                 }
             }
             CapsuleCollider capsuleCollider = boneInfo.anchor.gameObject.AddComponent <CapsuleCollider>();
             capsuleCollider.direction = num;
             Vector3 zero = Vector3.zero;
             zero[num] = num2 * 0.5f;
             capsuleCollider.center = zero;
             capsuleCollider.height = Mathf.Abs(num2);
             capsuleCollider.radius = Mathf.Abs(num2 * boneInfo.radiusScale);
         }
     }
 }
Example #4
0
        private static Vector3 CalculateDirectionAxis(Vector3 point)
        {
            int   index = 0;
            float num;

            RagdollBuilder.CalculateDirection(point, out index, out num);
            Vector3 zero = Vector3.zero;

            if (num > 0f)
            {
                zero[index] = 1f;
            }
            else
            {
                zero[index] = -1f;
            }
            return(zero);
        }
        private void AddHeadCollider()
        {
            if ((bool)((UnityEngine.Object) this.head.GetComponent <Collider>()))
            {
                UnityEngine.Object.Destroy((UnityEngine.Object) this.head.GetComponent <Collider>());
            }
            float          num            = Vector3.Distance(this.leftArm.transform.position, this.rightArm.transform.position) / 4f;
            SphereCollider sphereCollider = this.head.gameObject.AddComponent <SphereCollider>();

            sphereCollider.radius = num;
            Vector3 zero = Vector3.zero;
            int     direction;
            float   distance;

            RagdollBuilder.CalculateDirection(this.head.InverseTransformPoint(this.pelvis.position), out direction, out distance);
            zero[direction]       = (double)distance <= 0.0 ? num : -num;
            sphereCollider.center = zero;
        }
 private void BuildCapsules()
 {
     foreach (RagdollBuilder.BoneInfo bone in this.bones)
     {
         if (bone.colliderType == typeof(CapsuleCollider))
         {
             int   direction;
             float distance;
             if (bone.children.Count == 1)
             {
                 Vector3 position = ((RagdollBuilder.BoneInfo)bone.children[0]).anchor.position;
                 RagdollBuilder.CalculateDirection(bone.anchor.InverseTransformPoint(position), out direction, out distance);
             }
             else
             {
                 Vector3 position = bone.anchor.position - bone.parent.anchor.position + bone.anchor.position;
                 RagdollBuilder.CalculateDirection(bone.anchor.InverseTransformPoint(position), out direction, out distance);
                 if (bone.anchor.GetComponentsInChildren(typeof(Transform)).Length > 1)
                 {
                     Bounds bounds = new Bounds();
                     foreach (Transform componentsInChild in bone.anchor.GetComponentsInChildren(typeof(Transform)))
                     {
                         bounds.Encapsulate(bone.anchor.InverseTransformPoint(componentsInChild.position));
                     }
                     distance = (double)distance <= 0.0 ? bounds.min[direction] : bounds.max[direction];
                 }
             }
             CapsuleCollider capsuleCollider = bone.anchor.gameObject.AddComponent <CapsuleCollider>();
             capsuleCollider.direction = direction;
             Vector3 zero = Vector3.zero;
             zero[direction]        = distance * 0.5f;
             capsuleCollider.center = zero;
             capsuleCollider.height = Mathf.Abs(distance);
             capsuleCollider.radius = Mathf.Abs(distance * bone.radiusScale);
         }
     }
 }