示例#1
0
        public override void CheckCollisionBody(Body other)
        {
            //if (!active || !other.active) { return; }
            //if (exclusions.Contains(other)) return;
            if (invmass == 0 && other.invmass == 0)
                return;

            Manifold m = new Manifold(this, other);
            m.Solve();

            if (m.contact_count > 0)
            {
                if (DoExclusionCheck(other)) return;
                if (HandlersEnabled)
                {
                    //todo:add to handler list
                    if (OnCollisionStay != null)
                    {
                        OnCollisionStay(parent, other.parent);
                    }
                    bool parentEnter = OnCollisionEnter != null;
                    if (parentEnter || OnCollisionExit != null || OnCollisionFirstEnter != null || OnCollisionAllExit != null)
                    {
                        HashSet<Collider> lastframe = previousCollision;
                        HashSet<Collider> thisframe = currentCollision;
                        thisframe.Add(other);
                        if (!lastframe.Contains(other) && parentEnter)
                        {
                            OnCollisionEnter(parent, other.parent);
                        }
                    }
                }
                if (other.HandlersEnabled)
                {
                    if (other.OnCollisionStay != null)
                    {
                        other.OnCollisionStay(other.parent, parent);
                    }
                    bool otherEnter = other.OnCollisionEnter != null;
                    if (otherEnter || other.OnCollisionExit != null || other.OnCollisionFirstEnter != null || other.OnCollisionAllExit != null)
                    {
                        //HashSet<Node> lastframe = other.collision.currentIsCol1 ? other.collision.collisions1 : other.collision.collisions2;
                        //HashSet<Node> thisframe = !other.collision.currentIsCol1 ? other.collision.collisions1 : other.collision.collisions2;
                        HashSet<Collider> lastframe = other.previousCollision;
                        HashSet<Collider> thisframe = other.currentCollision;
                        thisframe.Add(this);
                        if (!lastframe.Contains(this) && otherEnter)
                        {
                            other.OnCollisionEnter(other.parent, parent);
                        }
                    }
                }
                if (DoExclusionCheckResolution(other)) return;
                if (isSolid && other.isSolid)
                    room.collisionManager.AddManifold(m);
            }
        }
 //only for links (no handlers)
 public override void AffectOther(Node other)
 {
     if (!active) return;
     Manifold m = new Manifold(parent.body, other.body);
     m.Solve();
     if (m.contact_count > 0)
     {
         room.collisionManager.AddManifold(m);
     }
 }