Exemple #1
0
        void doCollisionTest()
        {
            if (gjk.queryCollision(shapes[0], shapes[1]))
            {
                if (stage == CollisionStage.None)
                {
                    stage = CollisionStage.Enter;
                    getContacts(contacts);
                }
                else
                {
                    List <ContactInfo> newContacts = new List <ContactInfo>();
                    getContacts(newContacts);

                    foreach (var info in newContacts)
                    {
                        ContactInfo old = contacts.Find((v) => v.hash == info.hash);
                        if (old != null)
                        {
                            info.forceNormal  = old.forceNormal;
                            info.forceTangent = old.forceTangent;
                        }
                    }

                    contacts = newContacts;
                }
            }
            else
            {
                if (stage == CollisionStage.Stay)
                {
                    stage = CollisionStage.Exit;
                }
            }
        }
Exemple #2
0
        public void update(float dt)
        {
            foreach (var body in rigidbodies)
            {
                body.preUpdate(dt);
            }

            doCollisionTest();

            // 可以在这里派发事件
            switch (stage)
            {
            case CollisionStage.Enter:
                stage = CollisionStage.Stay;
                Debug.Log("collisionEnter");
                break;

            case CollisionStage.Exit:
                stage = CollisionStage.None;
                Debug.Log("collisionExit");
                break;

            case CollisionStage.Stay:
                break;

            default:
                break;
            }

            if (stage == CollisionStage.Stay)
            {
                doPreSeperation(dt);

                for (int i = 0; i < maxIteration; ++i)
                {
                    doPostSeperation(dt);
                }
            }

            foreach (var body in rigidbodies)
            {
                body.postUpdate(dt);
            }
        }
Exemple #3
0
        /// <summary>
        /// Changing collision algorithms options.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (sender == this.checkBoxTest)
            {
                if (this.checkBoxTest.Checked)
                {
                    CollisionLevel |= CollisionStage.Box;
                }
                else
                {
                    CollisionLevel -= CollisionStage.Box;
                }
            }
            if (sender == this.checkGJKTest)
            {
                if (this.checkGJKTest.Checked)
                {
                    CollisionLevel |= CollisionStage.GJK;
                }
                else
                {
                    CollisionLevel -= CollisionStage.GJK;
                }
            }
            if (sender == this.checkBSPTest)
            {
                if (this.checkBSPTest.Checked)
                {
                    CollisionLevel |= CollisionStage.BSP;
                    //this.autopartitioningBtn.Checked = true;
                }
                else
                {
                    CollisionLevel -= CollisionStage.BSP;
                }
            }

            if (SpaceApplication.Instance.ActiveObject != null)
            {
                SpaceApplication.Instance.ActiveObject.IsChanged = true;
            }
            SpaceApplication.Instance.Focus();
        }