Beispiel #1
0
        public override void DestroyVolume(MyElement element)
        {
            if (element.ProxyData == MyElement.PROXY_UNASSIGNED)
            {
                return;
            }
            m_DAABBTree.RemoveProxy(element.ProxyData);
            element.ProxyData = MyElement.PROXY_UNASSIGNED;

            if ((element.Flags & MyElementFlag.EF_SENSOR_ELEMENT) > 0)
            {
                MySensorElement se = (MySensorElement)element;
            }

            if ((element.Flags & MyElementFlag.EF_RB_ELEMENT) > 0)
            {
                MyRBElement elm = (MyRBElement)element;


                //clear all iterations from me and from objects i iterate with
                while (elm.GetRBElementInteractions().Count > 0)
                {
                    MyRBElementInteraction intr = elm.GetRBElementInteractions()[0];
                    MyPhysics.physicsSystem.GetRBInteractionModule().RemoveRBElementInteraction(intr.RBElement1, intr.RBElement2);
                }


                elm.GetRBElementInteractions().Clear();
            }
        }
        /// <summary>
        /// Looks if interaction between those elements already exist
        /// </summary>
        public MyRBElementInteraction FindRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            // look for interaction on element
            for (int i = 0; i < el1.GetRBElementInteractions().Count; i++)
            {
                MyRBElementInteraction intr = el1.GetRBElementInteractions()[i];
                if (intr.RBElement1 == el2 || intr.RBElement2 == el2)
                {
                    return(intr);
                }
            }

            return(null);
        }
        /// <summary>
        /// Removes interaction between these 2 elements
        /// </summary>
        public void RemoveRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            if (el1 != null)
            {
                // look for interaction on element
                for (int i = 0; i < el1.GetRBElementInteractions().Count; i++)
                {
                    MyRBElementInteraction intr = el1.GetRBElementInteractions()[i];
                    if ((intr.RBElement1 == el1 && intr.RBElement2 == el2) || (intr.RBElement1 == el2 && intr.RBElement2 == el1))
                    {
                        // add it back
                        int t1 = (int)el1.GetElementType();
                        int t2 = (int)el2.GetElementType();
                        List <MyRBElementInteraction> intrList = null;
                        if (t1 < t2)
                        {
                            intrList = m_IslandsPool[t1, t2];
                        }
                        else
                        {
                            intrList = m_IslandsPool[t2, t1];
                        }
                        intrList.Add(intr);

                        el1.GetRBElementInteractions().Remove(intr);
                        break;
                    }
                }
            }

            if (el2 != null)
            {
                for (int i = 0; i < el2.GetRBElementInteractions().Count; i++)
                {
                    MyRBElementInteraction intr = el2.GetRBElementInteractions()[i];
                    if ((intr.RBElement1 == el1 && intr.RBElement2 == el2) || (intr.RBElement1 == el2 && intr.RBElement2 == el1))
                    {
                        intr.RBElement1 = null;
                        intr.RBElement2 = null;

                        el2.GetRBElementInteractions().Remove(intr);
                        break;
                    }
                }
            }
        }
