Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
 public static void RemoveNode(OctCell root, IOctNode node)
 {
     VisitTree(root, node.Bounds, (cell) => { if (cell.Contents != null)
                                              {
                                                  cell.Contents.Remove(node);
                                              }
               });
 }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 12
0
 public static void RemoveNode(OctCell root, IOctNode node)
 {
     VisitTree(root, node.Bounds, (cell) => { if (cell.Contents != null) cell.Contents.Remove(node); });
 }
Ejemplo n.º 13
0
 public static void InsertNode(OctCell root, IOctNode node, float leafSize)
 {
     BuildTree(root, node.Bounds, (cell) => { cell.Contents.Add(node); }, leafSize);
 }
Ejemplo n.º 14
0
 public static void InsertNode(OctCell root, IOctNode node, float leafSize)
 {
     BuildTree(root, node.Bounds, (cell) => { cell.Contents.Add(node); }, leafSize);
 }