コード例 #1
0
ファイル: Block.cs プロジェクト: catdawg/Ch0nkEngine
 public Block(Ch0nk ch0Nk, Vector3b relativePosition, IMaterial material, byte size)
 {
     this.ch0Nk = ch0Nk;
     this.relativePosition = relativePosition;
     this.material = material;
     this.size = size;
 }
コード例 #2
0
ファイル: EightFoldTree.cs プロジェクト: catdawg/Ch0nkEngine
        /// <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;
        }
コード例 #3
0
ファイル: EightFoldTree.cs プロジェクト: catdawg/Ch0nkEngine
        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));
                            }
                        }
            }
        }