Exemplo n.º 1
0
        /// <summary>
        /// Creates a new chunk.
        /// </summary>
        /// <param name="world">The world this chunk belongs to.</param>
        /// <param name="index">The index of the chunk.</param>
        /// <param name="generateTerrain">True to generate some initial terrain, false to leave each block empty.</param>
        private Chunk( World world, Vector3 index, bool generateTerrain )
        {
            _world = world;
            _data = new ChunkData( index );
            _terrain = new VoxelBuffer();

            // create bounds
            var sizeOffs = ChunkData.SizeXZ * 0.5f - 0.5f;
            Vector3 boundsMin = new Vector3(
                index.X - sizeOffs,
                -0.5f,
                index.Z - sizeOffs
            );
            Vector3 boundsMax = new Vector3(
                index.X + sizeOffs,
                0.5f + ChunkData.SizeY,
                index.Z + sizeOffs
            );
            _bounds = new BoundingBox( boundsMin, boundsMax );
            _octree = new ChunkOctree( _bounds );

            // check if we need to populate
            if ( generateTerrain )
            {
                PopulateTerrain();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new chunk.
        /// </summary>
        /// <param name="world">The world this chunk belongs to.</param>
        /// <param name="index">The index of the chunk.</param>
        /// <param name="generateTerrain">True to generate some initial terrain, false to leave each block empty.</param>
        private Chunk(World world, Vector3 index, bool generateTerrain)
        {
            _world   = world;
            _data    = new ChunkData(index);
            _terrain = new VoxelBuffer();

            // create bounds
            var     sizeOffs  = ChunkData.SizeXZ * 0.5f - 0.5f;
            Vector3 boundsMin = new Vector3(
                index.X - sizeOffs,
                -0.5f,
                index.Z - sizeOffs
                );
            Vector3 boundsMax = new Vector3(
                index.X + sizeOffs,
                0.5f + ChunkData.SizeY,
                index.Z + sizeOffs
                );

            _bounds = new BoundingBox(boundsMin, boundsMax);
            _octree = new ChunkOctree(_bounds);

            // check if we need to populate
            if (generateTerrain)
            {
                PopulateTerrain();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Populates a voxel buffer with the current face data.
 /// </summary>
 /// <param name="buff">The buffer.</param>
 public void PopulateBuffer(VoxelBuffer buff)
 {
     buff.Dispose();
     if (_vertices.Count > 0)
     {
         buff.SetData(_vertices.ToArray());
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Populates a voxel buffer with the current face data.
 /// </summary>
 /// <param name="buff">The buffer.</param>
 public void PopulateBuffer( VoxelBuffer buff )
 {
     buff.Dispose();
     if ( _vertices.Count > 0 )
     {
         buff.SetData( _vertices.ToArray() );
     }
 }