Exemple #1
0
        internal void HandleCollision(TimeStep step, Body body1, Body body2)
        {
            if (body1.Mass.MassInv == 0 && body2.Mass.MassInv == 0)
            {
                return;
            }
            IShape shape1 = body1.Shape;
            IShape shape2 = body2.Shape;


            if (shape1.CanGetCustomIntersection ||
                shape2.CanGetCustomIntersection ||
                body1.IsBroadPhaseOnly ||
                body2.IsBroadPhaseOnly)
            {
                object customIntersectionInfo;
                if (body1.IsBroadPhaseOnly)
                {
                    body1.OnCollision(step, body2, null);
                }
                else if (shape1.CanGetCustomIntersection &&
                         shape1.TryGetCustomIntersection(body1, body2, out customIntersectionInfo))
                {
                    body1.OnCollision(step, body2, customIntersectionInfo);
                }
                if (body2.IsBroadPhaseOnly)
                {
                    body2.OnCollision(step, body1, null);
                }
                else if (shape2.CanGetCustomIntersection &&
                         shape2.TryGetCustomIntersection(body2, body1, out customIntersectionInfo))
                {
                    body2.OnCollision(step, body1, customIntersectionInfo);
                }
            }
            else
            {
                IContact contact;
                if (solver.TryGetIntersection(step, body1, body2, out contact))
                {
                    if (contact.State == ContactState.New)
                    {
                        body1.OnCollision(step, body2, contact);
                        body2.OnCollision(step, body1, contact);
                    }

                    body1.OnColliding(step, body2, contact);
                    body2.OnColliding(step, body1, contact);
                }
            }
        }
        internal void HandleCollision(TimeStep step, Body body1, Body body2)
        {
            if (body1.Mass.MassInv == 0 && body2.Mass.MassInv == 0)
            {
                return;
            }
            Shape shape1 = body1.Shape;
            Shape shape2 = body2.Shape;


            if (shape1.CanGetCustomIntersection ||
                shape2.CanGetCustomIntersection ||
                shape1.BroadPhaseDetectionOnly ||
                shape2.BroadPhaseDetectionOnly)
            {
                object customIntersectionInfo;
                if (shape1.BroadPhaseDetectionOnly)
                {
                    body1.OnCollision(body2, null);
                }
                else if (shape1.CanGetCustomIntersection &&
                         shape1.TryGetCustomIntersection(body1, body2, out customIntersectionInfo))
                {
                    body1.OnCollision(body2, customIntersectionInfo);
                }
                if (shape2.BroadPhaseDetectionOnly)
                {
                    body2.OnCollision(body1, null);
                }
                else if (shape2.CanGetCustomIntersection &&
                         shape2.TryGetCustomIntersection(body2, body1, out customIntersectionInfo))
                {
                    body2.OnCollision(body1, customIntersectionInfo);
                }
            }
            else
            {
                ReadOnlyCollection <IContactInfo> contacts;
                if (solver.TryGetIntersection(step, body1, body2, out contacts))
                {
                    body1.OnCollision(body2, contacts);
                    body2.OnCollision(body1, contacts);
                }
            }
        }