예제 #1
0
 public static void BuildTree(OctCell root, BoundingSphere bounds, Action <OctCell> forLeaves, float leafSize)
 {
     if (bounds.Intersects(root.Bounds))
     {
         if ((root.Bounds.Max.X - root.Bounds.Min.X) <= leafSize)
         {
             if (root.Contents == null)
             {
                 root.Contents = new List <IOctNode>();
             }
             forLeaves(root);
         }
         else
         {
             if (root.Children == null)
             {
                 root.Children = splitCell(root);
             }
             foreach (var child in root.Children)
             {
                 BuildTree(child, bounds, forLeaves, leafSize);
             }
         }
     }
 }
예제 #2
0
 public static void VisitTree(OctCell root, Ray ray, Action<OctCell> callback)
 {
     if (ray.Intersects(root.Bounds).HasValue)
     {
         if (root.Leaf) callback(root);
         else foreach (var child in root.Children) VisitTree(child, ray, callback);
     }
 }
예제 #3
0
 public static void VisitTree(OctCell root, BoundingFrustum frustum, Action<OctCell> callback)
 {
     if (frustum.Intersects(root.Bounds))
     {
         if (root.Leaf) callback(root);
         else foreach (var child in root.Children) VisitTree(child, frustum, callback);
     }
 }
예제 #4
0
 public static void VisitTree(OctCell root, BoundingSphere bounds, Action<OctCell> callback)
 {
     if (bounds.Intersects(root.Bounds))
     {
         if (root.Leaf) callback(root);
         else foreach (var child in root.Children) VisitTree(child, bounds, callback);
     }
 }
예제 #5
0
 public static void RemoveNode(OctCell root, IOctNode node)
 {
     VisitTree(root, node.Bounds, (cell) => { if (cell.Contents != null)
                                              {
                                                  cell.Contents.Remove(node);
                                              }
               });
 }
예제 #6
0
 public static void BuildTree(OctCell root, BoundingSphere bounds, Action<OctCell> forLeaves, float leafSize)
 {
     if (bounds.Intersects(root.Bounds))
     {
         if ((root.Bounds.Max.X - root.Bounds.Min.X) <= leafSize)
         {
             if (root.Contents == null) root.Contents = new List<IOctNode>();
             forLeaves(root);
         }
         else
         {
             if (root.Children == null) root.Children = splitCell(root);
             foreach (var child in root.Children) BuildTree(child, bounds, forLeaves, leafSize);
         }
     }
 }
예제 #7
0
 public static void VisitTree(OctCell root, Ray ray, Action <OctCell> callback)
 {
     if (ray.Intersects(root.Bounds).HasValue)
     {
         if (root.Leaf)
         {
             callback(root);
         }
         else
         {
             foreach (var child in root.Children)
             {
                 VisitTree(child, ray, callback);
             }
         }
     }
 }
예제 #8
0
 public static void VisitTree(OctCell root, BoundingFrustum frustum, Action <OctCell> callback)
 {
     if (frustum.Intersects(root.Bounds))
     {
         if (root.Leaf)
         {
             callback(root);
         }
         else
         {
             foreach (var child in root.Children)
             {
                 VisitTree(child, frustum, callback);
             }
         }
     }
 }
예제 #9
0
 public static void VisitTree(OctCell root, BoundingSphere bounds, Action <OctCell> callback)
 {
     if (bounds.Intersects(root.Bounds))
     {
         if (root.Leaf)
         {
             callback(root);
         }
         else
         {
             foreach (var child in root.Children)
             {
                 VisitTree(child, bounds, callback);
             }
         }
     }
 }
예제 #10
0
        private static OctCell[] splitCell(OctCell root)
        {
            var into = new OctCell[8];
            var dims = (root.Bounds.Max - root.Bounds.Min) / 2;
            var min  = root.Bounds.Min;

            into[0] = new OctCell(makeBox(min.X, min.Y, min.Z, dims.X, dims.Y, dims.Z));
            into[1] = new OctCell(makeBox(min.X + dims.X, min.Y, min.Z, dims.X, dims.Y, dims.Z));
            into[2] = new OctCell(makeBox(min.X, min.Y + dims.Y, min.Z, dims.X, dims.Y, dims.Z));
            into[3] = new OctCell(makeBox(min.X + dims.X, min.Y + dims.Y, min.Z, dims.X, dims.Y, dims.Z));

            into[4] = new OctCell(makeBox(min.X, min.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));
            into[5] = new OctCell(makeBox(min.X + dims.X, min.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));
            into[6] = new OctCell(makeBox(min.X, min.Y + dims.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));
            into[7] = new OctCell(makeBox(min.X + dims.X, min.Y + dims.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));

            return(into);
        }
예제 #11
0
        private static OctCell[] splitCell(OctCell root)
        {
            var into = new OctCell[8];
            var dims = (root.Bounds.Max - root.Bounds.Min) / 2;
            var min = root.Bounds.Min;
            into[0] = new OctCell(makeBox(min.X, min.Y, min.Z, dims.X, dims.Y, dims.Z));
            into[1] = new OctCell(makeBox(min.X + dims.X, min.Y, min.Z, dims.X, dims.Y, dims.Z));
            into[2] = new OctCell(makeBox(min.X, min.Y + dims.Y, min.Z, dims.X, dims.Y, dims.Z));
            into[3] = new OctCell(makeBox(min.X + dims.X, min.Y + dims.Y, min.Z, dims.X, dims.Y, dims.Z));

            into[4] = new OctCell(makeBox(min.X, min.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));
            into[5] = new OctCell(makeBox(min.X + dims.X, min.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));
            into[6] = new OctCell(makeBox(min.X, min.Y + dims.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));
            into[7] = new OctCell(makeBox(min.X + dims.X, min.Y + dims.Y, min.Z + dims.Z, dims.X, dims.Y, dims.Z));

            return into;
        }
예제 #12
0
 public static void RemoveNode(OctCell root, IOctNode node)
 {
     VisitTree(root, node.Bounds, (cell) => { if (cell.Contents != null) cell.Contents.Remove(node); });
 }
예제 #13
0
 public static void InsertNode(OctCell root, IOctNode node, float leafSize)
 {
     BuildTree(root, node.Bounds, (cell) => { cell.Contents.Add(node); }, leafSize);
 }
예제 #14
0
 public static void InsertNode(OctCell root, IOctNode node, float leafSize)
 {
     BuildTree(root, node.Bounds, (cell) => { cell.Contents.Add(node); }, leafSize);
 }