Beispiel #4
0
        public override void DestroyVolume(MyElement element)
        {
            if ((element.Flags & MyElementFlag.EF_SENSOR_ELEMENT) > 0)
            {
                return;
            }
            MyRBElement elm = (MyRBElement)element;

            elm.GetRBElementInteractions().Clear();
            m_Elements.Remove(elm);
        }
        /// <summary>
        /// Adds interaction between 2 given elements
        /// </summary>
        public MyRBElementInteraction AddRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            // get it
            int t1 = (int)el1.GetElementType();
            int t2 = (int)el2.GetElementType();
            List <MyRBElementInteraction> intrList = null;

            if (t1 < t2)
            {
                intrList = m_IslandsPool[t1, t2];
            }
            else
            {
                intrList = m_IslandsPool[t2, t1];
            }

            //pada to jinak
            if (intrList.Count == 0)
            {
                return(null);
            }

            MyCommonDebugUtils.AssertDebug(intrList.Count != 0);

            if (intrList.Count == 1)
            {
                MyRBElementInteraction ins = intrList[0].CreateNewInstance();
                intrList.Add(ins);
            }

            MyRBElementInteraction intr = intrList[intrList.Count - 1];

            intrList.RemoveAt(intrList.Count - 1);

            intr.RBElement1 = el1;
            intr.RBElement2 = el2;

            el1.GetRBElementInteractions().Add(intr);
            el2.GetRBElementInteractions().Add(intr);

            return(intr);
        }
        /// <summary>
        /// Adding rigid body recursively to check for constraint connections and make sure that its only in 1 island
        /// </summary>
        private void AddRigidBody(MyRigidBody rbo, MyRigidBody secondRigidBody, MyRigidBodyIsland addIsland)
        {
            if (rbo.IsStatic())
            {
                rbo.PutToSleep();
                return;
            }

            if (!m_proccesedList.Add(rbo))
            {
                return;
            }

            // add rigid bodies to island recursively
            int numInteractions = 0;

            for (int j = 0; j < rbo.GetRBElementList().Count; j++)
            {
                MyRBElement el = rbo.GetRBElementList()[j];
                numInteractions += el.GetRBElementInteractions().Count;

                for (int k = 0; k < el.GetRBElementInteractions().Count; k++)
                {
                    if (addIsland == null && !rbo.IsStatic())
                    {
                        addIsland = m_islandsPool.Allocate();
                        addIsland.Clear();
                        addIsland.IterationCount = 0;
                        addIsland.AddRigidBody(rbo);

                        m_islands.Add(addIsland);
                    }
                    else
                    {
                        if (!rbo.IsStatic())
                        {
                            addIsland.AddRigidBody(rbo);
                        }
                    }

                    MyRBElementInteraction intr = el.GetRBElementInteractions()[k];

                    if (intr.GetRigidBody1() != rbo && intr.GetRigidBody2() != secondRigidBody)
                    {
                        AddRigidBody(intr.GetRigidBody1(), rbo, addIsland);
                    }

                    if (intr.GetRigidBody2() != rbo && intr.GetRigidBody1() != secondRigidBody)
                    {
                        AddRigidBody(intr.GetRigidBody2(), rbo, addIsland);
                    }
                }
            }

            // isolated rbo
            if (numInteractions == 0 && !rbo.IsStatic())
            {
                MyRigidBodyIsland island = m_islandsPool.Allocate();
                island.Clear();
                island.IterationCount = 0;
                island.AddRigidBody(rbo);

                m_islands.Add(island);
            }
        }
        /// <summary>
        /// Removes interaction between these 2 elements
        /// </summary>
        public void RemoveRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            if (el1 != null)
            {
                // look for interaction on element
                for (int i = 0; i < el1.GetRBElementInteractions().Count; i++)
                {
                    MyRBElementInteraction intr = el1.GetRBElementInteractions()[i];
                    if ((intr.RBElement1 == el1 && intr.RBElement2 == el2) || (intr.RBElement1 == el2 && intr.RBElement2 == el1))
                    {
                        // add it back
                        int t1 = (int)el1.GetElementType();
                        int t2 = (int)el2.GetElementType();
                        List<MyRBElementInteraction> intrList = null;
                        if (t1 < t2)
                            intrList = m_IslandsPool[t1, t2];
                        else
                            intrList = m_IslandsPool[t2, t1];
                        intrList.Add(intr);

                        el1.GetRBElementInteractions().Remove(intr);
                        break;
                    }
                }
            }

            if (el2 != null)
            {
                for (int i = 0; i < el2.GetRBElementInteractions().Count; i++)
                {
                    MyRBElementInteraction intr = el2.GetRBElementInteractions()[i];
                    if ((intr.RBElement1 == el1 && intr.RBElement2 == el2) || (intr.RBElement1 == el2 && intr.RBElement2 == el1))
                    {
                        intr.RBElement1 = null;
                        intr.RBElement2 = null;

                        el2.GetRBElementInteractions().Remove(intr);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Adds interaction between 2 given elements
        /// </summary>
        public MyRBElementInteraction AddRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            // get it
            int t1 = (int)el1.GetElementType();
            int t2 = (int)el2.GetElementType();
            List<MyRBElementInteraction> intrList = null;
            if (t1 < t2)
                intrList = m_IslandsPool[t1, t2];
            else
                intrList = m_IslandsPool[t2, t1];

            //pada to jinak
            if (intrList.Count == 0)
                return null; 

            MyCommonDebugUtils.AssertDebug(intrList.Count != 0);

            if (intrList.Count == 1)
            {
                MyRBElementInteraction ins = intrList[0].CreateNewInstance();
                intrList.Add(ins);
            }

            MyRBElementInteraction intr = intrList[intrList.Count - 1];
            intrList.RemoveAt(intrList.Count - 1);

            intr.RBElement1 = el1;
            intr.RBElement2 = el2;

            el1.GetRBElementInteractions().Add(intr);
            el2.GetRBElementInteractions().Add(intr);

            return intr;
        }
        /// <summary>
        /// Looks if interaction between those elements already exist
        /// </summary>
        public MyRBElementInteraction FindRBElementInteraction(MyRBElement el1, MyRBElement el2)
        {
            // look for interaction on element
            for (int i = 0; i < el1.GetRBElementInteractions().Count; i++)
            {
                MyRBElementInteraction intr = el1.GetRBElementInteractions()[i];
                if (intr.RBElement1 == el2 || intr.RBElement2 == el2)
                    return intr;
            }

            return null;
        }