Example #1
0
        public void Query(TSVector origin, TSVector direction, List <int> collisions)
        {
            ResourcePoolItemStack <int> stack = stackPool.GetNew();

            stack.Push(_root);

            while (stack.Count > 0)
            {
                int nodeId = stack.Pop();
                DynamicTreeNode <T> node = _nodes[nodeId];

                if (node.AABB.RayIntersect(ref origin, ref direction))
                {
                    if (node.IsLeaf())
                    {
                        collisions.Add(nodeId);
                    }
                    else
                    {
                        if (_nodes[node.Child1].AABB.RayIntersect(ref origin, ref direction))
                        {
                            stack.Push(node.Child1);
                        }
                        if (_nodes[node.Child2].AABB.RayIntersect(ref origin, ref direction))
                        {
                            stack.Push(node.Child2);
                        }
                    }
                }
            }

            stackPool.GiveBack(stack);
        }
Example #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">The callback.</param>
        /// <param name="aabb">The aabb.</param>
        public void Query(List <int> my, ref TSBBox aabb)
        {
            //Stack<int> _stack = new Stack<int>(256);
            ResourcePoolItemStack <int> _stack = stackPool.GetNew();

            _stack.Push(_root);

            while (_stack.Count > 0)
            {
                int nodeId = _stack.Pop();
                if (nodeId == NullNode)
                {
                    continue;
                }

                DynamicTreeNode <T> node = _nodes[nodeId];

                //if (JBBox.TestOverlap(ref node.AABB, ref aabb))
                if (aabb.Contains(ref node.AABB) != TSBBox.ContainmentType.Disjoint)
                {
                    if (node.IsLeaf())
                    {
                        my.Add(nodeId);
                        //bool proceed = callback(nodeId);
                        //if (proceed == false)
                        //{
                        //    return;
                        //}
                    }
                    else
                    {
                        _stack.Push(node.Child1);
                        _stack.Push(node.Child2);
                    }
                }
            }

            stackPool.GiveBack(_stack);
        }
Example #3
0
        public void Query(List <int> other, List <int> my, DynamicTree <T> tree)
        {
            ResourcePoolItemStack <int> stack1 = stackPool.GetNew();
            ResourcePoolItemStack <int> stack2 = stackPool.GetNew();

            stack1.Push(_root);
            stack2.Push(tree._root);

            while (stack1.Count > 0)
            {
                int nodeId1 = stack1.Pop();
                int nodeId2 = stack2.Pop();

                if (nodeId1 == NullNode)
                {
                    continue;
                }
                if (nodeId2 == NullNode)
                {
                    continue;
                }

                if (tree._nodes[nodeId2].AABB.Contains(ref _nodes[nodeId1].AABB) != TSBBox.ContainmentType.Disjoint)
                {
                    if (_nodes[nodeId1].IsLeaf() && tree._nodes[nodeId2].IsLeaf())
                    {
                        my.Add(nodeId1);
                        other.Add(nodeId2);
                    }
                    else if (tree._nodes[nodeId2].IsLeaf())
                    {
                        stack1.Push(_nodes[nodeId1].Child1);
                        stack2.Push(nodeId2);

                        stack1.Push(_nodes[nodeId1].Child2);
                        stack2.Push(nodeId2);
                    }
                    else if (_nodes[nodeId1].IsLeaf())
                    {
                        stack1.Push(nodeId1);
                        stack2.Push(tree._nodes[nodeId2].Child1);

                        stack1.Push(nodeId1);
                        stack2.Push(tree._nodes[nodeId2].Child2);
                    }
                    else
                    {
                        stack1.Push(_nodes[nodeId1].Child1);
                        stack2.Push(tree._nodes[nodeId2].Child1);

                        stack1.Push(_nodes[nodeId1].Child1);
                        stack2.Push(tree._nodes[nodeId2].Child2);

                        stack1.Push(_nodes[nodeId1].Child2);
                        stack2.Push(tree._nodes[nodeId2].Child1);

                        stack1.Push(_nodes[nodeId1].Child2);
                        stack2.Push(tree._nodes[nodeId2].Child2);
                    }
                }
            }

            stackPool.GiveBack(stack1);
            stackPool.GiveBack(stack2);
        }