Exemple #1
0
        private void ClearInteractions()
        {
            MyRBInteractionModule module = MyPhysics.physicsSystem.GetRBInteractionModule();

            foreach (var intr in m_InteractionList)
            {
                module.RemoveRBElementInteraction(intr.RBElement1, intr.RBElement2);
            }

            m_InteractionList.Clear();
        }
Exemple #2
0
        public override void DoWork()
        {
            // brute force
            MyRBInteractionModule module       = MyPhysics.physicsSystem.GetRBInteractionModule();
            List <MyRigidBody>    activeRigids = MyPhysics.physicsSystem.GetRigidBodyModule().GetActiveRigids();

            m_ActiveElements.Clear();

            for (int i = 0; i < activeRigids.Count; i++)
            {
                MyRigidBody rbo = activeRigids[i];
                for (int j = 0; j < rbo.GetRBElementList().Count; j++)
                {
                    MyRBElement el = rbo.GetRBElementList()[j];
                    el.UpdateAABB();
                    m_ActiveElements.Add(el);
                }
            }

            // parse the elements
            BoundingBox            bbox;
            MyRBElementInteraction interaction = null;

            m_InteractionList.Clear();
            for (int i = 0; i < m_ActiveElements.Count; i++)
            {
                MyRBElement testEl   = m_ActiveElements[i];
                BoundingBox testAABB = testEl.GetWorldSpaceAABB();
                for (int j = 0; j < m_Elements.Count; j++)
                {
                    MyRBElement el = m_Elements[j];
                    interaction = null;
                    if (el != testEl)
                    {
                        if (el.GetRigidBody().IsStatic() && testEl.GetRigidBody().IsStatic())
                        {
                            continue;
                        }

                        if (el.GetRigidBody().IsKinematic() && testEl.GetRigidBody().IsKinematic())
                        {
                            continue;
                        }

                        if (el.GetRigidBody() == testEl.GetRigidBody())
                        {
                            continue;
                        }

                        bbox = el.GetWorldSpaceAABB();
                        if (bbox.Intersects(testAABB))
                        {
                            interaction = module.FindRBElementInteraction(el, testEl);
                            if (interaction == null)
                            {
                                interaction = module.AddRBElementInteraction(el, testEl);
                            }
                        }
                        else
                        {
                            interaction = module.FindRBElementInteraction(el, testEl);
                            if (interaction != null)
                            {
                                interaction = null;
                                module.RemoveRBElementInteraction(el, testEl);
                            }
                        }

                        if (interaction != null)
                        {
                            bool iinserted = false;
                            for (int t = 0; t < m_InteractionList.Count; t++)
                            {
                                if (m_InteractionList[t] == interaction)
                                {
                                    iinserted = true;
                                    break;
                                }
                            }
                            if (!iinserted)
                            {
                                m_InteractionList.Add(interaction);
                            }
                        }
                    }
                }
            }
        }