Example #1
0
        /// <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);
                    }
                }
            }
        }
Example #2
0
 /// <summary> Return the index of a particular arbiter in the list
 /// 
 /// </summary>
 /// <param name="arbiter">The arbiter to search for
 /// </param>
 /// <returns> The index of -1 if not found
 /// </returns>
 public virtual int indexOf(Arbiter arbiter)
 {
     return elements.IndexOf(arbiter);
 }
Example #3
0
 /// <summary> Remove an abiter from the list
 /// 
 /// </summary>
 /// <param name="arbiter">The arbiter ot Remove from the list
 /// </param>
 internal virtual void remove(Arbiter arbiter)
 {
     if (!elements.Contains(arbiter))
     {
         return ;
     }
     elements[elements.IndexOf(arbiter)] = elements[elements.Count - 1];
     elements.RemoveAt(elements.Count - 1);
 }
Example #4
0
 /// <summary> Check if an arbiter is contained within a list
 /// 
 /// </summary>
 /// <param name="arb">The arbiter to check for
 /// </param>
 /// <returns> True if the arbiter is in the list
 /// </returns>
 public virtual bool Contains(Arbiter arb)
 {
     return elements.Contains(arb);
 }
Example #5
0
 /// <summary> Add an arbiter to the list
 /// 
 /// </summary>
 /// <param name="arbiter">The arbiter to Add
 /// </param>
 internal virtual void add(Arbiter arbiter)
 {
     elements.Add(arbiter);
 }