public void AddToChildBroadphase(MultiSapProxy parentMultiSapProxy, BroadphaseProxy childProxy, IBroadphaseInterface childBroadphase)
        {
            BridgeProxy bridgeProxyRef = new BridgeProxy();

            bridgeProxyRef.m_childProxy      = childProxy;
            bridgeProxyRef.m_childBroadphase = childBroadphase;
            parentMultiSapProxy.m_bridgeProxies.Add(bridgeProxyRef);
        }
        public virtual void SetAabb(BroadphaseProxy proxy, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax, IDispatcher dispatcher)
        {
            MultiSapProxy multiProxy = (MultiSapProxy)proxy;

            multiProxy.m_aabbMin = aabbMin;
            multiProxy.m_aabbMax = aabbMax;

            MyNodeOverlapCallback myNodeCallback = new MyNodeOverlapCallback(this, multiProxy, dispatcher);

            if (m_optimizedAabbTree != null)
            {
                m_optimizedAabbTree.ReportAabbOverlappingNodex(myNodeCallback, ref aabbMin, ref aabbMax);
            }

            for (int i = 0; i < multiProxy.m_bridgeProxies.Count; i++)
            {
                IndexedVector3 worldAabbMin;
                IndexedVector3 worldAabbMax;
                multiProxy.m_bridgeProxies[i].m_childBroadphase.GetBroadphaseAabb(out worldAabbMin, out worldAabbMax);
                bool overlapsBroadphase = AabbUtil2.TestAabbAgainstAabb2(ref worldAabbMin, ref worldAabbMax, ref multiProxy.m_aabbMin, ref multiProxy.m_aabbMax);
                if (!overlapsBroadphase)
                {
                    //remove it now
                    BridgeProxy bridgeProxy = multiProxy.m_bridgeProxies[i];

                    BroadphaseProxy childProxy = bridgeProxy.m_childProxy;
                    bridgeProxy.m_childBroadphase.DestroyProxy(childProxy, dispatcher);

                    multiProxy.m_bridgeProxies.RemoveAtQuick(i);
                }
            }


            /*
             *
             * if (1)
             * {
             *
             *  //find broadphase that contain this multiProxy
             *  int numChildBroadphases = getBroadphaseArray().size();
             *  for (int i=0;i<numChildBroadphases;i++)
             *  {
             *      btBroadphaseInterface* childBroadphase = getBroadphaseArray()[i];
             *      btVector3 worldAabbMin,worldAabbMax;
             *      childBroadphase->getBroadphaseAabb(worldAabbMin,worldAabbMax);
             *      bool overlapsBroadphase = TestAabbAgainstAabb2(worldAabbMin,worldAabbMax,multiProxy->m_aabbMin,multiProxy->m_aabbMax);
             *
             *  //	fullyContained = fullyContained || boxIsContainedWithinBox(worldAabbMin,worldAabbMax,multiProxy->m_aabbMin,multiProxy->m_aabbMax);
             *      int containingBroadphaseIndex = -1;
             *
             *      //if already contains this
             *
             *      for (int i=0;i<multiProxy->m_bridgeProxies.size();i++)
             *      {
             *          if (multiProxy->m_bridgeProxies[i]->m_childBroadphase == childBroadphase)
             *          {
             *              containingBroadphaseIndex = i;
             *          }
             *          alreadyInSimple = alreadyInSimple || (multiProxy->m_bridgeProxies[i]->m_childBroadphase == m_simpleBroadphase);
             *      }
             *
             *      if (overlapsBroadphase)
             *      {
             *          if (containingBroadphaseIndex<0)
             *          {
             *              btBroadphaseProxy* childProxy = childBroadphase->createProxy(aabbMin,aabbMax,multiProxy->m_shapeType,multiProxy->m_clientObject,multiProxy->m_collisionFilterGroup,multiProxy->m_collisionFilterMask, dispatcher);
             *              childProxy->m_multiSapParentProxy = multiProxy;
             *              addToChildBroadphase(multiProxy,childProxy,childBroadphase);
             *          }
             *      } else
             *      {
             *          if (containingBroadphaseIndex>=0)
             *          {
             *              //remove
             *              btBridgeProxy* bridgeProxy = multiProxy->m_bridgeProxies[containingBroadphaseIndex];
             *
             *              btBroadphaseProxy* childProxy = bridgeProxy->m_childProxy;
             *              bridgeProxy->m_childBroadphase->destroyProxy(childProxy,dispatcher);
             *
             *              multiProxy->m_bridgeProxies.swap( containingBroadphaseIndex,multiProxy->m_bridgeProxies.size()-1);
             *              multiProxy->m_bridgeProxies.pop_back();
             *          }
             *      }
             *  }
             *
             *
             *  ///If we are in no other child broadphase, stick the proxy in the global 'simple' broadphase (brute force)
             *  ///hopefully we don't end up with many entries here (can assert/provide feedback on stats)
             *  if (0)//!multiProxy->m_bridgeProxies.size())
             *  {
             *      ///we don't pass the userPtr but our multisap proxy. We need to patch this, before processing an actual collision
             *      ///this is needed to be able to calculate the aabb overlap
             *      btBroadphaseProxy* childProxy = m_simpleBroadphase->createProxy(aabbMin,aabbMax,multiProxy->m_shapeType,multiProxy->m_clientObject,multiProxy->m_collisionFilterGroup,multiProxy->m_collisionFilterMask, dispatcher);
             *      childProxy->m_multiSapParentProxy = multiProxy;
             *      addToChildBroadphase(multiProxy,childProxy,m_simpleBroadphase);
             *  }
             * }
             *
             * if (!multiProxy->m_bridgeProxies.size())
             * {
             *  ///we don't pass the userPtr but our multisap proxy. We need to patch this, before processing an actual collision
             *  ///this is needed to be able to calculate the aabb overlap
             *  btBroadphaseProxy* childProxy = m_simpleBroadphase->createProxy(aabbMin,aabbMax,multiProxy->m_shapeType,multiProxy->m_clientObject,multiProxy->m_collisionFilterGroup,multiProxy->m_collisionFilterMask, dispatcher);
             *  childProxy->m_multiSapParentProxy = multiProxy;
             *  addToChildBroadphase(multiProxy,childProxy,m_simpleBroadphase);
             * }
             */


            //update
            for (int i = 0; i < multiProxy.m_bridgeProxies.Count; i++)
            {
                BridgeProxy bridgeProxyRef = multiProxy.m_bridgeProxies[i];
                bridgeProxyRef.m_childBroadphase.SetAabb(bridgeProxyRef.m_childProxy, ref aabbMin, ref aabbMax, dispatcher);
            }
        }