コード例 #1
0
        protected override void LoadContent()
        {
            device = graphics.GraphicsDevice;
            cCross = new CoordCross(device);

            Texture2D grassTexture = Content.Load <Texture2D>("grass");

            Texture2D heightMap = Content.Load <Texture2D>("heightmap");
            int       width     = heightMap.Width;
            int       height    = heightMap.Height;

            float[,] heightData = TerrainUtils.LoadHeightData(heightMap);
            VertexPositionNormalTexture[] vertices = TerrainUtils.CreateTerrainVertices(heightData);
            int[] indices = TerrainUtils.CreateTerrainIndices(width, height);
            vertices = TerrainUtils.GenerateNormalsForTriangleStrip(vertices, indices);
            VertexPositionNormalTexture[,] vertexArray = Reshape1Dto2D <VertexPositionNormalTexture>(vertices, width, height);

            rootNode = new QTNode(vertexArray, device, grassTexture, 64);
        }
コード例 #2
0
        public QTNode(VertexPositionNormalTexture[,] vertexArray, GraphicsDevice device, Texture2D grassTexture, int maxSize)
        {
            this.device       = device;
            this.grassTexture = grassTexture;
            basicEffect       = new BasicEffect(device, null);

            width           = vertexArray.GetLength(0);
            height          = vertexArray.GetLength(1);
            nodeBoundingBox = CreateBoundingBox(vertexArray);

            isEndNode  = width <= maxSize;
            isEndNode &= height <= maxSize;
            if (isEndNode)
            {
                VertexPositionNormalTexture[] vertices = Reshape2Dto1D <VertexPositionNormalTexture>(vertexArray);
                int[] indices = TerrainUtils.CreateTerrainIndices(width, height);
                TerrainUtils.CreateBuffers(vertices, indices, out nodeVertexBuffer, out nodeIndexBuffer, device);
            }
            else
            {
                CreateChildNodes(vertexArray, maxSize);
            }
        }