示例#1
0
        private void CreateChildNodes(VertexMultiTextured[,] vertexArray, int maxSize)
        {
            VertexMultiTextured[,] ulArray = new VertexMultiTextured[width / 2 + 1, height / 2 + 1];
            for (int w = 0; w < width / 2 + 1; w++)
                for (int h = 0; h < height / 2 + 1; h++)
                    ulArray[w, h] = vertexArray[w, h];
            nodeUL = new QTNode(ulArray, device, grassTexture, maxSize, effect, rockTexture, snowTexture, sandTexture);

            VertexMultiTextured[,] urArray = new VertexMultiTextured[width - (width / 2), height / 2 + 1];
            for (int w = 0; w < width - (width / 2); w++)
                for (int h = 0; h < height / 2 + 1; h++)
                    urArray[w, h] = vertexArray[width / 2 + w, h];
            nodeUR = new QTNode(urArray, device, grassTexture, maxSize, effect, rockTexture, snowTexture, sandTexture);

            VertexMultiTextured[,] llArray = new VertexMultiTextured[width / 2 + 1, height - (height / 2)];
            for (int w = 0; w < width / 2 + 1; w++)
                for (int h = 0; h < height - (height / 2); h++)
                    llArray[w, h] = vertexArray[w, height / 2 + h];
            nodeLL = new QTNode(llArray, device, grassTexture, maxSize, effect, rockTexture, snowTexture, sandTexture);

            VertexMultiTextured[,] lrArray = new VertexMultiTextured[width - (width / 2), height - (height / 2)];
            for (int w = 0; w < width - (width / 2); w++)
                for (int h = 0; h < height - (height / 2); h++)
                    lrArray[w, h] = vertexArray[width / 2 + w, height / 2 + h];
            nodeLR = new QTNode(lrArray, device, grassTexture, maxSize, effect, rockTexture, snowTexture, sandTexture);
        }
示例#2
0
        protected override void LoadContent()
        {
            //Loading textures and effects from content
            terrainMap = Game.Content.Load<Texture2D>("Models/Terrain/Heightmaps/heightmap4");
            grassTexture = Game.Content.Load<Texture2D>("Models/Terrain/Textures/grass");
            sandTexture = Game.Content.Load<Texture2D>("Models/Terrain/Textures/sand");
            snowTexture = Game.Content.Load<Texture2D>("Models/Terrain/Textures/snow");
            rockTexture = Game.Content.Load<Texture2D>("Models/Terrain/Textures/rock");
            TerrainUtils.LoadHeightData(terrainMap, ref heightData, ref width, ref height);
            TerrainUtils.SetUpVertices(heightData, ref vertices, width, height);
            indices = TerrainUtils.CreateTerrainIndices(width, height);
            vertices = TerrainUtils.GenerateNormalsForTriangleStrip(vertices, indices);
            VertexMultiTextured[,] vertexArray = TerrainUtils.Reshape1DTo2D<VertexMultiTextured>(vertices, width, height);
            rootNode = new QTNode(vertexArray, device, grassTexture, 64, effect, rockTexture, snowTexture, sandTexture);
            TerrainUtils.CopyToBuffer(ref vertexBuffer, ref indexBuffer, vertices, indices, device);

            int terrainSize = 32;
            Triangle leftTriangle = new Triangle(null, new Vector2(0, 0), new Vector2(terrainSize, 0), new Vector2(0, terrainSize), heightData);
            Triangle rightTriangle = new Triangle(null, new Vector2(terrainSize, terrainSize), new Vector2(0, terrainSize), new Vector2(terrainSize, 0), heightData);
            leftTriangle.AddNeighs(null, null, rightTriangle);
            rightTriangle.AddNeighs(null, null, leftTriangle);

            triangleList = new List<Triangle>();
            triangleList.Add(leftTriangle);
            triangleList.Add(rightTriangle);

            indicesList = new List<int>();
            foreach (Triangle t in triangleList)
                t.AddIndices(ref indicesList);

            dynamicIndexBuffer = new DynamicIndexBuffer(device, typeof(int), indicesList.Count, BufferUsage.WriteOnly);
            dynamicIndexBuffer.SetData(indicesList.ToArray(), 0, indicesList.Count, SetDataOptions.Discard);
            dynamicIndexBuffer.ContentLost += dynamicIndexBuffer_ContentLost;
        }