public Block(Ch0nk ch0Nk, Vector3b relativePosition, IMaterial material, byte size) { this.ch0Nk = ch0Nk; this.relativePosition = relativePosition; this.material = material; this.size = size; }
public List<Block> GetRandomTestingBlocks(Vector3i startingPosition) { List<Block> blocks = new List<Block>(); PerlinNoise noise = new PerlinNoise(99); Ch0nk c = new Ch0nk(this, startingPosition, new GrassMaterial()); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { for (int k = 0; k < 64; k++) { double d = noise.Noise(i + 0.5, j + 0.5, k + 0.5); //Console.WriteLine(d); IMaterial material = new GrassMaterial(); if (d > 0.5) material = new GrassMaterial(); else if (d > 0.0) material = new SandMaterial(); else if (d > -0.5) material = new StoneMaterial(); blocks.Add(new Block(c, new Vector3b(i, j, k), material, 1)); } } } return blocks; }
/// <summary> /// Gets all the blocks contained in this tree and the subtrees /// </summary> /// <param name="ch0Nk"></param> /// <param name="startLocation"></param> /// <returns></returns> public List<Block> GetAllBlocks(Ch0nk ch0Nk, Vector3b startLocation) { //if there are no children, this block is returned if (_children == null) //if (_material is AirMaterial) // return new List<Block>(1); //else return new List<Block>(new[] { new Block(ch0Nk, startLocation, _material, Size) }); //otherwise, iterate over all the children List<Block> blocks = new List<Block>(); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) { if (_children[i, j, k] == null) blocks.Add(new Block(ch0Nk, startLocation + new Vector3b(i * _middle, j * _middle, k * _middle), _material, _middle)); else blocks.AddRange(_children[i, j, k].GetAllBlocks(ch0Nk, startLocation + new Vector3b(i * _middle, j * _middle, k * _middle))); //else if (!(_material is AirMaterial)) } return blocks; }
public void ChangeMaterial(BoundingShape boundingShape, IMaterial material, Ch0nk ch0Nk, Vector3b startLocation) { Vector3i treeAbsolutePosition = ch0Nk.Position + startLocation; BoundingCube treeBoundingBox = new BoundingCube(treeAbsolutePosition, Size); //if (_children == null && boundingShape.Encloses(treeBoundingBox) && Size > 1) //Console.WriteLine("GOT IT"); if ((Size == 1) || (_children == null && boundingShape.Encloses(treeBoundingBox))) { _material = material; } else { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) { Vector3i childAbsolutePosition = ch0Nk.Position + startLocation + new Vector3b(i * _middle, j * _middle, k * _middle); BoundingCube childBoundingBox = new BoundingCube(childAbsolutePosition, _middle); if (childBoundingBox.Intersects(boundingShape)) { if (_children == null) _children = new EightFoldTree[2, 2, 2]; if (_children[i, j, k] == null) _children[i, j, k] = new EightFoldTree(_middle, _material); _children[i, j, k].ChangeMaterial(boundingShape, material, ch0Nk, startLocation + new Vector3b(i * _middle, j * _middle, k * _middle)); } } } }