/// <summary>
            /// Checks if two objects are equal.
            /// </summary>
            /// <param name="obj">The object to check against.</param>
            /// <returns>Returns true if they are equal, otherwise false.</returns>
            public override bool Equals(object obj)
            {
                BodyPair other = (BodyPair)obj;

                return(other.body1.Equals(body1) && other.body2.Equals(body2) ||
                       other.body1.Equals(body2) && other.body2.Equals(body1));
            }
        private void SortAxis(List <SweepPoint> axis)
        {
            for (int j = 1; j < axis.Count; j++)
            {
                SweepPoint keyelement = axis[j];
                float      key        = keyelement.GetValue();

                int i = j - 1;

                while (i >= 0 && axis[i].GetValue() > key)
                {
                    SweepPoint swapper = axis[i];

                    if (keyelement.Begin && !swapper.Begin)
                    {
                        lock (t2bM)
                        {
                            int count = t2bM.IncrementCounter(keyelement.Body.BroadphaseTag,
                                                              swapper.Body.BroadphaseTag);

                            if (count == 3)
                            {
                                BodyPair pair = new BodyPair(keyelement.Body, swapper.Body);
                                fullOverlaps.Add(pair);
                            }
                        }
                    }

                    if (!keyelement.Begin && swapper.Begin)
                    {
                        lock (t2bM)
                        {
                            int count = t2bM.DecrementCounter(keyelement.Body.BroadphaseTag,
                                                              swapper.Body.BroadphaseTag);

                            if (count == 2)
                            {
                                BodyPair pair = new BodyPair(keyelement.Body, swapper.Body);
                                fullOverlaps.Remove(pair);
                            }
                        }
                    }

                    axis[i + 1] = swapper;
                    i           = i - 1;
                }
                axis[i + 1] = keyelement;
            }
        }
示例#3
0
        public void Add(ContactConstraint contact)
        {
            var cachedContact = _alloc.Allocate();

            cachedContact.Count = contact.Count;
            for (int j = 0; j < contact.Count; j++)
            {
                cachedContact.Points[j] = new CachedContactPoint(contact.Points[j]);
            }
            var pair = new BodyPair(contact.BodyA, contact.BodyB);

            if (!_pairs.ContainsKey(pair))
            {
                _pairs.Add(pair, cachedContact);
            }
            _allocatedContacts.Add(cachedContact);
        }
示例#4
0
        public CachedContact Get(RigidBody a, RigidBody b)
        {
            var pair = new BodyPair(a, b);

            return(_pairs.ContainsKey(pair) ? _pairs[pair] : null);
        }
        private void SortAxis(List<SweepPoint> axis)
        {
            for (int j = 1; j < axis.Count; j++)
            {
                SweepPoint keyelement = axis[j];
                float key = keyelement.GetValue();

                int i = j - 1;

                while (i >= 0 && axis[i].GetValue() > key)
                {
                    SweepPoint swapper = axis[i];

                    if (keyelement.Begin && !swapper.Begin)
                    {
                        lock (t2bM)
                        {
                            int count = t2bM.IncrementCounter(keyelement.Body.BroadphaseTag,
                                swapper.Body.BroadphaseTag);

                            if (count == 3)
                            {
                                BodyPair pair = new BodyPair(keyelement.Body, swapper.Body);
                                fullOverlaps.Add(pair);
                            }
                        }
                    }

                    if (!keyelement.Begin && swapper.Begin)
                    {
                        lock (t2bM)
                        {
                            int count = t2bM.DecrementCounter(keyelement.Body.BroadphaseTag,
                                swapper.Body.BroadphaseTag);

                            if (count == 2)
                            {
                                BodyPair pair = new BodyPair(keyelement.Body, swapper.Body);
                                fullOverlaps.Remove(pair);
                            }
                        }
                    }

                    axis[i + 1] = swapper;
                    i = i - 1;
                }
                axis[i + 1] = keyelement;
            }
        }