예제 #1
0
        public void Apply(VoxelStencil stencil)
        {
            int xStart = stencil.XStart;
            if (xStart < 0)
            {
                xStart = 0;
            }
            int xEnd = stencil.XEnd;
            if (xEnd >= resolution)
            {
                xEnd = resolution - 1;
            }
            int yStart = stencil.YStart;
            if (yStart < 0)
            {
                yStart = 0;
            }
            int yEnd = stencil.YEnd;
            if (yEnd >= resolution)
            {
                yEnd = resolution - 1;
            }

            for (int y = yStart; y <= yEnd; y++)
            {
                int i = y * resolution + xStart;
                for (int x = xStart; x <= xEnd; x++, i++)
                {
                    voxels[i].state = stencil.Apply(x, y, voxels[i].state);
                }
            }
            Refresh();
        }
예제 #2
0
        /// <summary>
        /// Update the voxel map.
        /// </summary>
        /// <param name="point">The point which was touched.</param>
        private void EditVoxels(Vector3 point)
        {
            int centerX = (int)((point.x + halfSize) / voxelSize);
            int centerY = (int)((point.y + halfSize) / voxelSize);

            int xStart = (centerX - 1) / voxelResolution;
            if (xStart < 0)
            {
                xStart = 0;
            }
            int xEnd = (centerX) / voxelResolution;
            if (xEnd >= chunkResolution)
            {
                xEnd = chunkResolution - 1;
            }
            int yStart = (centerY - 1) / voxelResolution;
            if (yStart < 0)
            {
                yStart = 0;
            }
            int yEnd = (centerY) / voxelResolution;
            if (yEnd >= chunkResolution)
            {
                yEnd = chunkResolution - 1;
            }

            VoxelStencil activeStencil = new VoxelStencil();
            activeStencil.Initialize(true, 0);

            int voxelYOffset = yEnd * voxelResolution;
            for (int y = yEnd; y >= yStart; y--)
            {
                int i = y * chunkResolution + xEnd;
                int voxelXOffset = xEnd * voxelResolution;
                for (int x = xEnd; x >= xStart; x--, i--)
                {
                    activeStencil.SetCenter(centerX - voxelXOffset, centerY - voxelYOffset);
                    chunks[i].Apply(activeStencil);
                    voxelXOffset -= voxelResolution;
                }
                voxelYOffset -= voxelResolution;
            }
        }