Пример #1
0
        /// <summary> Notify listeners of a collision
        /// 
        /// </summary>
        /// <param name="body1">The first body in the collision
        /// </param>
        /// <param name="body2">The second body in the collision
        /// </param>
        /// <param name="point">The point of collision (not always perfect - accepts penetration)
        /// </param>
        /// <param name="normal">The normal of collision
        /// </param>
        /// <param name="depth">The penetration of of the contact
        /// </param>
        private void NotifyCollision(Body body1, Body body2, ROVector2f point, ROVector2f normal, float depth)
        {
            if (listeners.Count == 0)
            {
                return ;
            }

            CollisionEvent newEvent = new CollisionEvent(totalTime, body1, body2, point, normal, depth);

            for (int i = 0; i < listeners.Count; i++)
            {
                ((CollisionListener) listeners[i]).CollisionOccured(newEvent);
            }
        }
Пример #2
0
        /// <summary> Get a list of collisions at the current time for a given body
        /// 
        /// </summary>
        /// <param name="body">The body to check for
        /// </param>
        /// <returns> The list of collision events describing the current contacts
        /// </returns>
        public virtual CollisionEvent[] GetContacts(Body body)
        {
            List<CollisionEvent> collisions = new List<CollisionEvent>();

            for (int i = 0; i < arbiters.size(); i++)
            {
                Arbiter arb = arbiters.Item(i);

                if (arb.Concerns(body))
                {
                    for (int j = 0; j < arb.NumContacts; j++)
                    {
                        Contact contact = arb.GetContact(j);
                        CollisionEvent newEvent = new CollisionEvent(0, arb.Body1, arb.Body2, contact.Position, contact.Normal, contact.Separation);

                        collisions.Add(newEvent);
                    }
                }
            }

            return collisions.ToArray();
        }