Exemplo n.º 1
0
        private void InitializeBlocks()
        {
            BlockCount = (Size - 1) / (BlockSize - 1);

            blocks = new Block[BlockCount, BlockCount];

            for (int i = 0; i < BlockCount; i++)
                for (int j = 0; j < BlockCount; j++)
                    blocks[i, j] = new Block(this, new Point(i, j), new Point(i * (BlockSize - 1), j * (BlockSize - 1)));

            foreach (Block block in blocks)
                block.Initialize();
        }
Exemplo n.º 2
0
        private float[] GetNeighborBlendings(Block block)
        {
            int x = block.Position.X;
            int y = block.Position.Y;

            return new float[] {
                (y < BlockCount - 1) ? blocks[x, y + 1].Blending : block.Blending,
                (x < BlockCount - 1) ? blocks[x + 1, y].Blending : block.Blending,
                (y > 0) ? blocks[x, y - 1].Blending : block.Blending,
                (x > 0) ? blocks[x - 1, y].Blending : block.Blending
            };
        }
Exemplo n.º 3
0
        private int[] GetNeighborLevels(Block block)
        {
            int x = block.Position.X;
            int y = block.Position.Y;

            return new int[] {
                (y < BlockCount - 1) ? blocks[x, y + 1].CurrentLevel : block.CurrentLevel,
                (x < BlockCount - 1) ? blocks[x + 1, y].CurrentLevel : block.CurrentLevel,
                (y > 0) ? blocks[x, y - 1].CurrentLevel : block.CurrentLevel,
                (x > 0) ? blocks[x - 1, y].CurrentLevel : block.CurrentLevel
            };
        }
Exemplo n.º 4
0
        private void DrawBlock(Block block)
        {
            int[] neighborLevels = GetNeighborLevels(block);
            int[] blockIndices = indices.GetIndices(block.CurrentLevel, neighborLevels).ToArray();

            if (blockIndices.Length == 0)
                return;

            Effect.Parameters["Level"].SetValue(block.CurrentLevel);
            Effect.Parameters["Blending"].SetValue(block.Blending);
            Effect.Parameters["NeighborLevels"].SetValue(neighborLevels);
            Effect.Parameters["NeighborBlendings"].SetValue(GetNeighborBlendings(block));
            Effect.Parameters["Offset"].SetValue(new Vector2(block.Offset.X, block.Offset.Y));
            Effect.CurrentTechnique.Passes[0].Apply();

            IndexBuffer.SetData<int>(blockIndices, 0, blockIndices.Length, SetDataOptions.Discard);

            int size = (int)(BlockSize / Math.Pow(2, block.CurrentLevel) + 1);
            int primitiveCount = blockIndices.Length / 3;

            GraphicsDevice.DrawIndexedPrimitives(
                PrimitiveType.TriangleList, GetIndex(block.Offset), 0, size * size, 0, primitiveCount);

            TriangleCounter += primitiveCount;
            DrawCallCounter++;
        }