Esempio n. 1
0
        public QTNode(VertexMultiTextured[,] vertexArray, GraphicsDevice device, Texture2D grassTexture, int maxSize, Effect effect,Texture2D rockTexture, Texture2D snowTexture, Texture2D sandTexture)
        {
            this.device = device;
            this.grassTexture = grassTexture;
            this.rockTexture = rockTexture;
            this.sandTexture = sandTexture;
            this.snowTexture = snowTexture;
            this.effect = effect;
            width = vertexArray.GetLength(0);
            height = vertexArray.GetLength(1);

            nodeBoundingBox = TerrainUtils.CreateBoundingBox(vertexArray);

            isEndNode = width <= maxSize;
            isEndNode &= height <= maxSize;
            if (isEndNode)
            {
                VertexMultiTextured[] vertices = TerrainUtils.Reshape2DTo1D<VertexMultiTextured>(vertexArray);
                int[] indices = TerrainUtils.CreateTerrainIndices(width, height);
                TerrainUtils.CopyToBuffer(ref nodeVertexBuffer, ref nodeIndexBuffer, vertices, indices, device);
            }
            else
                CreateChildNodes(vertexArray, maxSize);
        }
Esempio n. 2
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);
        }