Exemplo n.º 1
0
        /// <summary>
        /// Generates the tilemap vertices.
        /// </summary>
        /// <returns>Generates the vertex and index data for the grid used for rendering the tilemap.</returns>
        private static (VertexPositionTextureColor[] vertexData, ushort[] indexData) GenerateTilemapVertices()
        {
            var iindex     = 0;
            var vertexData = new VertexPositionTextureColor[4 * (Configuration.ChunkWidth + 1) * (Configuration.ChunkHeight + 1)];
            var indexData  = new ushort[6 * (Configuration.ChunkWidth + 1) * (Configuration.ChunkHeight + 1)];

            for (var y = 0; y < Configuration.ChunkHeight + 1; y++)
            {
                for (var x = 0; x < Configuration.ChunkWidth + 1; x++)
                {
                    var vindex = 4 * (y * (Configuration.ChunkWidth + 1) + x);
                    vertexData[vindex]     = new VertexPositionTextureColor(new Vector2(x * Configuration.TileSize, y * Configuration.TileSize), new Vector2(0f, 0f));
                    vertexData[vindex + 1] = new VertexPositionTextureColor(new Vector2((x + 1) * Configuration.TileSize, y * Configuration.TileSize), new Vector2(1f, 0f));
                    vertexData[vindex + 2] = new VertexPositionTextureColor(new Vector2(x * Configuration.TileSize, (y + 1) * Configuration.TileSize), new Vector2(0f, 1f));
                    vertexData[vindex + 3] = new VertexPositionTextureColor(new Vector2((x + 1) * Configuration.TileSize, (y + 1) * Configuration.TileSize), new Vector2(1f, 1f));

                    indexData[iindex++] = (ushort)vindex;
                    indexData[iindex++] = (ushort)(vindex + 1);
                    indexData[iindex++] = (ushort)(vindex + 2);
                    indexData[iindex++] = (ushort)(vindex + 2);
                    indexData[iindex++] = (ushort)(vindex + 1);
                    indexData[iindex++] = (ushort)(vindex + 3);
                }
            }

            return(vertexData, indexData);
        }
Exemplo n.º 2
0
        public void Draw(ITexture2D Texture, Rectangle Rectangle, Rectangle RectangleSource, Color Color)
        {
            Vector2 uvMin = new Vector2(RectangleSource.Left / Texture.Width, RectangleSource.Top / Texture.Height);
            Vector2 uvMax = new Vector2(RectangleSource.Right / Texture.Width, RectangleSource.Bottom / Texture.Height);

            var a = new VertexPositionTextureColor(new Vector3(Rectangle.X, Rectangle.Y, 0), uvMin, Color);
            var b = new VertexPositionTextureColor(new Vector3(Rectangle.Right, Rectangle.Y, 0), new Vector2(uvMax.X, uvMin.Y), Color);
            var c = new VertexPositionTextureColor(new Vector3(Rectangle.Right, Rectangle.Bottom, 0), uvMax, Color);
            var d = new VertexPositionTextureColor(new Vector3(Rectangle.X, Rectangle.Bottom, 0), new Vector2(uvMin.X, uvMax.Y), Color);

            AddQuad(new Quad(Texture, a, b, c, d));
        }