コード例 #1
0
ファイル: ContactProcessing.cs プロジェクト: suzuke/BulletXNA
        public void MergeContactsUnique(ContactArray contacts)
        {
            Clear();

            if (contacts.Count == 0)
            {
                return;
            }

            if (contacts.Count == 1)
            {
                Add(contacts[0]);
                return;
            }

            GIM_CONTACT average_contact = contacts[0];

            for (int i = 1; i < contacts.Count; i++)
            {
                average_contact.m_point  += contacts[i].m_point;
                average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
            }

            // can't see how this does anything....
            //divide
            float divide_average = 1.0f / ((float)contacts.Count);

            average_contact.m_point *= divide_average;

            average_contact.m_normal *= divide_average;

            average_contact.m_depth = average_contact.m_normal.Length();

            average_contact.m_normal /= average_contact.m_depth;
        }
コード例 #2
0
ファイル: ContactProcessing.cs プロジェクト: suzuke/BulletXNA
        public void MergeContacts(ContactArray contacts, bool normal_contact_average)
        {
            Clear();

            if (contacts.Count == 0)
            {
                return;
            }


            if (contacts.Count == 1)
            {
                Add(contacts[0]);
                return;
            }

            ObjectArray <CONTACT_KEY_TOKEN> keycontacts = new ObjectArray <CONTACT_KEY_TOKEN>();

            keycontacts.Capacity = contacts.Count;

            //fill key contacts

            for (int i = 0; i < contacts.Count; i++)
            {
                keycontacts.Add(new CONTACT_KEY_TOKEN(contacts[i].CalcKeyContact(), i));
            }

            //sort keys

            keycontacts.Sort(new Comparison <CONTACT_KEY_TOKEN>(CONTACT_KEY_TOKEN.SortPredicate));


            // Merge contacts
            int coincident_count = 0;

            IndexedVector3[] coincident_normals = new IndexedVector3[MAX_COINCIDENT];

            uint last_key = keycontacts[0].m_key;
            uint key      = 0;

            Add(contacts[keycontacts[0].m_value]);

            GIM_CONTACT pcontact      = this[0];
            int         pcontactIndex = 0;

            for (int i = 1; i < keycontacts.Count; i++)
            {
                key = keycontacts[i].m_key;
                GIM_CONTACT scontact = contacts[keycontacts[i].m_value];

                if (last_key == key)//same points
                {
                    //merge contact
                    if (pcontact.m_depth - GIM_CONTACT.CONTACT_DIFF_EPSILON > scontact.m_depth)//)
                    {
                        //*pcontact = *scontact;
                        this[pcontactIndex] = scontact;
                        coincident_count    = 0;
                    }
                    else if (normal_contact_average)
                    {
                        if (Math.Abs(pcontact.m_depth - scontact.m_depth) < GIM_CONTACT.CONTACT_DIFF_EPSILON)
                        {
                            if (coincident_count < MAX_COINCIDENT)
                            {
                                coincident_normals[coincident_count] = scontact.m_normal;
                                coincident_count++;
                            }
                        }
                    }
                }
                else
                {//add new contact
                    if (normal_contact_average && coincident_count > 0)
                    {
                        pcontact.InterpolateNormals(coincident_normals, coincident_count);
                        coincident_count = 0;
                    }

                    Add(scontact);
                    pcontactIndex = Count - 1;
                    pcontact      = this[pcontactIndex];
                }
                last_key = key;
            }
        }
コード例 #3
0
ファイル: ContactProcessing.cs プロジェクト: suzuke/BulletXNA
 public void MergeContacts(ContactArray contacts)
 {
     MergeContacts(contacts, true);
 }