public static BitIndex ( int x, int y, int z, int bit ) : int | ||
x | int | |
y | int | |
z | int | |
bit | int | |
Résultat | int |
internal OctreeNode <T> Get(int x, int y, int z, int minlevel) { if (GetLevel() == minlevel) { return(this); } int equalOffsetNum = EqualOffsetNum(x, y, z); int l = level; if (equalOffsetNum == offsetBitNum) { l += offsetBitNum; } else { return(null); } int bitIndex = BitHack.BitIndex(x, y, z, l); if (!HasChilds() || nodes[bitIndex] == null) { return(null); } return(nodes[bitIndex].Get(x, y, z, minlevel)); }
internal void Set(int x, int y, int z, T val, int minlevel) { int equalOffsetNum = EqualOffsetNum(x, y, z); if (equalOffsetNum == offsetBitNum) { int bitIndex = BitHack.BitIndex(x, y, z, level + offsetBitNum); if (GetLevel() == minlevel) { value = val; return; } if (!HasChilds() || nodes[bitIndex] == null) { //Node doesn't exist - create it OctreeNode <T> leaf = initLeaf(bitIndex, x, y, z); //return leaf.value; leaf.value = val; //leaf.setChunkVal(x, y, z, val); } else { //Node exists - refer Set call // if (n.GetLevel() == minlevel) // return n.value; nodes[bitIndex].Set(x, y, z, val, minlevel); } } else { //Create Node OctreeNode <T> newc = parent.initChild(parent.GetChildIndex(this), x, y, z); newc.offsetBitNum = (byte)equalOffsetNum; newc.level = level; //Add this as child to the new Node int bitIndex = BitHack.BitIndex(xcoord, ycoord, zcoord, newc.level + newc.offsetBitNum); newc.SetChild(this, bitIndex); offsetBitNum -= (byte)(equalOffsetNum + 1); level = (byte)(newc.level + newc.offsetBitNum + 1); bitIndex = BitHack.BitIndex(x, y, z, newc.level + newc.offsetBitNum); OctreeNode <T> leaf = newc.initLeaf(bitIndex, x, y, z); //leaf.setChunkVal(x, y, z, val); //leaf.value[x, y, z] = val; leaf.value = val; } }