Exemple #1
0
        /// <summary> Get the list of bodies that this body is connected to. Only works if 
        /// resting body detection is turned on
        /// 
        /// </summary>
        /// <param name="stopAtStatic">True if we should stop traversing and looking for elements one you find a static one
        /// </param>
        /// <returns> The list of bodies this body Touches
        /// </returns>
        public virtual BodyList GetConnected(bool stopAtStatic)
        {
            BodyList connected = new BodyList();
            GetConnected(connected, new List<Body>(), stopAtStatic);

            return connected;
        }
Exemple #2
0
        /// <summary> Get the bodies connected to this one
        /// 
        /// </summary>
        /// <param name="stopAtStatic">True if we should stop traversing and looking for elements one you find a static one
        /// </param>
        /// <param name="list">The list we're building up
        /// </param>
        /// <param name="path">The list of elements we passed to get here
        /// </param>
        private void GetConnected(BodyList list, IList<Body> path, bool stopAtStatic)
        {
            path.Add(this);
            for (int i = 0; i < touching.Size(); i++)
            {
                Body body = touching.Item(i);
                if (path.Contains(body))
                {
                    continue;
                }
                if (body.Static && stopAtStatic)
                {
                    continue;
                }

                list.Add(body);
                body.GetConnected(list, path, stopAtStatic);
            }
        }
Exemple #3
0
        /// <summary> Get a list of bodies containing all of the bodies in this
        /// list except those specified
        /// 
        /// </summary>
        /// <param name="others">The bodies that should be removed from the contents
        /// </param>
        /// <returns> The list of bodies excluding those specified
        /// </returns>
        public virtual BodyList GetContentsExcluding(BodyList others)
        {
            BodyList list = new BodyList(this);
            //SupportClass.ICollectionSupport.RemoveAll(list.elements, others.elements);

            foreach (Body b in others.elements)
            {
                list.Remove(b);
            }
            return list;
        }
        /// <seealso cref="Silver.Weight.Raw.CollisionContext.Resolve(Silver.Weight.Raw.BodyList, float)">
        /// </seealso>
        public virtual void Resolve(BodyList bodyList, float dt)
        {
            for (int i = 0; i < bodyList.Size(); ++i)
            {
                Body bi = bodyList.Item(i);

                for (int j = i + 1; j < bodyList.Size(); ++j)
                {
                    Body bj = bodyList.Item(j);
                    if ((bitmask & bi.Bitmask & bj.Bitmask) == 0)
                    {
                        continue;
                    }
                    if (bi.ExcludedList.Contains(bj))
                    {
                        continue;
                    }
                    if (bi.InvMass == 0.0f && bj.InvMass == 0.0f)
                    {
                        continue;
                    }
                    if (!bi.Shape.Bounds.Touches(bi.GetPosition().X, bi.GetPosition().Y, bj.Shape.Bounds, bj.GetPosition().X, bj.GetPosition().Y))
                    {

                        arbiters.remove(new Arbiter(bi, bj));
                        continue;
                    }

                    Arbiter newArb = new Arbiter(bi, bj);
                    newArb.Collide(dt);

                    if (newArb.NumContacts > 0)
                    {
                        bi.Collided(bj);
                        bj.Collided(bi);

                        if (arbiters.Contains(newArb))
                        {
                            int index = arbiters.indexOf(newArb);
                            Arbiter arb = arbiters.Item(index);
                            arb.Update(newArb.Contacts, newArb.NumContacts);
                        }
                        else
                        {
                            Contact c = newArb.GetContact(0);

                            NotifyCollision(bi, bj, c.Position, c.Normal, c.Separation);
                            arbiters.add(newArb);
                            newArb.Init();
                        }
                    }
                    else
                    {
                        arbiters.remove(newArb);
                    }
                }
            }
        }
Exemple #5
0
 /// <summary> Create a new list containing the elements specified
 /// 
 /// </summary>
 /// <param name="list">The list of elements to Add to the new list
 /// </param>
 internal BodyList(BodyList list)
 {
     elements.AddRange(list.elements);
 }