Esempio n. 1
0
        public List <OctreeElement <T> > neighborsWithin(OctreeElement <T> e, uint distance)
        {
            Vector3 pos = new Vector3(e.myX, e.myY, e.myZ);
            int     id  = myNodes[0].nodeContainingSphere(pos, distance);

            List <OctreeElement <T> > actualList = new List <OctreeElement <T> >();

            foreach (OctreeElement <T> el in myNodes[id].myElements)
            {
                if (e.distanceBetween(el) < distance)
                {
                    actualList.Add(el);
                }
            }

            return(actualList);
        }
Esempio n. 2
0
        public OctreeElement <T> nearestNeighborWithin(OctreeElement <T> e, ref uint distance)
        {
            OctreeElement <T> nearest = null;

            if (isLeaf() == false)
            {
                for (int i = 0; i < 8; i++)
                {
                    int childId = myChildren[i];
                    if (childId != -1)
                    {
                        uint tempDistance = distance;
                        OctreeElement <T> tempNearest;
                        tempNearest = myOctree.myNodes[childId].nearestNeighborWithin(e, ref tempDistance);
                        if (tempNearest != e && tempDistance < distance)
                        {
                            distance = tempDistance;
                            nearest  = tempNearest;
                        }
                    }
                }
            }
            else
            {
                //check the elements stored in this node (assuming it's a leaf)
                foreach (OctreeElement <T> el in myElements)
                {
                    if (el == e)
                    {
                        continue;
                    }

                    uint tempDistance = e.distanceBetween(el);
                    if (tempDistance < distance)
                    {
                        distance = tempDistance;
                        nearest  = el;
                    }
                }
            }

            return(nearest);
        }