Exemple #1
0
        public void Query(ITreeCallback cb, AABB aabb)
        {
            int sp = 1;

            c_stack[0] = Root;

            while (sp > 0)
            {
                int id = c_stack[--sp];

                Node n = Nodes[id];
                if (AABB.AABBtoAABB(aabb, n.aabb))
                {
                    if (n.IsLeaf())
                    {
                        if (!cb.TreeCallback(id))
                        {
                            return;
                        }
                    }
                    else
                    {
                        c_stack[sp++] = n.left;
                        c_stack[sp++] = n.right;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Query an AABB for overlapping proxies. The callback class is called for each proxy that
        /// overlaps the supplied AABB.
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="aabb"></param>
        public void Query(ITreeCallback callback, AABB aabb)
        {
            intStack.Reset();
            intStack.Push(m_root);

            while (intStack.Count > 0)
            {
                int nodeId = intStack.Pop();
                if (nodeId == TreeNode.NULL_NODE)
                {
                    continue;
                }

                TreeNode node = m_nodes[nodeId];

                if (AABB.TestOverlap(node.AABB, aabb))
                {
                    if (node.Leaf)
                    {
                        bool proceed = callback.TreeCallback(nodeId);
                        if (!proceed)
                        {
                            return;
                        }
                    }
                    else
                    {
                        intStack.Push(node.Child1);
                        intStack.Push(node.Child2);
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Query an AABB for overlapping proxies. The callback class is called for each proxy that
 /// overlaps the supplied AABB.
 /// </summary>
 /// <param name="callback"></param>
 /// <param name="aabb"></param>
 public void Query(ITreeCallback callback, AABB aabb)
 {
     m_tree.Query(callback, aabb);
 }
Exemple #4
0
 /// <summary>
 /// Query an AABB for overlapping proxies. The callback class is called for each proxy that
 /// overlaps the supplied AABB.
 /// </summary>
 /// <param name="callback"></param>
 /// <param name="aabb"></param>
 public void Query(ITreeCallback callback, AABB aabb)
 {
     m_tree.Query(callback, aabb);
 }
Exemple #5
0
        public void Query(ITreeCallback cb, RaycastData rayCast)
        {
            double k_epsilon       = 1e-6;
            int    k_stackCapacity = 256;

            int[] stack = new int[k_stackCapacity];
            int   sp    = 1;

            stack[0] = Root;

            Vec3 p0 = rayCast.start;
            Vec3 p1 = p0 + rayCast.dir * rayCast.t;

            while (sp > 0)
            {
                // k_stackCapacity too small
                Assert(sp < k_stackCapacity);

                int id = stack[--sp];

                if (id == Node.Null)
                {
                    continue;
                }

                Node n = Nodes[id];

                Vec3 e = n.aabb.max - n.aabb.min;
                Vec3 d = p1 - p0;
                Vec3 m = p0 + p1 - n.aabb.min - n.aabb.max;

                double adx = Math.Abs(d.x);

                if (Math.Abs(m.x) > e.x + adx)
                {
                    continue;
                }

                double ady = Math.Abs(d.y);

                if (Math.Abs(m.y) > e.y + ady)
                {
                    continue;
                }

                double adz = Math.Abs(d.z);

                if (Math.Abs(m.z) > e.z + adz)
                {
                    continue;
                }

                adx += k_epsilon;
                ady += k_epsilon;
                adz += k_epsilon;

                if (Math.Abs(m.y * d.z - m.z * d.y) > e.y * adz + e.z * ady)
                {
                    continue;
                }

                if (Math.Abs(m.z * d.x - m.x * d.z) > e.x * adz + e.z * adx)
                {
                    continue;
                }

                if (Math.Abs(m.x * d.y - m.y * d.x) > e.x * ady + e.y * adx)
                {
                    continue;
                }

                if (n.IsLeaf())
                {
                    if (!cb.TreeCallback(id))
                    {
                        return;
                    }
                }

                else
                {
                    stack[sp++] = n.left;
                    stack[sp++] = n.right;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Query an AABB for overlapping proxies. The callback class is called for each proxy that
        /// overlaps the supplied AABB.
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="aabb"></param>
        public void Query(ITreeCallback callback, AABB aabb)
        {
            intStack.Reset();
            intStack.Push(m_root);

            while (intStack.Count > 0)
            {
                int nodeId = intStack.Pop();
                if (nodeId == TreeNode.NULL_NODE)
                {
                    continue;
                }

                TreeNode node = m_nodes[nodeId];

                if (AABB.TestOverlap(node.AABB, aabb))
                {
                    if (node.Leaf)
                    {
                        bool proceed = callback.TreeCallback(nodeId);
                        if (!proceed)
                        {
                            return;
                        }
                    }
                    else
                    {
                        intStack.Push(node.Child1);
                        intStack.Push(node.Child2);
                    }
                }
            }
        }