public static void splitAt(B45LODNode root, IntVector3 atpos, int lod) { // calculate the index of the child in which the split will happen. int ind = 0; B45LODNode cur = root; IntVector3 nodeCenterPos = IntVector3.Zero; int i = 0; for (; i < lod; i++) { nodeCenterPos.x = cur.pos.x + cur.logicalSize; nodeCenterPos.y = cur.pos.y + cur.logicalSize; nodeCenterPos.z = cur.pos.z + cur.logicalSize; ind = ((atpos.x > nodeCenterPos.x) ? 1 : 0) | ((atpos.y > nodeCenterPos.y) ? 2 : 0) | ((atpos.z > nodeCenterPos.z) ? 4 : 0); if (cur.isLeaf) { cur.split(); } cur = cur.children[ind]; } }
// obtain the level 0 node that associates with the given pos. public static B45LODNode readNode(IntVector3 atpos, B45LODNode root, int lod) { // calculate the index of the child in which the split will happen. int ind = 0; B45LODNode cur = root; IntVector3 nodeCenterPos = IntVector3.Zero; while (true) { nodeCenterPos.x = cur.pos.x + cur.logicalSize / 2; nodeCenterPos.y = cur.pos.y + cur.logicalSize / 2; nodeCenterPos.z = cur.pos.z + cur.logicalSize / 2; ind = ((atpos.x >= nodeCenterPos.x) ? 1 : 0) | ((atpos.y >= nodeCenterPos.y) ? 2 : 0) | ((atpos.z >= nodeCenterPos.z) ? 4 : 0); if (cur.isLeaf) { cur.split(); } cur = cur.children[ind]; if (cur.pos.w == 0) { break; } } return(cur); }