Exemple #1
0
        public bool BoxQuery(ref AABB box, ObjectArray <int> collided_results, bool graphics)
        {
            int curIndex = 0;
            int numNodes = GetNodeCount();

            if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactBVH && !graphics)
            {
                BulletGlobals.g_streamWriter.WriteLine("QIQBVH BoxQuery [{0}]", numNodes);
            }

            //quantize box

            UShortVector3 quantizedMin;
            UShortVector3 quantizedMax;

            m_box_tree.QuantizePoint(out quantizedMin, ref box.m_min);
            m_box_tree.QuantizePoint(out quantizedMax, ref box.m_max);


            while (curIndex < numNodes)
            {
                //catch bugs in tree data

                bool aabbOverlap = m_box_tree.TestQuantizedBoxOverlap(curIndex, ref quantizedMin, ref quantizedMax);
                bool isLeafNode  = IsLeafNode(curIndex);


                if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactBVH && !graphics)
                {
                    BulletGlobals.g_streamWriter.WriteLine("QIQBVH BoxQuery [{0}] o[{1}] l[{2}]", curIndex, aabbOverlap ? 1 : 0, isLeafNode ? 1 : 0);
                }

                if (isLeafNode && aabbOverlap)
                {
                    foreach (var i in GetNodeData(curIndex))
                    {
                        collided_results.Add(i);
                    }
                }

                if (aabbOverlap || isLeafNode)
                {
                    //next subnode
                    curIndex++;
                }
                else
                {
                    //skip node
                    curIndex += GetEscapeNodeIndex(curIndex);
                }
            }
            if (collided_results.Count > 0)
            {
                return(true);
            }
            return(false);
        }
        private bool BoxQuery(ref AABB box, ObjectArray <int> collided_results, bool graphics)
        {
            int curIndex = 0;
            int numNodes = GetNodeCount();

            //quantize box

            UShortVector3 quantizedMin;
            UShortVector3 quantizedMax;

            m_box_tree.QuantizePoint(out quantizedMin, ref box.m_min);
            m_box_tree.QuantizePoint(out quantizedMax, ref box.m_max);


            while (curIndex < numNodes)
            {
                //catch bugs in tree data

                bool aabbOverlap = m_box_tree.TestQuantizedBoxOverlap(curIndex, ref quantizedMin, ref quantizedMax);
                bool isLeafNode  = IsLeafNode(curIndex);

                if (isLeafNode && aabbOverlap)
                {
                    foreach (var i in GetNodeData(curIndex))
                    {
                        collided_results.Add(i);
                    }
                }

                if (aabbOverlap || isLeafNode)
                {
                    //next subnode
                    curIndex++;
                }
                else
                {
                    //skip node
                    curIndex += GetEscapeNodeIndex(curIndex);
                }
            }
            if (collided_results.Count > 0)
            {
                return(true);
            }
            return(false);
        }