void IPairHandlerParent.AddSolverUpdateable(SolverUpdateable addedItem)
 {
     manifoldConstraintGroup.Add(addedItem);
     //If this is the first child solver item to be added, we need to add ourselves to our parent too.
     if (manifoldConstraintGroup.SolverUpdateables.Count == 1)
     {
         if (Parent != null)
         {
             Parent.AddSolverUpdateable(manifoldConstraintGroup);
         }
         else if (NarrowPhase != null)
         {
             NarrowPhase.NotifyUpdateableAdded(manifoldConstraintGroup);
         }
     }
 }
Example #2
0
        ///<summary>
        /// Updates the pair handler.
        ///</summary>
        ///<param name="dt">Timestep duration.</param>
        public override void UpdateCollision(float dt)
        {
            //Cache some properties.
            var a        = CollidableA;
            var b        = CollidableB;
            var triggerA = a.EventTriggerer;
            var triggerB = b.EventTriggerer;

            if (!suppressEvents)
            {
                triggerA.OnPairUpdated(b, this);
                triggerB.OnPairUpdated(a, this);
            }

            ContactManifold.Update(dt);

            if (ContactManifold.contacts.count > 0)
            {
                if (!suppressEvents)
                {
                    triggerA.OnPairTouching(b, this);
                    triggerB.OnPairTouching(a, this);
                }

                if (previousContactCount == 0)
                {
                    //New collision.

                    //Add a solver item.
                    if (Parent != null)
                    {
                        Parent.AddSolverUpdateable(ContactConstraint);
                    }
                    else if (NarrowPhase != null)
                    {
                        NarrowPhase.NotifyUpdateableAdded(ContactConstraint);
                    }

                    //And notify the pair members.
                    if (!suppressEvents)
                    {
                        triggerA.OnInitialCollisionDetected(b, this);
                        triggerB.OnInitialCollisionDetected(a, this);
                    }
                }
            }
            else if (previousContactCount > 0)
            {
                //Just exited collision.

                //Remove the solver item.
                if (Parent != null)
                {
                    Parent.RemoveSolverUpdateable(ContactConstraint);
                }
                else if (NarrowPhase != null)
                {
                    NarrowPhase.NotifyUpdateableRemoved(ContactConstraint);
                }

                if (!suppressEvents)
                {
                    triggerA.OnCollisionEnded(b, this);
                    triggerB.OnCollisionEnded(a, this);
                }
            }
            previousContactCount = ContactManifold.contacts.count;
        }