Exemple #1
0
        /// <summary> Create a new arbiter - this should only be done by the 
        /// engine
        /// 
        /// </summary>
        /// <param name="b1">The first body in contact
        /// </param>
        /// <param name="b2">The second body in contact
        /// </param>
        internal Arbiter(Body b1, Body b2)
        {
            for (int i = 0; i < MAX_POINTS; i++)
            {
                contacts[i] = new Contact();
            }

            if (!(b2 is StaticBody) && b1.GetHashCode() < b2.GetHashCode())
            {
                body1 = b1;
                body2 = b2;
            }
            else
            {
                body1 = b2;
                body2 = b1;
            }
        }
Exemple #2
0
 /// <summary> Set the contact information based on another contact
 /// 
 /// </summary>
 /// <param name="contact">The contact information
 /// </param>
 internal virtual void Reconfigure(Contact contact)
 {
     position.Reconfigure(contact.position);
     normal.Reconfigure(contact.normal);
     separation = contact.separation;
     accumulatedNormalImpulse = contact.accumulatedNormalImpulse;
     accumulatedTangentImpulse = contact.accumulatedTangentImpulse;
     massNormal = contact.massNormal;
     massTangent = contact.massTangent;
     bias = contact.bias;
     restitution = contact.restitution;
     feature.SetFromOther(contact.feature);
 }
Exemple #3
0
        /// <summary> Update this arbiter from a second set of data determined
        /// as the simulation continues
        /// 
        /// </summary>
        /// <param name="newContacts">The new contacts that have been found
        /// </param>
        /// <param name="numNewContacts">The number of new contacts discovered
        /// </param>
        internal virtual void Update(Contact[] newContacts, int numNewContacts)
        {
            Contact[] mergedContacts = new Contact[MAX_POINTS];
            for (int i = 0; i < mergedContacts.Length; i++)
            {
                mergedContacts[i] = new Contact();
            }

            for (int i = 0; i < numNewContacts; ++i)
            {
                Contact cNew = newContacts[i];
                int k = - 1;
                for (int j = 0; j < numContacts; ++j)
                {
                    Contact cOld = contacts[j];
                    if (cNew.feature.Equals(cOld.feature))
                    {
                        k = j;
                        break;
                    }
                }

                if (k > - 1)
                {
                    Contact c = mergedContacts[i];
                    Contact cOld = contacts[k];
                    c.Reconfigure(cNew);
                    c.accumulatedNormalImpulse = cOld.accumulatedNormalImpulse;
                    c.accumulatedTangentImpulse = cOld.accumulatedTangentImpulse;
                }
                else
                {
                    mergedContacts[i].Reconfigure(newContacts[i]);
                }
            }

            for (int i = 0; i < numNewContacts; ++i)
            {
                contacts[i].Reconfigure(mergedContacts[i]);
            }

            numContacts = numNewContacts;
        }