Beispiel #1
0
        void DrawDebugGarbage(GameTime gameTime)
        {
            var fps = 1.0 / gameTime.ElapsedGameTime.TotalSeconds;

            var dbgi = GardenChunk.Index(dbgi_x, dbgi_y);
            var dbg  = garden.Chunks[0].Vertices[dbgi];

            var cat = (squareEffect.World * squareEffect.View * squareEffect.Projection);
            var p2  = Vector4.Transform(new Vector4(dbg.Position, 1), cat);
            var pp  = GraphicsDevice.Viewport.Project(
                dbg.Position,
                squareEffect.Projection,
                squareEffect.View,
                squareEffect.World);

            var spriteBatch = new SpriteBatch(GraphicsDevice);

            spriteBatch.Begin();
            spriteBatch.DrawString(
                font,
                $"{fps:0.00} {zoom:0.00} {yaw:0.00} {dv(dbg.Position)} " +
                $"{dv(p2)} {dv(pp)}",
                new Vector2(10, 10),
                Color.White);

            Vector2 xp = new Vector2(pp.X - 6, pp.Y - 6);

            spriteBatch.DrawString(font, "X", xp, Color.White);
            spriteBatch.End();
        }
Beispiel #2
0
        static IndexBuffer BuildChunkIndexBuffer(GraphicsDevice device, GardenChunk chunk)
        {
            int cursor = 0;

            int indexCount =
                (GardenChunk.Width - 1) * (GardenChunk.Height - 1) * 6;

            short[] indices = new short[indexCount];
            for (int y = 0; y < GardenChunk.Height - 1; y++)
            {
                for (int x = 0; x < GardenChunk.Width - 1; x++)
                {
                    indices[cursor + 0] = (short)GardenChunk.Index(x + 0, y + 1);
                    indices[cursor + 1] = (short)GardenChunk.Index(x + 0, y + 0);
                    indices[cursor + 2] = (short)GardenChunk.Index(x + 1, y + 1);

                    indices[cursor + 3] = (short)GardenChunk.Index(x + 1, y + 1);
                    indices[cursor + 4] = (short)GardenChunk.Index(x + 0, y + 0);
                    indices[cursor + 5] = (short)GardenChunk.Index(x + 1, y + 0);

                    cursor += 6;
                }
            }
            var gardenIndices = new IndexBuffer(
                device,
                typeof(short),
                indices.Length,
                BufferUsage.WriteOnly);

            gardenIndices.SetData(indices);
            return(gardenIndices);
        }
Beispiel #3
0
        void DrawChunk(int wx, int wy)
        {
            int ci = Garden.Index(wx, wy);

            IndexBuffer indexBuffer = gardenIndices[ci];

            if (indexBuffer == null)
            {
                indexBuffer = gardenIndices[ci] = BuildChunkIndexBuffer(
                    GraphicsDevice, garden.Chunks[ci]);
            }
            GraphicsDevice.Indices = indexBuffer;

            VertexBuffer vertexBuffer = gardenVertices[ci];

            if (vertexBuffer == null)
            {
                GardenChunk           chunk    = garden.Chunks[ci];
                VertexPositionColor[] vertices = chunk.Vertices;
                vertexBuffer = gardenVertices[ci] = new VertexBuffer(
                    GraphicsDevice,
                    typeof(VertexPositionColor),
                    vertices.Length,
                    BufferUsage.WriteOnly);
                gardenVertices[ci].SetData(vertices);
            }
            GraphicsDevice.SetVertexBuffer(vertexBuffer);

            squareEffect.World = Matrix.CreateTranslation(
                wx * (GardenChunk.Width - 1),
                0,
                wy * (GardenChunk.Height - 1));
            foreach (EffectPass pass in squareEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                GraphicsDevice.DrawIndexedPrimitives(
                    primitiveType: PrimitiveType.TriangleList,
                    baseVertex: 0,
                    startIndex: 0,
                    primitiveCount: indexBuffer.IndexCount / 3);
            }
        }