Exemplo n.º 1
0
  public void addNode(NodeModel node) {
    if (node.getOctant() != null) {
      throw new RuntimeException("Can't add a node to two octants");
    }
    Octant octant = root;
    int depth = octant.depth;

    clampPosition(node);

    while (depth < maxDepth) {
      if (octant.children == null) {
        subdivide(octant);
      }

      int index = node.octreePosition(octant.posX, octant.posY, octant.posZ, octant.size);
      octant = octant.children[index];
      depth = octant.depth;
    }

    if (octant.isEmpty()) {
      addLeaf(octant);
    }

    octant.addNode(node);
    node.setOctant(octant);
  }
Exemplo n.º 2
0
 public void removeNode(NodeModel node) {
   Octant octant = node.getOctant();
   octant.removeNode(node);
   if (octant.isEmpty()) {
     removeLeaf(octant);
   }
   node.setOctant(null);
 }