示例#1
0
 public bool Equals(SatResult obj)
 {
     return(A == obj.A &&
            B == obj.B &&
            NormalAxis == obj.NormalAxis &&
            Penetration == obj.Penetration &&
            DeepestPoint == obj.DeepestPoint);
 }
示例#2
0
 public bool Equals(SatResult obj)
 {
     return A == obj.A
         && B == obj.B
         && NormalAxis == obj.NormalAxis
         && Penetration == obj.Penetration
         && DeepestPoint == obj.DeepestPoint;
 }
示例#3
0
        public void FindContacts(SatTester tester, int maxContacts = 8)
        {
            if (!IsActive)
            {
                return;
            }

            // perform SAT collision detection
            SatResult?r = tester.FindIntersection(a, b);

            if (r == null)
            {
                contacts.Clear();
                return;
            }

            SatResult result = r.Value;

            normal           = result.NormalAxis;
            penetrationDepth = result.Penetration;

            // find all vertices in a which are inside b, add them as contacts
            var aVertices = a.GetVertices(result.NormalAxis);

            for (int i = 0; i < aVertices.Length; i++)
            {
                if (newContacts.Count == maxContacts)
                {
                    break;
                }

                if (b.Contains(aVertices[i]))
                {
                    newContacts.Add(new Contact(aVertices[i], a, i));
                }
            }

            // find all vertices in b which are inside a, add them as contacts
            var bVertices = b.GetVertices(-result.NormalAxis);

            for (int i = 0; i < bVertices.Length; i++)
            {
                if (contacts.Count == maxContacts)
                {
                    break;
                }

                if (a.Contains(bVertices[i]))
                {
                    newContacts.Add(new Contact(bVertices[i], b, i));
                }
            }

            // add the deepest point if we found no others
            if (newContacts.Count == 0)
            {
                newContacts.Add(new Contact(result.DeepestPoint, a, 0));
            }

            // merge new contacts with the old ones
            MergeContacts();

            if (!initialised)
            {
                A.collidingWith.Add(B);
                B.collidingWith.Add(A);
                initialised = true;
            }
        }